From 948fc66f5e86450e602a1d48025f76b13efd5bd2 Mon Sep 17 00:00:00 2001 From: Daniel Bertalan Date: Thu, 10 Nov 2022 22:42:19 +0100 Subject: [PATCH] [lld-macho] Set 4-byte alignment for `__init_offsets` 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 | 1 + lld/test/MachO/init-offsets.s | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp index c1da641..267f97a 100644 --- a/lld/MachO/SyntheticSections.cpp +++ b/lld/MachO/SyntheticSections.cpp @@ -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 { diff --git a/lld/test/MachO/init-offsets.s b/lld/test/MachO/init-offsets.s index 9a27033..844951a 100644 --- a/lld/test/MachO/init-offsets.s +++ b/lld/test/MachO/init-offsets.s @@ -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 -- 2.7.4