]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
resolve_btfids: Implement --patch_btfids
authorIhor Solodrai <ihor.solodrai@linux.dev>
Wed, 31 Dec 2025 01:25:57 +0000 (17:25 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 31 Dec 2025 17:04:09 +0000 (09:04 -0800)
commit1a8fa7faf4890d201aad4f5d4943f74d840cd0ba
tree55b0a26f2a9cfb3a890d191edd9d71272a364a18
parentc0e4a193ae91e5dcfbb920b2ba74599b05e2b2eb
resolve_btfids: Implement --patch_btfids

Recent changes in BTF generation [1] rely on ${OBJCOPY} command to
update .BTF_ids section data in target ELF files.

This exposed a bug in llvm-objcopy --update-section code path, that
may lead to corruption of a target ELF file. Specifically, because of
the bug st_shndx of some symbols may be (incorrectly) set to 0xffff
(SHN_XINDEX) [2][3].

While there is a pending fix for LLVM, it'll take some time before it
lands (likely in 22.x). And the kernel build must keep working with
older LLVM toolchains in the foreseeable future.

Using GNU objcopy for .BTF_ids update would work, but it would require
changes to LLVM-based build process, likely breaking existing build
environments as discussed in [2].

To work around llvm-objcopy bug, implement --patch_btfids code path in
resolve_btfids as a drop-in replacement for:

    ${OBJCOPY} --update-section .BTF_ids=${btf_ids} ${elf}

Which works specifically for .BTF_ids section:

    ${RESOLVE_BTFIDS} --patch_btfids ${btf_ids} ${elf}

This feature in resolve_btfids can be removed at some point in the
future, when llvm-objcopy with a relevant bugfix becomes common.

[1] https://lore.kernel.org/bpf/20251219181321.1283664-1-ihor.solodrai@linux.dev/
[2] https://lore.kernel.org/bpf/20251224005752.201911-1-ihor.solodrai@linux.dev/
[3] https://github.com/llvm/llvm-project/issues/168060#issuecomment-3533552952

Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
Link: https://lore.kernel.org/r/20251231012558.1699758-1-ihor.solodrai@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
scripts/gen-btf.sh
scripts/link-vmlinux.sh
tools/bpf/resolve_btfids/main.c
tools/testing/selftests/bpf/Makefile