[PATCH v2] backends,bpf: add proper relocation support

Yonghong Song yhs@fb.com
Wed Jun 20 14:18:00 GMT 2018



On 6/20/18 4:41 AM, Mark Wielaard wrote:
> On Sat, 2018-06-16 at 13:02 -0700, Yonghong Song wrote:
>> Due to libdw does not have proper BPF relocation support,
>> the pahole cannot display filenames correctly for objects
>> with default llvm options. So we have to invent
>> a special option "llc -march=bpf -mattr=dwarfris" to
>> prevent llvm from generating cross-section dwarf relocation
>> records (https://urldefense.proofpoint.com/v2/url?u=https-3A__reviews.llvm.org_rL326505&d=DwIFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=DA8e1B5r073vIqRrFz7MRA&m=BipW-mskUvazgUra_yLXaDDQuxRPN7odXPkQGoyQPCY&s=o2hBnG4NsHUyYJPq0YMC9vTjoTet5flJ1AnhjW8tDBw&e=).
>> The pahole related discussion is in linux netdev
>> mailing list (https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.openwall.net_netdev_2018_06_15_38&d=DwIFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=DA8e1B5r073vIqRrFz7MRA&m=BipW-mskUvazgUra_yLXaDDQuxRPN7odXPkQGoyQPCY&s=oqLz1O0PLduCn5Y2DVhr5yIpsLrSZ4GoRbHcZs5ZocA&e=, etc.)
>>
>> We would like to add proper BPF relocation support
>> to libdw so eventually we could retire the special llc bpf
>> flag "-mattr=dwarfris".
>>
>> The bpf relocations are defined in
>> llvm_repo:include/llvm/BinaryFormat/ELFRelocs/BPF.def:
>>    ELF_RELOC(R_BPF_NONE,        0)
>>    ELF_RELOC(R_BPF_64_64,       1)
>>    ELF_RELOC(R_BPF_64_32,      10)
>>
>> Removed the relocation type R_BPF_MAP_FD whoes name does not
>> confirm to llvm definition and replaced it with R_BPF_64_64.
>> The BPF object is just a relocatible object, not an executable or
>> a shared library, so assign ELF type to REL only in bpf_reloc.def.
>>
>> Signed-off-by: Yonghong Song <yhs@fb.com>
>> ---
>>   backends/ChangeLog                  |   7 +++++
>>   backends/Makefile.am                |   2 +-
>>   backends/bpf_init.c                 |   1 +
>>   backends/bpf_reloc.def              |   3 +-
>>   backends/bpf_symbol.c               |  54
>> ++++++++++++++++++++++++++++++++++++
>>   libelf/elf.h                        |   3 +-
>>   tests/ChangeLog                     |   9 ++++++
>>   tests/Makefile.am                   |   5 +++-
>>   tests/run-reloc-bpf.sh              |  33 ++++++++++++++++++++++
>>   tests/testfile-bpf-reloc.expect.bz2 | Bin 0 -> 300 bytes
>>   tests/testfile-bpf-reloc.o.bz2      | Bin 0 -> 933 bytes
>>   11 files changed, 113 insertions(+), 4 deletions(-)
>>   create mode 100644 backends/bpf_symbol.c
>>   create mode 100755 tests/run-reloc-bpf.sh
>>   create mode 100644 tests/testfile-bpf-reloc.expect.bz2
>>   create mode 100644 tests/testfile-bpf-reloc.o.bz2
>>
>> Note:
>>   I didn't add the Changelog to libelf/elf.h as I anticipate the
>>   change will come from sync'ing with glibc.
>>   If this patch version looks good, I can send another revision
>>   once the libelf/elf.h is synced.
> 
> The patch looks perfect. And the new testcase is good. I used the
> testfile to quickly test eu-readelf --debug-dump also got the
> relocations right, and it did of course.
> 
> Just waiting for the glibc elf.h update/sync and then I'll push this to
> master.

This looks perfect. Thanks!

> 
> Thanks,
> 
> Mark
> 



More information about the Elfutils-devel mailing list