Skip to content

Commit 74f9928

Browse files
alan-maguireKernel Patches Daemon
authored andcommitted
kbuild: Add support for extra BTF
information .BTF.extra sections wil be used to add additional BTF information for inlines etc. .BTF.extra sections are split BTF relative to kernel/module BTF and are enabled via CONFIG_DEBUG_INFO_BTF_EXTRA. It is bool for now but will become tristate in a later patch when support for a separate module is added (vmlinux .BTF.extra is 9Mb so 'y' is not a good option for most cases since it will bloat vmlinux size). Signed-off-by: Alan Maguire <[email protected]>
1 parent 54a7c19 commit 74f9928

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

include/asm-generic/vmlinux.lds.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,10 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG)
675675
. = ALIGN(PAGE_SIZE); \
676676
.BTF_ids : AT(ADDR(.BTF_ids) - LOAD_OFFSET) { \
677677
*(.BTF_ids) \
678+
} \
679+
. = ALIGN(PAGE_SIZE); \
680+
.BTF.extra : AT(ADDR(.BTF.extra) - LOAD_OFFSET) { \
681+
BOUNDED_SECTION_BY(.BTF.extra, _BTF_extra) \
678682
}
679683
#else
680684
#define BTF

lib/Kconfig.debug

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,13 @@ config PAHOLE_HAS_LANG_EXCLUDE
409409
otherwise it would emit malformed kernel and module binaries when
410410
using DEBUG_INFO_BTF_MODULES.
411411

412+
config PAHOLE_HAS_INLINE
413+
def_bool PAHOLE_VERSION >= 130
414+
help
415+
Support for the "inline" feature in BTF is available; it supports
416+
encoding information about inline sites in BTF; their location
417+
and information to help retrieve their associated parameters.
418+
412419
config DEBUG_INFO_BTF_MODULES
413420
bool "Generate BTF type information for kernel modules"
414421
default y
@@ -426,6 +433,17 @@ config MODULE_ALLOW_BTF_MISMATCH
426433
this option will still load module BTF where possible but ignore
427434
it when a mismatch is found.
428435

436+
config DEBUG_INFO_BTF_EXTRA
437+
bool "Provide extra information about inline sites in BTF"
438+
default n
439+
depends on DEBUG_INFO_BTF && PAHOLE_HAS_INLINE
440+
help
441+
Generate information about inline sites in .BTF.extra sections
442+
which consist of split BTF relative to kernel/module BTF;
443+
this BTF is made available to the user in /sys/kernel/btf.extra
444+
where the filename corresponds to the kernel (vmlinux) or the
445+
module the inline info refers to.
446+
429447
config GDB_SCRIPTS
430448
bool "Provide GDB scripts for kernel debugging"
431449
help

scripts/Makefile.btf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
pahole-ver := $(CONFIG_PAHOLE_VERSION)
44
pahole-flags-y :=
5+
btf-extra :=
56

67
JOBS := $(patsubst -j%,%,$(filter -j%,$(MAKEFLAGS)))
78

@@ -25,8 +26,14 @@ pahole-flags-$(call test-ge, $(pahole-ver), 126) = -j$(JOBS) --btf_features=enc
2526

2627
pahole-flags-$(call test-ge, $(pahole-ver), 130) += --btf_features=attributes
2728

29+
btf-extra =
2830
ifneq ($(KBUILD_EXTMOD),)
2931
module-pahole-flags-$(call test-ge, $(pahole-ver), 128) += --btf_features=distilled_base
32+
else
33+
ifneq ($(CONFIG_DEBUG_INFO_BTF_EXTRA),)
34+
pahole-flags-$(call test-ge, $(pahole-ver), 130) += --btf_features=inline.extra
35+
btf-extra := y
36+
endif
3037
endif
3138

3239
endif
@@ -35,3 +42,4 @@ pahole-flags-$(CONFIG_PAHOLE_HAS_LANG_EXCLUDE) += --lang_exclude=rust
3542

3643
export PAHOLE_FLAGS := $(pahole-flags-y)
3744
export MODULE_PAHOLE_FLAGS := $(module-pahole-flags-y)
45+
export BTF_EXTRA := $(btf-extra)

scripts/link-vmlinux.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,22 +105,29 @@ vmlinux_link()
105105
${kallsymso} ${btf_vmlinux_bin_o} ${arch_vmlinux_o} ${ldlibs}
106106
}
107107

108-
# generate .BTF typeinfo from DWARF debuginfo
108+
# generate .BTF typeinfo from DWARF debuginfo. Optionally add .BTF.extra
109+
# section if BTF_EXTRA is set.
109110
# ${1} - vmlinux image
110111
gen_btf()
111112
{
112113
local btf_data=${1}.btf.o
114+
local btf_extra_flags=
113115

114116
info BTF "${btf_data}"
115117
LLVM_OBJCOPY="${OBJCOPY}" ${PAHOLE} -J ${PAHOLE_FLAGS} ${1}
116118

117-
# Create ${btf_data} which contains just .BTF section but no symbols. Add
119+
120+
if [ -n "${BTF_EXTRA}" ]; then
121+
btf_extra_flags="--only-section=.BTF.extra --set-section-flags .BTF.extra=alloc,readonly"
122+
fi
123+
124+
# Create ${btf_data} which contains just .BTF sections but no symbols. Add
118125
# SHF_ALLOC because .BTF will be part of the vmlinux image. --strip-all
119126
# deletes all symbols including __start_BTF and __stop_BTF, which will
120127
# be redefined in the linker script. Add 2>/dev/null to suppress GNU
121128
# objcopy warnings: "empty loadable segment detected at ..."
122129
${OBJCOPY} --only-section=.BTF --set-section-flags .BTF=alloc,readonly \
123-
--strip-all ${1} "${btf_data}" 2>/dev/null
130+
${btf_extra_flags} --strip-all ${1} "${btf_data}" 2>/dev/null
124131
# Change e_type to ET_REL so that it can be used to link final vmlinux.
125132
# GNU ld 2.35+ and lld do not allow an ET_EXEC input.
126133
if is_enabled CONFIG_CPU_BIG_ENDIAN; then

0 commit comments

Comments
 (0)