Bug 24702 - objdump: use STT_SECTION symbol in the symbolizer
Summary: objdump: use STT_SECTION symbol in the symbolizer
Status: UNCONFIRMED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.33
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-06-19 03:32 UTC by Fangrui Song
Modified: 2021-01-07 20:38 UTC (History)
1 user (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fangrui Song 2019-06-19 03:32:20 UTC
STT_SECTION symbols are not used to symbolize addresses in objdump -d output, but that will be useful when the relevant symbols are missing.

e.g. In a typical disassembly listing of the .plt section in an x86-64 program:

Disassembly of section .plt:

00000000002011f0 <printf@plt-0x10>:
                  ^^^^^^^^ it would be nice to symbolize this as: .plt
  2011f0:       ff 35 22 1e 00 00       pushq  0x1e22(%rip)        # 203018 <__TMC_END__+0x8>
  2011f6:       ff 25 24 1e 00 00       jmpq   *0x1e24(%rip)        # 203020 <__TMC_END__+0x10>
  2011fc:       0f 1f 40 00             nopl   0x0(%rax)

0000000000201200 <printf@plt>:
  201200:       ff 25 22 1e 00 00       jmpq   *0x1e22(%rip)        # 203028 <printf@GLIBC_2.2.5>
  201206:       68 00 00 00 00          pushq  $0x0
  20120b:       e9 e0 ff ff ff          jmpq   2011f0 <_fini+0x14>
                                                       ^^^^ if there is a symbol with a greater address than .plt, this may be symbolized as: foo-0x34
                                                       ^^^^ In any case, jmpq 2011f0 <.plt> will look better
Comment 1 Fangrui Song 2021-01-07 20:38:17 UTC
The idea is that section+offset should be preferred over far_away_symbol+large_offset because the former is more relevant.

Update: d1bcae833b32f1408485ce69f844dcd7ded093a8 ("ELF: Don't generate unused section symbols") may reveal more instances. This suggests that even in the absence of STT_SECTION (they are optional, not useful if no relocation references them), we should synthesize them from section headers.

--- a/ld/testsuite/ld-x86-64/pr21038b.d
+++ b/ld/testsuite/ld-x86-64/pr21038b.d
@@ -53,7 +53,7 @@ Disassembly of section .plt:
  +[a-f0-9]+:   f2 ff 25 53 0e 20 00    bnd jmp \*0x200e53\(%rip\)        # 201010 <_GLOBAL_OFFSET_TABLE_\+0x10>
  +[a-f0-9]+:   0f 1f 00                nopl   \(%rax\)
  +[a-f0-9]+:   68 00 00 00 00          push   \$0x0
- +[a-f0-9]+:   f2 e9 e5 ff ff ff       bnd jmp 1b0 <.plt>
+ +[a-f0-9]+:   f2 e9 e5 ff ff ff       bnd jmp 1b0 <func@plt-0x20>
  +[a-f0-9]+:   0f 1f 44 00 00          nopl   0x0\(%rax,%rax,1\)


- +[a-f0-9]+:   e9 e0 ff ff ff          jmp    180 <.plt>
+ +[a-f0-9]+:   e9 e0 ff ff ff          jmp    180 <\*ABS\*@plt-0x10>


--- a/ld/testsuite/ld-ifunc/ifunc-21-x86-64.d
+++ b/ld/testsuite/ld-ifunc/ifunc-21-x86-64.d
@@ -9,11 +9,11 @@
 Disassembly of section .text:
 
 0+4000c8 <__start>:
- +[a-f0-9]+:   ff 15 2a 00 20 00       call   \*0x20002a\(%rip\)        # 6000f8 <.got>
- +[a-f0-9]+:   ff 25 24 00 20 00       jmp    \*0x200024\(%rip\)        # 6000f8 <.got>
- +[a-f0-9]+:   48 03 05 1d 00 20 00    add    0x20001d\(%rip\),%rax        # 6000f8 <.got>
- +[a-f0-9]+:   48 8b 05 16 00 20 00    mov    0x200016\(%rip\),%rax        # 6000f8 <.got>
- +[a-f0-9]+:   48 85 05 0f 00 20 00    test   %rax,0x20000f\(%rip\)        # 6000f8 <.got>
+ +[a-f0-9]+:   ff 15 2a 00 20 00       call   \*0x20002a\(%rip\)        # 6000f8 <bar\+0x200007>
+ +[a-f0-9]+:   ff 25 24 00 20 00       jmp    \*0x200024\(%rip\)        # 6000f8 <bar\+0x200007>
+ +[a-f0-9]+:   48 03 05 1d 00 20 00    add    0x20001d\(%rip\),%rax        # 6000f8 <bar\+0x200007>
+ +[a-f0-9]+:   48 8b 05 16 00 20 00    mov    0x200016\(%rip\),%rax        # 6000f8 <bar\+0x200007>
+ +[a-f0-9]+:   48 85 05 0f 00 20 00    test   %rax,0x20000f\(%rip\)        # 6000f8 <bar\+0x200007>
  +[a-f0-9]+:   48 c7 c0 f1 00 40 00    mov    \$0x4000f1,%rax