llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.09k stars 12k forks source link

llvm-objdump doesn't calculate relative branch target address for arm binaries #48862

Open yabinc opened 3 years ago

yabinc commented 3 years ago
Bugzilla Link 49518
Version trunk
OS Linux
Attachments arm binary for testing
CC @DavidSpickett,@eugenis,@MaskRay,@kbeyls,@nickdesaulniers,@ostannard,@pirama-arumuga-nainar,@rupprecht,@stephenhines,@yabinc

Extended Description

For arm binaries, llvm-objdump doesn't calculate relative branch target address. Instead, it only shows offsets from current address. And users need to calculate target address manually. Below is an example:

$ llvm-objdump -dlC --no-show-raw-insn --start-address=0x784 --stop-address=0x7d4 simpleperf_runtest_two_functions_arm

00000784

: ; main(): ... 7a4: movs r1, #​0 ; system/extras/simpleperf/runtest/two_functions.cpp:9 7a6: str.w r1, [r7, r0, lsl #​2] ; system/extras/simpleperf/runtest/two_functions.cpp:8 7aa: adds r1, #​1 7ac: cmp r6, r1 7ae: bne #-12 <main+0x22>

To know the branch target address of bne instruction in 0x7ae, we need to calculate either 0x7ae + 4 - 12, or 0x784 + 0x22. But there is no directly show of 0x7a6.

For comparison, binutils objdump for arm binaries shows branch target address as below:

$ arm-linux-androideabi-objdump -dlC --no-show-raw-insn --start-address=0x784 --stop-address=0x7d4 simpleperf_runtest_two_functions_arm

00000784

: ... system/extras/simpleperf/runtest/two_functions.cpp:9 7a6: str.w r1, [r7, r0, lsl #​2] system/extras/simpleperf/runtest/two_functions.cpp:8 7aa: adds r1, #​1 7ac: cmp r6, r1 7ae: bne.n 7a6 <main+0x22> ...

And llvm-objdump shows branch target address for binaries in other targets, including arm64, x86, x86_64.

yabinc commented 3 years ago

This is follow up from llvm/llvm-project#48730 .