From: Jason A. Donenfeld Date: Sat, 13 Feb 2021 23:04:48 +0000 (+0100) Subject: cmd/link: set SizeOfRawData rather than VirtualSize in COFF files for .bss section X-Git-Tag: go1.17beta1~1432 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=a51daac840482d71d89742871b860a023dbdba0e;p=gostls13.git cmd/link: set SizeOfRawData rather than VirtualSize in COFF files for .bss section GCC and Clang both set the SizeOfRawData field rather than the VirtualSize field for communicating the size of the .bss section. As a consequence, LLD does not look at VirtualSize and collapses the .bss section into whatever is around it, resulting in runtime crashes. This commit changes the logic so that if the requested "file size" is 0, then the SizeOfRawData field is set rather than the VirtualSize field as the sole length marker. Fixes #44250. Fixes #39326. Updates #38755. Updates #36439. Updates #43800. Change-Id: Ied89ddaa0a717fed840238244c6e4848845aeeb6 Reviewed-on: https://go-review.googlesource.com/c/go/+/291630 Trust: Jason A. Donenfeld Run-TryBot: Jason A. Donenfeld TryBot-Result: Go Bot Reviewed-by: Than McIntosh --- diff --git a/src/cmd/link/internal/ld/pe.go b/src/cmd/link/internal/ld/pe.go index 36c8e0da9a..46e3df5df1 100644 --- a/src/cmd/link/internal/ld/pe.go +++ b/src/cmd/link/internal/ld/pe.go @@ -418,14 +418,16 @@ func (f *peFile) addSection(name string, sectsize int, filesize int) *peSection name: name, shortName: name, index: len(f.sections) + 1, - virtualSize: uint32(sectsize), virtualAddress: f.nextSectOffset, pointerToRawData: f.nextFileOffset, } f.nextSectOffset = uint32(Rnd(int64(f.nextSectOffset)+int64(sectsize), PESECTALIGN)) if filesize > 0 { + sect.virtualSize = uint32(sectsize) sect.sizeOfRawData = uint32(Rnd(int64(filesize), PEFILEALIGN)) f.nextFileOffset += sect.sizeOfRawData + } else { + sect.sizeOfRawData = uint32(sectsize) } f.sections = append(f.sections, sect) return sect