Skip to content

Commit 91cfbf3

Browse files
committed
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 <[email protected]> Run-TryBot: Jason A. Donenfeld <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Than McIntosh <[email protected]>
1 parent 811167e commit 91cfbf3

File tree

1 file changed

+8
-7
lines changed
  • src/cmd/link/internal/ld

1 file changed

+8
-7
lines changed

src/cmd/link/internal/ld/pe.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ const (
6666
IMAGE_SCN_MEM_WRITE = 0x80000000
6767
IMAGE_SCN_MEM_DISCARDABLE = 0x2000000
6868
IMAGE_SCN_LNK_NRELOC_OVFL = 0x1000000
69+
IMAGE_SCN_ALIGN_4BYTES = 0x300000
70+
IMAGE_SCN_ALIGN_8BYTES = 0x400000
6971
IMAGE_SCN_ALIGN_32BYTES = 0x600000
7072
)
7173

@@ -478,20 +480,19 @@ func (f *peFile) addInitArray(ctxt *Link) *peSection {
478480
// However, the entire Go runtime is initialized from just one function, so it is unlikely
479481
// that this will need to grow in the future.
480482
var size int
483+
var alignment uint32
481484
switch objabi.GOARCH {
482485
default:
483486
Exitf("peFile.addInitArray: unsupported GOARCH=%q\n", objabi.GOARCH)
484-
case "386":
485-
size = 4
486-
case "amd64":
487-
size = 8
488-
case "arm":
487+
case "386", "arm":
489488
size = 4
490-
case "arm64":
489+
alignment = IMAGE_SCN_ALIGN_4BYTES
490+
case "amd64", "arm64":
491491
size = 8
492+
alignment = IMAGE_SCN_ALIGN_8BYTES
492493
}
493494
sect := f.addSection(".ctors", size, size)
494-
sect.characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ
495+
sect.characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE | alignment
495496
sect.sizeOfRawData = uint32(size)
496497
ctxt.Out.SeekSet(int64(sect.pointerToRawData))
497498
sect.checkOffset(ctxt.Out.Offset())

0 commit comments

Comments
 (0)