mirror of
https://github.com/golang/go
synced 2024-11-26 11:58:07 -07:00
cmd/link: set .ctors COFF section to writable and aligned
Without setting these flags, LLVM's LLD ignores the .ctors section when merging objects. Updates #44250. Updates #39326. Updates #38755. Updates #36439. Updates #43800. Change-Id: I8766104508f7acd832088a590ee7d68afa0d6065 Reviewed-on: https://go-review.googlesource.com/c/go/+/291633 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
811167e2c9
commit
91cfbf39e4
@ -66,6 +66,8 @@ const (
|
||||
IMAGE_SCN_MEM_WRITE = 0x80000000
|
||||
IMAGE_SCN_MEM_DISCARDABLE = 0x2000000
|
||||
IMAGE_SCN_LNK_NRELOC_OVFL = 0x1000000
|
||||
IMAGE_SCN_ALIGN_4BYTES = 0x300000
|
||||
IMAGE_SCN_ALIGN_8BYTES = 0x400000
|
||||
IMAGE_SCN_ALIGN_32BYTES = 0x600000
|
||||
)
|
||||
|
||||
@ -478,20 +480,19 @@ func (f *peFile) addInitArray(ctxt *Link) *peSection {
|
||||
// However, the entire Go runtime is initialized from just one function, so it is unlikely
|
||||
// that this will need to grow in the future.
|
||||
var size int
|
||||
var alignment uint32
|
||||
switch objabi.GOARCH {
|
||||
default:
|
||||
Exitf("peFile.addInitArray: unsupported GOARCH=%q\n", objabi.GOARCH)
|
||||
case "386":
|
||||
case "386", "arm":
|
||||
size = 4
|
||||
case "amd64":
|
||||
size = 8
|
||||
case "arm":
|
||||
size = 4
|
||||
case "arm64":
|
||||
alignment = IMAGE_SCN_ALIGN_4BYTES
|
||||
case "amd64", "arm64":
|
||||
size = 8
|
||||
alignment = IMAGE_SCN_ALIGN_8BYTES
|
||||
}
|
||||
sect := f.addSection(".ctors", size, size)
|
||||
sect.characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ
|
||||
sect.characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE | alignment
|
||||
sect.sizeOfRawData = uint32(size)
|
||||
ctxt.Out.SeekSet(int64(sect.pointerToRawData))
|
||||
sect.checkOffset(ctxt.Out.Offset())
|
||||
|
Loading…
Reference in New Issue
Block a user