Re: [PATCH v3 03/21] perf llvm: Fix arm64 adrp instruction disassembly mismatch with objdump
From: Namhyung Kim
Date: Thu Jul 16 2026 - 17:13:14 EST
On Thu, Jul 16, 2026 at 08:46:01PM +0800, Tengda Wu wrote:
>
>
> On 2026/7/9 15:49, Tengda Wu wrote:
> >
> >
> > On 2026/7/9 14:18, Namhyung Kim wrote:
> >> On Wed, Jul 01, 2026 at 03:53:37AM +0000, Tengda Wu wrote:
> >>> The operands of 'adrp' instructions parsed by libllvm are currently
> >>> represented as raw immediates rather than the "address <symbol+offset>"
> >>> format used by objdump. This inconsistency causes arm64_mov__parse()
> >>> to fail when parsing these instructions during post-processing.
> >>>
> >>> Example of the mismatch:
> >>> Current: adrp x18, 8014
> >>> Fix: adrp x18, ffff800081f5f000 <this_cpu_vector>
> >>>
> >>> Fix this by manually extracting the target address from the raw adrp
> >>> instruction via symbol_lookup_callback(). The address is then converted
> >>> to a specific symbol during symbol__disassemble_llvm() and formatted
> >>> to match objdump's output, ensuring compatibility with existing
> >>> parsers.
> >>>
> >>> Signed-off-by: Tengda Wu <wutengda@xxxxxxxxxxxxxxx>
> >>> ---
> >>> tools/perf/util/llvm.c | 50 ++++++++++++++++++++++++++++++++++++++++++
> >>> 1 file changed, 50 insertions(+)
> >>>
> >>> diff --git a/tools/perf/util/llvm.c b/tools/perf/util/llvm.c
> >>> index a0deb742a733..533d47e8084d 100644
> >>> --- a/tools/perf/util/llvm.c
> >>> +++ b/tools/perf/util/llvm.c
> >>> @@ -94,6 +94,7 @@ static void init_llvm(void)
> >>> struct symbol_lookup_storage {
> >>> u64 branch_addr;
> >>> u64 pcrel_load_addr;
> >>> + u64 pcrel_adrp_addr;
> >>> };
> >>>
> >>> static const char *
> >>> @@ -108,6 +109,18 @@ symbol_lookup_callback(void *disinfo, uint64_t value,
> >>> storage->branch_addr = value;
> >>> else if (*ref_type == LLVMDisassembler_ReferenceType_In_PCrel_Load)
> >>> storage->pcrel_load_addr = value;
> >>
> >> Is this used by arm64? If not, would be possible to reuse
> >> pcrel_load_addr unless it'd complicate the code significantly?
> >>
> >> I think it's the common concept of PC-relative addressing while it
> >> requires two instructions to set up the final address on arm64.
> >>
> >> Thanks,
> >> Namhyung
> >>
>
> I checked the LLVM internal implementation and conducted further experiments.
> You are correct, arm64 does not trigger LLVMDisassembler_ReferenceType_In_PCrel_Load
> at all. Instead, it utilizes its own architecture-specific reference types
> like LLVMDisassembler_ReferenceType_In_ARM64_ADRP, _LDRXl, etc.
> Therefore, 'pcrel_load_addr' is completely safe to reuse here.
>
> I will reuse 'pcrel_load_addr' to avoid adding unnecessary fields and
> optimize this patch in the next version.
Great, thanks for looking into it.
Thanks,
Namhyung