Bug 29847 - objdump: add --show-all-symbols
Summary: objdump: add --show-all-symbols
Status: NEW
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.40
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-12-05 00:32 UTC by Fangrui Song
Modified: 2022-12-08 15:02 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Proposed patch (1.81 KB, patch)
2022-12-08 15:02 UTC, Nick Clifton
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Fangrui Song 2022-12-05 00:32:17 UTC
llvm-objdump 16 will have a new option --show-all-symbols (https://reviews.llvm.org/D131589) which prints all symbols during disassembly.
This is useful to know all symbols defined at a location.

https://github.com/llvm/llvm-project/blob/main/llvm/test/tools/llvm-objdump/multiple-symbols.s and https://github.com/llvm/llvm-project/blob/main/llvm/test/tools/llvm-objdump/multiple-symbols-mangling.s demonstrate the behavior.

Here is some dump for your convenience. You can reproduce by yourself if you have installed llvm-mc and yaml2obj and have cloned llvm-project.

cd llvm-project/llvm/test/tools/llvm-objdump
llvm-mc -triple armv8a-unknown-linux -filetype=obj multiple-symbols.s -o a.o

% fllvm-objdump --triple armv8a -d a.o

a.o:    file format elf32-littlearm

Disassembly of section .text:

00000000 <bbbb>:
       0: e0800080      add     r0, r0, r0, lsl #1
       4: e12fff1e      bx      lr

00000008 <dddd>:
       8: eb00 0080     add.w   r0, r0, r0, lsl #2
       c: 4770          bx      lr
% fllvm-objdump --triple armv8a --show-all-symbols -d a.o

a.o:    file format elf32-littlearm

Disassembly of section .text:

00000000 <$a.0>:
00000000 <aaaa>:
00000000 <bbbb>:
       0: e0800080      add     r0, r0, r0, lsl #1
       4: e12fff1e      bx      lr

00000008 <$t.1>:
00000008 <cccc>:
00000008 <dddd>:
       8: eb00 0080     add.w   r0, r0, r0, lsl #2
       c: 4770          bx      lr
% fllvm-objdump --triple armv8a --disassemble-symbols=aaaa -d a.o

a.o:    file format elf32-littlearm

Disassembly of section .text:

00000000 <aaaa>:
       0: e0800080      add     r0, r0, r0, lsl #1
       4: e12fff1e      bx      lr

(llvm-objdump doesn't have --disassemble[=symbol]. It uses --disassemble-symbols=aaaa)
Comment 1 Nick Clifton 2022-12-08 15:02:37 UTC
Created attachment 14488 [details]
Proposed patch

Hi Fanguri,

  What do you think of the uploaded patch ?

  With it applied, objdump's behaviour is similar to llvm-objdump's:

    % .objdump -d multisym.o --show-all-symbols
    multisym.o:     file format elf32-littlearm

    Disassembly of section .text:

    00000000 <aaaa>:
    00000000 <bbbb>:
       0:	e0800080 	add	r0, r0, r0, lsl #1
    ...etc...

  The difference is that it does not show the <$a.0> symbol.  (Because
  the ARM backend in the BFD library considers it to be an "invalid"
  symbol).

  Personally I prefer this behaviour since those markup symbols are
  rarely useful to the user.

Cheers
  Nick