}
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));
}
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.
# 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