[all-commits] [llvm/llvm-project] 039586: [BPF] Make llvm-objdump disasm default cpu v4 (#10...

yonghong-song via All-commits all-commits at lists.llvm.org
Tue Aug 6 18:24:10 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 03958680b23dafd961ea0606c77d8e6bc8d80781
      https://github.com/llvm/llvm-project/commit/03958680b23dafd961ea0606c77d8e6bc8d80781
  Author: yonghong-song <yhs at fb.com>
  Date:   2024-08-06 (Tue, 06 Aug 2024)

  Changed paths:
    M llvm/lib/Object/ELFObjectFile.cpp
    M llvm/test/CodeGen/BPF/objdump_atomics.ll
    M llvm/test/CodeGen/BPF/objdump_cond_op.ll
    M llvm/test/CodeGen/BPF/objdump_imm_hex.ll
    M llvm/test/CodeGen/BPF/objdump_static_var.ll
    M llvm/test/MC/BPF/insn-unit.s
    M llvm/test/MC/BPF/load-store-32.s

  Log Message:
  -----------
  [BPF] Make llvm-objdump disasm default cpu v4 (#102166)

Currently, with the following example,
  $ cat t.c
  void foo(int a, _Atomic int *b)
  {
   *b &= a;
  }
  $ clang --target=bpf -O2 -c -mcpu=v3 t.c
  $ llvm-objdump -d t.o
  t.o:    file format elf64-bpf

  Disassembly of section .text:

  0000000000000000 <foo>:
       0:       c3 12 00 00 51 00 00 00 <unknown>
       1:       95 00 00 00 00 00 00 00 exit

Basically, the default cpu for llvm-objdump is v1 and it won't be able
to decode insn properly.

If we add --mcpu=v3 to llvm-objdump command line, we will have
  $ llvm-objdump -d --mcpu=v3 t.o

  t.o:    file format elf64-bpf

  Disassembly of section .text:

  0000000000000000 <foo>:
0: c3 12 00 00 51 00 00 00 w1 = atomic_fetch_and((u32 *)(r2 + 0x0), w1)
       1:       95 00 00 00 00 00 00 00 exit

The atomic_fetch_and insn can be decoded properly. Using latest cpu
version --mcpu=v4 can also decode properly like the above --mcpu=v3.

To avoid the above '<unknown>' decoding with common 'llvm-objdump -d
t.o', this patch marked the default cpu for llvm-objdump with the
current highest cpu number v4 in ELFObjectFileBase::tryGetCPUName(). The
cpu number in ELFObjectFileBase::tryGetCPUName() will be adjusted in the
future if cpu number is increased e.g. v5 etc. Such an approach also
aligns with gcc-bpf as discussed in [1].

Six bpf unit tests are affected with this change. I changed test output
for three unit tests and added --mcpu=v1 for the other three unit tests,
to demonstrate the default (cpu v4) behavior and explicit --mcpu=v1
behavior.

[1]
https://lore.kernel.org/bpf/6f32c0a1-9de2-4145-92ea-be025362182f@linux.dev/T/#m0f7e63c390bc8f5a5523e7f2f0537becd4205200

Co-authored-by: Yonghong Song <yonghong.song at linux.dev>



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list