diff --git a/llvm/test/tools/llvm-objdump/MachO/disassemble-symbol-same-addr.test b/llvm/test/tools/llvm-objdump/MachO/disassemble-symbol-same-addr.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-objdump/MachO/disassemble-symbol-same-addr.test @@ -0,0 +1,14 @@ +# RUN: llvm-mc %s --triple x86_64-apple-darwin -filetype=obj -o %t.o +# RUN: llvm-objdump --macho -d %t.o | FileCheck %s + +_foo: +_bar: +_baz: +_qux: + nop + +## Ensure symbols with the same address are printed in a deterministic order +# CHECK: _foo +# CHECK-NEXT: _bar +# CHECK-NEXT: _baz +# CHECK-NEXT: _qux diff --git a/llvm/tools/llvm-objdump/MachODump.cpp b/llvm/tools/llvm-objdump/MachODump.cpp --- a/llvm/tools/llvm-objdump/MachODump.cpp +++ b/llvm/tools/llvm-objdump/MachODump.cpp @@ -7318,7 +7318,7 @@ BaseSegmentAddress); // Sort the symbols by address, just in case they didn't come in that way. - llvm::sort(Symbols, SymbolSorter()); + llvm::stable_sort(Symbols, SymbolSorter()); // Build a data in code table that is sorted on by the address of each entry. uint64_t BaseAddress = 0;