]> git.ipfire.org Git - thirdparty/linux.git/commit
scripts/gen-btf.sh: Ensure initial object in gen_btf_o is ELF with correct endianness
authorNathan Chancellor <nathan@kernel.org>
Tue, 6 Jan 2026 22:44:20 +0000 (15:44 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 7 Jan 2026 05:00:38 +0000 (21:00 -0800)
commit2421649778dca8fe6e7b166905e97278aa0fdf58
tree4ed8cb7091ba61e141f62a0ee6f50f02ec7013d4
parentf39703b20b57126b6acbb2ed32bf81e3c8ec9f96
scripts/gen-btf.sh: Ensure initial object in gen_btf_o is ELF with correct endianness

After commit 600605853f87 ("scripts/gen-btf.sh: Fix .btf.o generation
when compiling for RISCV"), there is an error from llvm-objcopy when
CONFIG_LTO_CLANG is enabled:

  llvm-objcopy: error: '.tmp_vmlinux1.btf.o': The file was not recognized as a valid object file
  Failed to generate BTF for vmlinux

KBUILD_CFLAGS includes CC_FLAGS_LTO, which makes clang emit an LLVM IR
object, rather than an ELF one as expected by llvm-objcopy.

Most areas of the kernel deal with this by filtering out CC_FLAGS_LTO
from KBUILD_CFLAGS for the particular object or directory but this is
not so easy to do in bash. Just include '-fno-lto' after KBUILD_CFLAGS
to ensure an ELF object is consistently created as the initial .o file.

Additionally, while there is no reported or discovered bug yet, the
absence of KBUILD_CPPFLAGS from this command could result in incorrect
endianness because KBUILD_CPPFLAGS typically contains '-mbig-endian' and
'-mlittle-endian' so that biendian toolchains can be used. Include it in
this ${CC} command to hopefully limit necessary changes to this command
for the foreseeable future.

Fixes: 600605853f87 ("scripts/gen-btf.sh: Fix .btf.o generation when compiling for RISCV")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Acked-by: Ihor Solodrai <ihor.solodrai@linux.dev>
Link: https://lore.kernel.org/r/20260106-fix-gen-btf-sh-lto-v2-1-01d3e1c241c4@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
scripts/gen-btf.sh