mirror of
https://github.com/golang/go
synced 2024-11-26 16:16:57 -07:00
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 <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>
This commit is contained in:
parent
e5159b2a2f
commit
a51daac840
@ -418,14 +418,16 @@ func (f *peFile) addSection(name string, sectsize int, filesize int) *peSection
|
|||||||
name: name,
|
name: name,
|
||||||
shortName: name,
|
shortName: name,
|
||||||
index: len(f.sections) + 1,
|
index: len(f.sections) + 1,
|
||||||
virtualSize: uint32(sectsize),
|
|
||||||
virtualAddress: f.nextSectOffset,
|
virtualAddress: f.nextSectOffset,
|
||||||
pointerToRawData: f.nextFileOffset,
|
pointerToRawData: f.nextFileOffset,
|
||||||
}
|
}
|
||||||
f.nextSectOffset = uint32(Rnd(int64(f.nextSectOffset)+int64(sectsize), PESECTALIGN))
|
f.nextSectOffset = uint32(Rnd(int64(f.nextSectOffset)+int64(sectsize), PESECTALIGN))
|
||||||
if filesize > 0 {
|
if filesize > 0 {
|
||||||
|
sect.virtualSize = uint32(sectsize)
|
||||||
sect.sizeOfRawData = uint32(Rnd(int64(filesize), PEFILEALIGN))
|
sect.sizeOfRawData = uint32(Rnd(int64(filesize), PEFILEALIGN))
|
||||||
f.nextFileOffset += sect.sizeOfRawData
|
f.nextFileOffset += sect.sizeOfRawData
|
||||||
|
} else {
|
||||||
|
sect.sizeOfRawData = uint32(sectsize)
|
||||||
}
|
}
|
||||||
f.sections = append(f.sections, sect)
|
f.sections = append(f.sections, sect)
|
||||||
return sect
|
return sect
|
||||||
|
Loading…
Reference in New Issue
Block a user