Skip to content

[llvm-objdump] improve disassembler symbol search #145253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

arjunUpatel
Copy link

Relevant after #144620 is merged.

This PR changes how llvm-objdump picks candidate sections to choose symbols and labels for address resolution. Currently llvm-objdump adds only the symbols and labels in the set of sections that are closest to a target address at an address less than the target address. The problem is that this section may not contain any symbols. As a fallback, absolute symbols are added to the set of candidate sections but these are also not guaranteed to be there. Hence, we run into cases of disassemblies where no address resolution is emitted despite labels/symbols existing in addresses lower than the target address. This is illustrated by this test:

.text
test:
  la a0, gdata
  .skip 0x100000

ldata:
  .int 0

.data
gdata:
  .int 0

Credits to @PiJoules for coming up with this test in #108469.

Compiled with:
clang --target=fuchsia-elf-riscv64 -march=rv64g test.s -nostdlib -o test

Disassembly with llvm-objdump -d test yields:

0000000000001000 <_start>:
    1000: 00101517     	auipc	a0, 0x101
    1004: 00853503     	ld	a0, 0x8(a0)

while disassembly with riscv64-linux-gnu-objdump -d test yields

0000000000001000 <_start>:
    1000:	00101517          	auipc	a0,0x101
    1004:	00853503          	ld	a0,8(a0) # 102008 <ldata+0x1000>

Binutils auipc+ld sequence prints address resolution but this is not the case with llvm, which is exactly what this PR addresses

Previously, the loop would only add labels in the set of sections that were closest to Target. Set of section here because multiple sections can have the same address, so all of their symbols would be added to the set of candidate symbols. The following changes make it such that we loop down from sections closest to the Target and populate the set of candidate symbols with symbols from the first set of sections that do contain symbols
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@arjunUpatel arjunUpatel changed the title Objdump symbol search [llvm-ojdump] improve disassembler symbol search Jun 23, 2025
@arjunUpatel arjunUpatel changed the title [llvm-ojdump] improve disassembler symbol search [llvm-objdump] improve disassembler symbol search Jun 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant