[lld] 948fc66 - [lld-macho] Set 4-byte alignment for `__init_offsets`

Daniel Bertalan via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 10 14:33:11 PST 2022


Author: Daniel Bertalan
Date: 2022-11-10T23:32:55+01:00
New Revision: 948fc66f5e86450e602a1d48025f76b13efd5bd2

URL: https://github.com/llvm/llvm-project/commit/948fc66f5e86450e602a1d48025f76b13efd5bd2
DIFF: https://github.com/llvm/llvm-project/commit/948fc66f5e86450e602a1d48025f76b13efd5bd2.diff

LOG: [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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp
index c1da64179026e..267f97ac0ba07 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 9a27033adfdfe..844951a1dc380 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


        


More information about the llvm-commits mailing list