Index: lld/MachO/OutputSegment.cpp =================================================================== --- lld/MachO/OutputSegment.cpp +++ lld/MachO/OutputSegment.cpp @@ -140,10 +140,13 @@ } void OutputSegment::sortOutputSections() { - llvm::sort(sections, compareByOrder(sectionOrder)); + llvm::stable_sort(sections, compareByOrder(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(segmentOrder)); } Index: lld/MachO/Writer.cpp =================================================================== --- lld/MachO/Writer.cpp +++ lld/MachO/Writer.cpp @@ -78,7 +78,7 @@ LCUuid *uuidCommand = nullptr; OutputSegment *linkEditSegment = nullptr; - DenseMap concatOutputSections; + MapVector concatOutputSections; }; // LC_DYLD_INFO_ONLY stores the offsets of symbol import/export information.