[lld-macho] Set 4-byte alignment for `__init_offsets`
authorDaniel Bertalan <dani@danielbertalan.dev>
Thu, 10 Nov 2022 21:42:19 +0000 (22:42 +0100)
committerDaniel Bertalan <dani@danielbertalan.dev>
Thu, 10 Nov 2022 22:32:55 +0000 (23:32 +0100)
dyld refuses to run initializers if this section is unaligned.

Fixes https://bugs.chromium.org/p/chromium/issues/detail?id=1383240

Differential Revision: https://reviews.llvm.org/D137803

lld/MachO/SyntheticSections.cpp
lld/test/MachO/init-offsets.s

index c1da641..267f97a 100644 (file)
@@ -1899,6 +1899,7 @@ void ObjCImageInfoSection::writeTo(uint8_t *buf) const {
 InitOffsetsSection::InitOffsetsSection()
     : SyntheticSection(segment_names::text, section_names::initOffsets) {
   flags = S_INIT_FUNC_OFFSETS;
+  align = 4; // This section contains 32-bit integers.
 }
 
 uint64_t InitOffsetsSection::getSize() const {
index 9a27033..844951a 100644 (file)
@@ -27,7 +27,7 @@
 # FLAGS-NEXT:     addr
 # FLAGS-NEXT:     size 0x0000000000000010
 # FLAGS-NEXT:   offset
-# FLAGS-NEXT:    align
+# FLAGS-NEXT:    align 2^2 (4)
 # FLAGS-NEXT:   reloff 0
 # FLAGS-NEXT:   nreloc 0
 # FLAGS-NEXT:     type S_INIT_FUNC_OFFSETS