<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/75539>75539</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
llvm-objdump prints out unrelated relocations when disassembling specific symbols
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
mppf
</td>
</tr>
</table>
<pre>
I'm running into a problem that `llvm-objdump` has (at least as of LLVM 17) that does not seem to be present in GNU objdump. It seems to be printing out too many relocation entries when disassembling a specific symbol.
For an example, let's compile this C program to a .o file:
``` c
#include <math.h>
#include <stdio.h>
void foo(void);
void foo(void) {
printf("test1\n");
printf("test2\n");
printf("test3\n");
printf("test4\n");
putchar(0);
}
int main(int argc, char** argv) {
return sqrt(argc);
}
```
```
$ clang-17 -c hello.c
```
Now, we can ask for `llvm-objdump-17` to disassemble only `main`:
```
$ llvm-objdump-17 --disassemble-symbols=main hello.o
hello.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000050 <main>:
50: 55 pushq %rbp
51: 48 89 e5 movq %rsp, %rbp
54: 48 83 ec 10 subq $0x10, %rsp
58: c7 45 fc 00 00 00 00 movl $0x0, -0x4(%rbp)
5f: 89 7d f8 movl %edi, -0x8(%rbp)
62: 48 89 75 f0 movq %rsi, -0x10(%rbp)
66: f2 0f 2a 45 f8 cvtsi2sdl -0x8(%rbp), %xmm0
6b: e8 00 00 00 00 callq 0x70 <main+0x20>
70: f2 0f 2c c0 cvttsd2si %xmm0, %eax
74: 48 83 c4 10 addq $0x10, %rsp
78: 5d popq %rbp
79: c3 retq
```
However, this is unsatisfying because the `callq` there gives no indication that it is calling `sqrt`. So, we can add the `-r` flag to show the relocations:
```
$ llvm-objdump-17 --disassemble-symbols=main -r hello.o
hello.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000050 <main>:
50: 55 pushq %rbp
0000000000000007: R_X86_64_PC32 .L.str-0x4
000000000000000e: R_X86_64_PLT32 printf-0x4
0000000000000015: R_X86_64_PC32 .L.str.1-0x4
000000000000001c: R_X86_64_PLT32 printf-0x4
0000000000000023: R_X86_64_PC32 .L.str.2-0x4
000000000000002a: R_X86_64_PLT32 printf-0x4
0000000000000031: R_X86_64_PC32 .L.str.3-0x4
0000000000000038: R_X86_64_PLT32 printf-0x4
000000000000003f: R_X86_64_PLT32 putchar-0x4
51: 48 89 e5 movq %rsp, %rbp
54: 48 83 ec 10 subq $0x10, %rsp
58: c7 45 fc 00 00 00 00 movl $0x0, -0x4(%rbp)
5f: 89 7d f8 movl %edi, -0x8(%rbp)
62: 48 89 75 f0 movq %rsi, -0x10(%rbp)
66: f2 0f 2a 45 f8 cvtsi2sdl -0x8(%rbp), %xmm0
6b: e8 00 00 00 00 callq 0x70 <main+0x20>
000000000000006c: R_X86_64_PLT32 sqrt-0x4
70: f2 0f 2c c0 cvttsd2si %xmm0, %eax
74: 48 83 c4 10 addq $0x10, %rsp
78: 5d popq %rbp
79: c3 retq
```
Now we can see the relocation printed just after the `callq` to show us it is calling `sqrt`.
However, there is a problem. It's showing a whole lot of unrelated relocations after the first instruction in `main`. It is just a few lines in the example above, but when disassembling a single symbol from a large .o file with `-r`, this turns into an ocean of text.
GNU objdump does not have this issue and it just shows the `sqrt` relocation in this case:
```
$ objdump --disassemble=main -r hello.o
hello.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000050 <main>:
50: 55 push %rbp
51: 48 89 e5 mov %rsp,%rbp
54: 48 83 ec 10 sub $0x10,%rsp
58: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%rbp)
5f: 89 7d f8 mov %edi,-0x8(%rbp)
62: 48 89 75 f0 mov %rsi,-0x10(%rbp)
66: f2 0f 2a 45 f8 cvtsi2sdl -0x8(%rbp),%xmm0
6b: e8 00 00 00 00 call 70 <main+0x20>
6c: R_X86_64_PLT32 sqrt-0x4
70: f2 0f 2c c0 cvttsd2si %xmm0,%eax
74: 48 83 c4 10 add $0x10,%rsp
78: 5d pop %rbp
79: c3 ret
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWE2P27wR_jX0ZWCDor4PPiS73fYF0qDoF3oLKGlkMaVER6Rs778vhpLXsi1vgqA99EUEw-u1Zh7OjIbPw7G0Vu06xC2LP7L4eSUH15h-2-739aow1ev2NybSFvqh61S3A9U5AxL2vSk0tuAa6YAlXOtDuzbF12po9yzh0EgLTGTSgUZpHUgLpoZPn_75ZwhSJvLRsTJooTMOLBKWgQJh36PFzoHq4I-f_wET5gZ-G63sm5nqHAVkBgfOGGhl9wo9alNKp0wH2LleoYVjgx1UykprsS00uUiweyxVrUqwr21h9IbxZ8Y_jO8vpgfZAZ5ku9fIxBNodEykFkrT7pVGcI2y8EQ12PXSxy1hY6BWGln4YY7FEj6-oJy-EKHqSj1UCCx8aqVrNg0L_7B007pKmfld_34wqoLaGCYy-shEzsKPj24BS6d7MBasZiJjQji0LmDxU8eEmCPcGYklozur8EegomWowZWN7JnI-PwGS5_nSavOQStVx0RGH2W_K-m5jJ4fmPhAXx1uEu7RDX0H9lvvqBO9z9IK50e0-NzODyaCUstutw5SWJfQoNZmU74D8NkcKcIjQik7kPbfUJv-dqOsg5Raw5lZfyKYTr-SpU844Y866hLZDSSs1zO49djhloXPBDiFbuaQ569ooZyamGJtpQPUdRKtT1myTqK5w_Mb_Cvtaoul33Ebhyd3Ey6_umI-dr3qqKvPluCvmDKFOAbG8_1gm2-M50zEfbG_sgrIKsogywG9bWsOZ1O7p5ovOEVnpxCwhIDD3cV4bodiBIr4KeBnJHuNlBFSmUIUQ10C55fXDKk1B31G8kBrfor8TvCRiXyCjGtCy3JIK6iz-6Bu0GKs1ISWLaD5KxGX-qQx1Mupzmt2hqSUH2AmhFkL4DUI6VO_DZbxvDw4q4StKNa7CMdintqWXwEXBIzZVR0JSmpN8fFTemkY8ZGfBH9jwxEh5bPQSij5FImzlbBqTNGvOgaA8nTlPeuLMqK-YDyXVfXdNk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