<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/62537>62537</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
llvm-objdump does not disassembly PLT subs of some DSOs produced by GNU toolchain.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
dougkwan
</td>
</tr>
</table>
<pre>
Some toolchains (e.g. gcc 12) may create shared objects without .got.plt sections and use .got for PLT entires. llvm-objdump fails to disassemble PLT stub entries of such objects. The followings show outputs from llvm-objdump and objdump in GNU binutils.
The problem with the current llvm-objdump is that it just looks for the .got.plt section. If it is absent, it does not add any PLT symbols. Some toolchains may not use a separate .got.plt section and just use a single .got section bot both PLT and non-PLT dynamic relocations.
1. Disassembly produced by a recent version of llvm-objdump. Note the PLT stub at 0x2040 without a label.
Disassembly of section .plt:
0000000000002020 <.plt>:
...
2036: 68 00 00 00 00 pushq $0x0
203b: e9 e0 ff ff ff jmp 0x2020 <.plt>
2040: ff 25 72 ce 00 00 jmpq *0xce72(%rip) # 0xeeb8 <_GLOBAL_OFFSET_TABLE_+0x20>
2046: 68 01 00 00 00 pushq $0x1
204b: e9 d0 ff ff ff jmp 0x2020 <.plt>
2050: ff 25 6a ce 00 00 jmpq *0xce6a(%rip) # 0xeec0 <_GLOBAL_OFFSET_TABLE_+0x28>
2056: 68 02 00 00 00 pushq $0x2
205b: e9 c0 ff ff ff jmp 0x2020 <.plt>
2060: ff 25 62 ce 00 00 jmpq *0xce62(%rip) # 0xeec8 <_GLOBAL_OFFSET_TABLE_+0x30>
2066: 68 03 00 00 00 pushq $0x3
2. Disassembly by gnu objdump:
Disassembly of section .plt:
...
2036: 68 00 00 00 00 push $0x0
203b: e9 e0 ff ff ff jmp 2020 <_init+0x20>
0000000000002040 <sb_newf@plt>:
2040: ff 25 72 ce 00 00 jmp *0xce72(%rip) # eeb8 <sb_newf@Base>
2046: 68 01 00 00 00 push $0x1
204b: e9 d0 ff ff ff jmp 2020 <_init+0x20>
I believe the problem is at least in llvm-project/llvm/lib/Object/ELFObjectFile.cpp. The following patch fixes this particular instance of the problem but I was told that it is incomplete as the "-z lazy" case is not handled.
==== a/llvm/lib/Object/ELFObjectFile.cpp#46 - b/llvm/llvm-project/llvm/lib/Object/ELFObjectFile.cpp ====
627c627
< std::optional<SectionRef> Plt, RelaPlt, GotPlt;
---
> std::optional<SectionRef> Plt, RelaPlt, GotPlt, Got;
641a642,643
> else if (Name == ".got")
> Got = Section;
643c645,650
< if (!Plt || !RelaPlt || !GotPlt)
---
>
> // Some toolchains do not use a seperate .got.plt section. Fall back
> // to .got if .got.plt is absent.
> std::optional<SectionRef> GotToSearch = GotPlt ? GotPlt : Got;
>
> if (!Plt || !RelaPlt || !GotToSearch)
652c659
< GotPlt->getAddress(), Triple);
---
> GotToSearch->getAddress(), Triple);
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykV91vo7oS_2ucl1GQYwNJHvKQfqRaqdquTnufK9sMwV2DOdhsm_PXXxnyAbnpNvesRYKB8Xz8ZsYzFs7pbYW4IskNSe4movWFbVaZbbc_30U1kTbbrZ5tieCtNaoQunJA2AKjbQRbpWDGCFtCKXagGhQewRWiwQysfEPlHcC79oVtPURb66PaeHCovLaVA1Fl0DrsvkBuG_jx-AJYed2gi8CYX-XUyresLWvIhTYOvIVMO-EcltJgR-58K8OaRqMDm4NrVXGQHcFLgZBbY-y7rrYOXGHfwba-br2DvLHlWEjQ5zDXFTx8_w9IXbVeGxcRekfouv8PXOvGSoNlZx34AkG1TYOVH3PUDnwhPGgPb63zYKz96TpTw5JzRCL4lgdS7UBIh5Un7DY8ZxYdVNaDyDIQ1a43fFdKa1wE584JrgjEAVkBDmvRBLecC-us7ZTaE-pqa_a-OJBI68Ov6AQG-spW0zDPdpUotYIGjVWi8-YIoVkEd0dH7QJYWaswA7kDAQ2qANQvbFwQY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