[all-commits] [llvm/llvm-project] d15f96: [BPF][DebugInfo] Show CO-RE relocations in llvm-ob...

eddyz87 via All-commits all-commits at lists.llvm.org
Thu Sep 21 12:00:31 PDT 2023

  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: d15f96fe4b64e24d262fcc727dc0eede327804ba
  Author: Eduard Zingerman <eddyz87 at gmail.com>
  Date:   2023-09-21 (Thu, 21 Sep 2023)

  Changed paths:
    M llvm/include/llvm/DebugInfo/BTF/BTF.h
    M llvm/include/llvm/DebugInfo/BTF/BTFParser.h
    M llvm/lib/DebugInfo/BTF/BTFContext.cpp
    M llvm/lib/DebugInfo/BTF/BTFParser.cpp
    M llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp
    M llvm/lib/Target/BPF/BPFCORE.h
    M llvm/lib/Target/BPF/BPFPreserveDIType.cpp
    M llvm/lib/Target/BPF/BTFDebug.cpp
    A llvm/test/tools/llvm-objdump/BPF/core-relo-byte-offset.ll
    A llvm/test/tools/llvm-objdump/BPF/core-relo-enum-value.ll
    A llvm/test/tools/llvm-objdump/BPF/core-relo-field-info.ll
    A llvm/test/tools/llvm-objdump/BPF/core-relo-formatting.s
    A llvm/test/tools/llvm-objdump/BPF/core-relo-type-id.ll
    A llvm/test/tools/llvm-objdump/BPF/core-relo-type-info.ll
    M llvm/tools/llvm-objdump/CMakeLists.txt
    M llvm/tools/llvm-objdump/llvm-objdump.cpp
    M llvm/unittests/DebugInfo/BTF/BTFParserTest.cpp

  Log Message:
  [BPF][DebugInfo] Show CO-RE relocations in llvm-objdump

Extend llvm-objdump to show CO-RE relocations when `-r` option is
passed and object file has .BTF and .BTF.ext sections.

For example, the following C program:

    #define __pai __attribute__((preserve_access_index))

    struct foo { int i; int j;} __pai;
    struct bar { struct foo f[7]; } __pai;
    extern void sink(void *);

    void root(struct bar *bar) {

Should lead to the following objdump output:

    $ clang --target=bpf -O2 -g t.c -c -o - | \
        llvm-objdump  --no-addresses --no-show-raw-insn -dr -

            r2 = 0x94
                    CO-RE <byte_off> [2] struct bar::[2].f[3].j (2:0:3:1)
            r1 += r2
            call -0x1
                    R_BPF_64_32     sink

More examples could be found in unit tests, see BTFParserTest.cpp.

To achieve this:
- Move CO-RE relocation kinds definitions from BPFCORE.h to BTF.h.
- Extend BTF.h with types derived from BTF::CommonType, e.g.
  BTF::IntType and BTF::StrutType, to allow dyn_cast() and access to
  type additional data.
- Extend BTFParser to load BTF type and relocation data.
- Modify llvm-objdump.cpp to create instance of BTFParser when
  disassembly of object file with BTF sections is processed and `-r`
  flag is supplied.

Additional information about CO-RE is available at [1].

[1] https://docs.kernel.org/bpf/llvm_reloc.html

Depends on D149058

Differential Revision: https://reviews.llvm.org/D150079

More information about the All-commits mailing list