[PATCH] D105054: [lld/mac] Fix nondeterminism in output section ordering
Nico Weber via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 28 15:41:54 PDT 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf1969b74a7e7: [lld/mac] Fix nondeterminism in output section ordering (authored by thakis).
Herald added a project: LLVM.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D105054/new/
https://reviews.llvm.org/D105054
Files:
lld/MachO/OutputSegment.cpp
lld/MachO/Writer.cpp
lld/test/MachO/tlv-dylib.s
Index: lld/test/MachO/tlv-dylib.s
===================================================================
--- lld/test/MachO/tlv-dylib.s
+++ lld/test/MachO/tlv-dylib.s
@@ -74,21 +74,21 @@
# FLAGS-NEXT: reloff 0
# FLAGS-NEXT: nreloc 0
# FLAGS-NEXT: type S_THREAD_LOCAL_ZEROFILL
-# FLAGS: sectname __bss
+# FLAGS: sectname __common
# FLAGS-NEXT: segname __DATA
# FLAGS-NEXT: addr
-# FLAGS-NEXT: size 0x0000000000002000
+# FLAGS-NEXT: size 0x0000000000004000
# FLAGS-NEXT: offset 0
-# FLAGS-NEXT: align 2^0 (1)
+# FLAGS-NEXT: align 2^14 (16384)
# FLAGS-NEXT: reloff 0
# FLAGS-NEXT: nreloc 0
# FLAGS-NEXT: type S_ZEROFILL
-# FLAGS: sectname __common
+# FLAGS: sectname __bss
# FLAGS-NEXT: segname __DATA
# FLAGS-NEXT: addr
-# FLAGS-NEXT: size 0x0000000000004000
+# FLAGS-NEXT: size 0x0000000000002000
# FLAGS-NEXT: offset 0
-# FLAGS-NEXT: align 2^14 (16384)
+# FLAGS-NEXT: align 2^0 (1)
# FLAGS-NEXT: reloff 0
# FLAGS-NEXT: nreloc 0
# FLAGS-NEXT: type S_ZEROFILL
Index: lld/MachO/Writer.cpp
===================================================================
--- lld/MachO/Writer.cpp
+++ lld/MachO/Writer.cpp
@@ -79,7 +79,10 @@
LCUuid *uuidCommand = nullptr;
OutputSegment *linkEditSegment = nullptr;
- DenseMap<NamePair, ConcatOutputSection *> concatOutputSections;
+
+ // Output sections are added to output segments in iteration order
+ // of ConcatOutputSection, so must have deterministic iteration order.
+ MapVector<NamePair, ConcatOutputSection *> concatOutputSections;
};
// LC_DYLD_INFO_ONLY stores the offsets of symbol import/export information.
Index: lld/MachO/OutputSegment.cpp
===================================================================
--- lld/MachO/OutputSegment.cpp
+++ lld/MachO/OutputSegment.cpp
@@ -140,10 +140,15 @@
}
void OutputSegment::sortOutputSections() {
- llvm::sort(sections, compareByOrder<OutputSection *>(sectionOrder));
+ // Must be stable_sort() to keep special sections such as
+ // S_THREAD_LOCAL_REGULAR in input order.
+ llvm::stable_sort(sections, compareByOrder<OutputSection *>(sectionOrder));
}
void macho::sortOutputSegments() {
+ // sort() instead of stable_sort() is fine because segmentOrder() is
+ // name-based and getOrCreateOutputSegment() makes there's only a single
+ // segment for every name.
llvm::sort(outputSegments, compareByOrder<OutputSegment *>(segmentOrder));
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105054.355052.patch
Type: text/x-patch
Size: 2491 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210628/fc6e4474/attachment.bin>
More information about the llvm-commits
mailing list