aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objdump/llvm-objdump.cpp
diff options
context:
space:
mode:
authorFangrui Song <maskray@google.com>2020-03-24 15:55:34 -0700
committerFangrui Song <maskray@google.com>2020-03-25 08:13:40 -0700
commit5e7a42cf077d2555038be1218907174f4df8e5a5 (patch)
tree4253fc28e7e4e4d9ca69ff4d6b705568219b0e60 /llvm/tools/llvm-objdump/llvm-objdump.cpp
parent3282d875d6f740b56b686c1af320ba7f31ba0a48 (diff)
downloadllvm-5e7a42cf077d2555038be1218907174f4df8e5a5.zip
llvm-5e7a42cf077d2555038be1218907174f4df8e5a5.tar.gz
llvm-5e7a42cf077d2555038be1218907174f4df8e5a5.tar.bz2
[llvm-objdump] Replace array_pod_sort with llvm::stable_sort
llvm-objdump.cpp has 3 array_pod_sort() calls used for symbolization. array_pod_start() calls qsort() internally and can have different behaviors across different libcs. Use llvm::stable_sort instead. Reviewed By: davidb, thopre Differential Revision: https://reviews.llvm.org/D76739
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r--llvm/tools/llvm-objdump/llvm-objdump.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 1cfd06d..768ddfe 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -1202,11 +1202,13 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj,
StringSaver Saver(A);
addPltEntries(Obj, AllSymbols, Saver);
- // Create a mapping from virtual address to section.
+ // Create a mapping from virtual address to section. An empty section can
+ // cause more than one section at the same address. Use a stable sort to
+ // stabalize the output.
std::vector<std::pair<uint64_t, SectionRef>> SectionAddresses;
for (SectionRef Sec : Obj->sections())
SectionAddresses.emplace_back(Sec.getAddress(), Sec);
- array_pod_sort(SectionAddresses.begin(), SectionAddresses.end());
+ stable_sort(SectionAddresses);
// Linked executables (.exe and .dll files) typically don't include a real
// symbol table but they might contain an export table.
@@ -1236,11 +1238,12 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj,
}
// Sort all the symbols, this allows us to use a simple binary search to find
- // a symbol near an address.
+ // Multiple symbols can have the same address. Use a stable sort to stabalize
+ // the output.
StringSet<> FoundDisasmSymbolSet;
for (std::pair<const SectionRef, SectionSymbolsTy> &SecSyms : AllSymbols)
- array_pod_sort(SecSyms.second.begin(), SecSyms.second.end());
- array_pod_sort(AbsoluteSymbols.begin(), AbsoluteSymbols.end());
+ stable_sort(SecSyms.second);
+ stable_sort(AbsoluteSymbols);
for (const SectionRef &Section : ToolSectionFilter(*Obj)) {
if (FilterSections.empty() && !DisassembleAll &&