[PATCH] binutils: Improve symbols lookup
Borislav Petkov
bp@suse.de
Wed Dec 11 16:06:00 GMT 2019
When objdumping the linux kernel, looking up in-line, auxiliary symbols
like this:
c7 05 d6 61 27 1a 00 movl $0x0,0x1a2761d6(%rip) # ffffffff9b6c5000 <__smp_locks_end>
is not optimal because there are multiple symbols at that address:
729871: ffffffff9b6c5000 0 NOTYPE GLOBAL DEFAULT 65 __nosave_begin
790965: ffffffff9b6c5000 4 OBJECT GLOBAL DEFAULT 65 in_suspend
804323: ffffffff9b6c5000 0 NOTYPE GLOBAL DEFAULT 63 __smp_locks_end
and the current binary search can stop somewhere in that set of symbols
with that address.
Add a heuristic which prefers "complete" symbols, i.e., OBJECT and FUNC
symbols to NOTYPE ones with the same address.
With that, the above line points to the correct symbol which is the one
used in the code too:
8b 05 99 cc 26 1a mov 0x1a26cc99(%rip),%eax # ffffffff9b6c5000 <in_suspend>
* objdump.c (find_symbol_for_address): Add a neuristic to improve
symbols lookup when multiple symbols with the same address present.
---
binutils/ChangeLog | 5 +++++
binutils/objdump.c | 7 +++++++
2 files changed, 12 insertions(+)
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index d91298924cfe..95ca9fba4f7e 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,8 @@
+2019-12-03 Borislav Petkov <bp@suse.de>
+
+ * objdump.c (find_symbol_for_address): Add a neuristic to improve
+ symbols lookup when multiple symbols with the same address present.
+
2019-11-22 Andrew Burgess <andrew.burgess@embecosm.com>
* dwarf.c (regname_internal_riscv): New function.
diff --git a/binutils/objdump.c b/binutils/objdump.c
index 6a1f142a0ebc..0036020e32e4 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -1129,6 +1129,13 @@ find_symbol_for_address (bfd_vma vma,
*place = thisplace;
return sorted_syms[thisplace];
+ } else if (sym_ok (FALSE, abfd, min, sec, inf)) {
+
+ /* Couldn't find a symbol in the current section, try any
+ section but prefer OBJECT or FUNC types to NOTYPE symbols. */
+ if (!(sorted_syms[thisplace]->flags & (BSF_OBJECT | BSF_FUNCTION))
+ && (sorted_syms[min]->flags & (BSF_OBJECT | BSF_FUNCTION)))
+ thisplace = min;
}
++min;
}
--
2.21.0
More information about the Binutils
mailing list