From: Jason A. Donenfeld Date: Sun, 14 Feb 2021 18:01:39 +0000 (+0100) Subject: cmd/link: set .ctors COFF section to writable and aligned X-Git-Tag: go1.17beta1~1430 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=91cfbf39e45b130562bbc5b353aa041cfe315faa;p=gostls13.git 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 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 46e3df5df1..a0aba866dc 100644 --- a/src/cmd/link/internal/ld/pe.go +++ b/src/cmd/link/internal/ld/pe.go @@ -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": - size = 4 - case "amd64": - size = 8 - case "arm": + case "386", "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())