[llvm-objdump] improve disassembler symbol search #145253
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Relevant after #144620 is merged.
This PR changes how
llvm-objdump
picks candidate sections to choose symbols and labels for address resolution. Currentlyllvm-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: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:while disassembly with
riscv64-linux-gnu-objdump -d test
yieldsBinutils auipc+ld sequence prints address resolution but this is not the case with llvm, which is exactly what this PR addresses