]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: set SizeOfRawData rather than VirtualSize in COFF files for .bss section
authorJason A. Donenfeld <Jason@zx2c4.com>
Sat, 13 Feb 2021 23:04:48 +0000 (00:04 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Tue, 23 Feb 2021 15:03:26 +0000 (15:03 +0000)
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 <Jason@zx2c4.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
src/cmd/link/internal/ld/pe.go

index 36c8e0da9a7d62f8af18201ee9b7809193da2d22..46e3df5df18dc0886250b48bec229333924e4751 100644 (file)
@@ -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