diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -601,7 +601,7 @@ continue; std::vector &symbolIndices = symbolsBySection[i]; - llvm::sort(symbolIndices, [&](uint32_t lhs, uint32_t rhs) { + llvm::stable_sort(symbolIndices, [&](uint32_t lhs, uint32_t rhs) { return nList[lhs].n_value < nList[rhs].n_value; }); uint64_t sectionAddr = sectionHeaders[i].addr; diff --git a/lld/test/MachO/stabs.s b/lld/test/MachO/stabs.s --- a/lld/test/MachO/stabs.s +++ b/lld/test/MachO/stabs.s @@ -191,14 +191,14 @@ .long Lset3 .byte 0 ## End Of Children Mark Ldebug_info_end0: -.subsections_via_symbols -.section __DWARF,__debug_line,regular,debug .section OTHER,more_text,regular,pure_instructions .globl _fun _fun: ret +.subsections_via_symbols + #--- foo.s .text .globl _foo @@ -240,13 +240,13 @@ .long Lset3 .byte 0 ## End Of Children Mark Ldebug_info_end0: -.subsections_via_symbols -.section __DWARF,__debug_line,regular,debug .section __DWARF,__debug_aranges,regular,debug ltmp1: .byte 0 +.subsections_via_symbols + #--- no-debug.s ## This file has no debug info. .text