[lld] e6cb55d - [lld/mac] Test zerofill sections after __thread_bss
Nico Weber via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 20 17:45:26 PDT 2021
Author: Nico Weber
Date: 2021-06-20T20:44:29-04:00
New Revision: e6cb55d5ceb8e3f623814779ba4fc0c1e003e9fa
URL: https://github.com/llvm/llvm-project/commit/e6cb55d5ceb8e3f623814779ba4fc0c1e003e9fa
DIFF: https://github.com/llvm/llvm-project/commit/e6cb55d5ceb8e3f623814779ba4fc0c1e003e9fa.diff
LOG: [lld/mac] Test zerofill sections after __thread_bss
Real zerofill sections go after __thread_bss, since zerofill sections
must all be at the end of their segment and __thread_bss must be right
after __thread_data.
Works fine already, but wasn't tested as far as I can tell.
Also tweak comment about zerofill sections a bit.
No behavior change.
Differential Revision: https://reviews.llvm.org/D104609
Added:
Modified:
lld/MachO/OutputSegment.cpp
lld/test/MachO/tlv-dylib.s
Removed:
################################################################################
diff --git a/lld/MachO/OutputSegment.cpp b/lld/MachO/OutputSegment.cpp
index 9a775ce0e5ca3..77aa50cd03043 100644
--- a/lld/MachO/OutputSegment.cpp
+++ b/lld/MachO/OutputSegment.cpp
@@ -130,8 +130,10 @@ static int sectionOrder(OutputSection *osec) {
.Case(section_names::codeSignature, std::numeric_limits<int>::max())
.Default(osec->inputOrder);
}
- // ZeroFill sections must always be the at the end of their segments,
- // otherwise subsequent sections may get overwritten with zeroes at runtime.
+ // ZeroFill sections must always be the at the end of their segments:
+ // dyld checks if a segment's file size is smaller than its in-memory
+ // size to detect if a segment has zerofill sections, and if so it maps
+ // the missing tail as zerofill.
if (sectionType(osec->flags) == S_ZEROFILL)
return std::numeric_limits<int>::max();
return osec->inputOrder;
diff --git a/lld/test/MachO/tlv-dylib.s b/lld/test/MachO/tlv-dylib.s
index 2d452a2b9caaf..c41f152eb16fa 100644
--- a/lld/test/MachO/tlv-dylib.s
+++ b/lld/test/MachO/tlv-dylib.s
@@ -69,11 +69,29 @@
# FLAGS-NEXT: segname __DATA
# FLAGS-NEXT: addr
# FLAGS-NEXT: size 0x0000000000000008
-# FLAGS-NEXT: offset
+# FLAGS-NEXT: offset 0
# FLAGS-NEXT: align 2^3 (8)
# FLAGS-NEXT: reloff 0
# FLAGS-NEXT: nreloc 0
# FLAGS-NEXT: type S_THREAD_LOCAL_ZEROFILL
+# FLAGS: sectname __bss
+# FLAGS-NEXT: segname __DATA
+# FLAGS-NEXT: addr
+# FLAGS-NEXT: size 0x0000000000002000
+# FLAGS-NEXT: offset 0
+# FLAGS-NEXT: align 2^0 (1)
+# FLAGS-NEXT: reloff 0
+# FLAGS-NEXT: nreloc 0
+# FLAGS-NEXT: type S_ZEROFILL
+# FLAGS: sectname __common
+# FLAGS-NEXT: segname __DATA
+# FLAGS-NEXT: addr
+# FLAGS-NEXT: size 0x0000000000004000
+# FLAGS-NEXT: offset 0
+# FLAGS-NEXT: align 2^14 (16384)
+# FLAGS-NEXT: reloff 0
+# FLAGS-NEXT: nreloc 0
+# FLAGS-NEXT: type S_ZEROFILL
#--- libtlv.s
.section __DATA,__thread_vars,thread_local_variables
@@ -95,6 +113,12 @@ _main:
## Add some TLVs to test too, so that we can test the ordering
## of __thread_ptrs, __thread_data, and __thread_bss.
+## Also add a .bss and a .comm for good measure too. Since they
+## are both zerofill, they end up after __thread_bss.
+.comm _com, 0x4000
+.bss
+.zero 0x2000
+
.section __DATA,__thread_data,thread_local_regular
_tfoo$tlv$init:
.quad 123
More information about the llvm-commits
mailing list