aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objdump/llvm-objdump.cpp
diff options
context:
space:
mode:
authorKristina Bessonova <kbessonova@accesssoftek.com>2022-11-18 19:56:51 +0200
committerKristina Bessonova <kbessonova@accesssoftek.com>2022-12-06 12:19:12 +0200
commit4e958b4d7cd3629d7a21ceea0ea5c4aa1c19e4c0 (patch)
treeafbadd1cfff30a3acb36f449958469392becba6b /llvm/tools/llvm-objdump/llvm-objdump.cpp
parent825da072a8ede585be9d23829f7ac483f2dbae78 (diff)
downloadllvm-4e958b4d7cd3629d7a21ceea0ea5c4aa1c19e4c0.zip
llvm-4e958b4d7cd3629d7a21ceea0ea5c4aa1c19e4c0.tar.gz
llvm-4e958b4d7cd3629d7a21ceea0ea5c4aa1c19e4c0.tar.bz2
[llvm-objdump] Avoid using mapping symbols as branch target labels
The main motivation for this change is to avoid ambiguity because mapping symbol names may not be unique across a binary and do not allow uniquely identifying target address. So that mapping symbols used as branch target labels make llvm-objdump output less readable. Another point is that mapping symbols sometimes appear in non-allocatable sections, like debug info sections which make objdump output even more confusing. For example, a small AArch64 executable may contain plenty of `$d[.*]` symbols and none of them would be useful as a label for resolving a branch or a memory operand target address: ``` 0000000000000254 l .note.ABI-tag 0000000000000000 $d 00000000000008d4 l .eh_frame 0000000000000000 $d 0000000000000868 l .rodata 0000000000000000 $d 0000000000011028 l .data 0000000000000000 $d 0000000000010db8 l .fini_array 0000000000000000 $d 0000000000010db0 l .init_array 0000000000000000 $d 00000000000008e8 l .eh_frame 0000000000000000 $d 0000000000011034 l .bss 0000000000000000 $d ``` Note that GNU objdump doesn't use mapping symbols as branch target labels for all targets that support such symbols (ARM, AArch64, CSKY). Differential Revision: https://reviews.llvm.org/D139131
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r--llvm/tools/llvm-objdump/llvm-objdump.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 422e6e5..ab66e1b 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -463,6 +463,11 @@ static bool hasMappingSymbols(const ObjectFile &Obj) {
return isArmElf(Obj) || isAArch64Elf(Obj) || isCSKYElf(Obj) ;
}
+static bool isMappingSymbol(const SymbolInfoTy &Sym) {
+ return Sym.Name.startswith("$d") || Sym.Name.startswith("$x") ||
+ Sym.Name.startswith("$a") || Sym.Name.startswith("$t");
+}
+
static void printRelocation(formatted_raw_ostream &OS, StringRef FileName,
const RelocationRef &Rel, uint64_t Address,
bool Is64Bits) {
@@ -1877,10 +1882,17 @@ static void disassembleObject(const Target *TheTarget, ObjectFile &Obj,
auto It = llvm::partition_point(
*TargetSymbols,
[=](const SymbolInfoTy &O) { return O.Addr <= Target; });
- if (It != TargetSymbols->begin()) {
- TargetSym = &*(It - 1);
- break;
+ while (It != TargetSymbols->begin()) {
+ --It;
+ // Skip mapping symbols to avoid possible ambiguity as they
+ // do not allow uniquely identifying the target address.
+ if (!hasMappingSymbols(Obj) || !isMappingSymbol(*It)) {
+ TargetSym = &*It;
+ break;
+ }
}
+ if (TargetSym)
+ break;
}
// Print the labels corresponding to the target if there's any.