Skip to contentSkip to conversation

scripts/gen-btf.sh: Fix .btf.o generation when compiling for RISCV

PATCH Applied Ihor Solodrai 2 participants 2 messages Dec 29, 2025 – Dec 30, 2025

Subsystems (2)
lore
Share & tools
lore

Ihor Solodrai

author reviewer
#0 lore raw

PATCH 1/1 scripts/gen-btf.sh: Fix .btf.o generation when compiling for RISCV

gen-btf.sh emits a .btf.o file with BTF sections to be linked into vmlinux in link-vmlinux.sh

This .btf.o file is created by compiling an emptystring with ${CC}, and then adding BTF sections into it with ${OBJCOPY}.

To ensure the .btf.o is linkable when cross-compiling with LLVM, we have to also pass ${KBUILD_FLAGS}, which in particular control the target word size.

---
 scripts/gen-btf.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/gen-btf.sh +1 -1
index 06c6d8becaa2..12244dbe097c 100755
@@ -96,7 +96,7 @@ gen_btf_o()
 	# deletes all symbols including __start_BTF and __stop_BTF, which will
 	# be redefined in the linker script.
 	info OBJCOPY "${btf_data}"
-	echo "" | ${CC} ${CLANG_FLAGS} -c -x c -o ${btf_data} -
+	echo "" | ${CC} ${CLANG_FLAGS} ${KBUILD_CFLAGS} -c -x c -o ${btf_data} -
 	${OBJCOPY} --add-section .BTF=${ELF_FILE}.BTF \
 		--set-section-flags .BTF=alloc,readonly ${btf_data}
 	${OBJCOPY} --only-section=.BTF --strip-all ${btf_data}
Signature · 1 line
2.52.0
#1 lore raw
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Quoted 11 lines · On Mon, 29 Dec 2025 12:28:23 -0800 you wrote:

gen-btf.sh emits a .btf.o file with BTF sections to be linked into vmlinux in link-vmlinux.sh

This .btf.o file is created by compiling an emptystring with ${CC}, and then adding BTF sections into it with ${OBJCOPY}.

To ensure the .btf.o is linkable when cross-compiling with LLVM, we have to also pass ${KBUILD_FLAGS}, which in particular control the target word size.

[...]

Here is the summary with links:
- [bpf-next] scripts/gen-btf.sh: Fix .btf.o generation when compiling for RISCV

    https://git.kernel.org/bpf/bpf-next/c/600605853f87

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html