Use pahole --header_guards_db flag to enable encoding of header guard information in kernel BTF. The actual correspondence between header file and guard string is computed by the scripts/infer_header_guards.pl. The encoded header guard information could be used to restore the original guards in the vmlinux.h, e.g.: include/uapi/linux/tcp.h: #ifndef _UAPI_LINUX_TCP_H #define _UAPI_LINUX_TCP_H ... union tcp_word_hdr { struct tcphdr hdr; __be32 words[5]; }; ... #endif /* _UAPI_LINUX_TCP_H */ vmlinux.h: ... #ifndef _UAPI_LINUX_TCP_H union tcp_word_hdr { struct tcphdr hdr; __be32 words[5]; }; #endif /* _UAPI_LINUX_TCP_H */ ... Signed-off-by: Eduard Zingerman <eddyz87@xxxxxxxxx> --- scripts/link-vmlinux.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 918470d768e9..f57f621eda1f 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -110,6 +110,7 @@ vmlinux_link() gen_btf() { local pahole_ver + local extra_flags if ! [ -x "$(command -v ${PAHOLE})" ]; then echo >&2 "BTF: ${1}: pahole (${PAHOLE}) is not available" @@ -122,10 +123,20 @@ gen_btf() return 1 fi + if [ "${pahole_ver}" -ge "124" ]; then + scripts/infer_header_guards.pl \ + include/uapi \ + include/generated/uapi \ + arch/${SRCARCH}/include/uapi \ + arch/${SRCARCH}/include/generated/uapi \ + > .btf.uapi_header_guards || return 1; + extra_flags="--header_guards_db .btf.uapi_header_guards" + fi + vmlinux_link ${1} info "BTF" ${2} - LLVM_OBJCOPY="${OBJCOPY}" ${PAHOLE} -J ${PAHOLE_FLAGS} ${1} + LLVM_OBJCOPY="${OBJCOPY}" ${PAHOLE} -J ${PAHOLE_FLAGS} ${extra_flags} ${1} # Create ${2} which contains just .BTF section but no symbols. Add # SHF_ALLOC because .BTF will be part of the vmlinux image. --strip-all -- 2.34.1