[llvm] 6875165 - [llvm-objdump/mac] Print symbols at the same address deterministically
Jez Ng via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 30 19:38:22 PDT 2021
Author: Jez Ng
Date: 2021-06-30T22:38:07-04:00
New Revision: 68751651235562b27b83788a5da4d23e431443c1
URL: https://github.com/llvm/llvm-project/commit/68751651235562b27b83788a5da4d23e431443c1
DIFF: https://github.com/llvm/llvm-project/commit/68751651235562b27b83788a5da4d23e431443c1.diff
LOG: [llvm-objdump/mac] Print symbols at the same address deterministically
By using stable_sort.
Added a test case which previously failed when expensive checks were
enabled.
Reviewed By: MaskRay
Differential Revision: https://reviews.llvm.org/D105240
Added:
llvm/test/tools/llvm-objdump/MachO/disassemble-symbol-same-addr.test
Modified:
llvm/tools/llvm-objdump/MachODump.cpp
Removed:
################################################################################
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
index 0000000000000..fa430ee911f8a
--- /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
index 552cf077453cb..7c1fdf03542f1 100644
--- a/llvm/tools/llvm-objdump/MachODump.cpp
+++ b/llvm/tools/llvm-objdump/MachODump.cpp
@@ -7318,7 +7318,7 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
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;
More information about the llvm-commits
mailing list