bpf: Fix build for disabled CONFIG_DEBUG_INFO_BTF option
Subsystems (3)
Jiri Olsa
reviewerPATCH 1/2 bpf: Fix build for disabled CONFIG_DEBUG_INFO_BTF option
Stephen reported following linker warnings on powerpc build:
ld: warning: orphan section .BTF_ids' from kernel/trace/bpf_trace.o' being placed in section `.BTF_ids'
ld: warning: orphan section .BTF_ids' from kernel/bpf/btf.o' being placed in section `.BTF_ids'
ld: warning: orphan section .BTF_ids' from kernel/bpf/stackmap.o' being placed in section `.BTF_ids'
ld: warning: orphan section .BTF_ids' from net/core/filter.o' being placed in section `.BTF_ids'
ld: warning: orphan section .BTF_ids' from kernel/trace/bpf_trace.o' being placed in section `.BTF_ids'
It's because we generated .BTF_ids section even when CONFIG_DEBUG_INFO_BTF is not enabled. Fixing this by generating empty btf_id arrays for this case.
--- include/linux/btf_ids.h | 9 +++++++++ 1 file changed, 9 insertions(+)
include/linux/btf_ids.h +9 -0
@@ -3,6 +3,8 @@#ifndef _LINUX_BTF_IDS_H#define _LINUX_BTF_IDS_H +#ifdef CONFIG_DEBUG_INFO_BTF +#include <linux/compiler.h> /* for __PASTE */ /*
@@ -83,5 +85,12 @@ asm( \".zero 4 \n" \ ".popsection; \n"); +#else + +#define BTF_ID_LIST (name) static u32 name[5]; +#define BTF_ID (prefix, name) +#define BTF_ID_UNUSED + +#endif /* CONFIG_DEBUG_INFO_BTF */ #endif
Signature · 1 line
2.25.4
Jiri Olsa
reviewerPATCH 2/2 bpf: Fix cross build for CONFIG_DEBUG_INFO_BTF option
Stephen and 0-DAY CI Kernel Test Service reported broken cross build for arm (arm-linux-gnueabi-gcc (GCC) 9.3.0), with following output:
/tmp/ccMS5uth.s: Assembler messages:
/tmp/ccMS5uth.s:69: Error: unrecognized symbol type "" /tmp/ccMS5uth.s:82: Error: unrecognized symbol type ""
Having '@object' for .type diretive is wrong because '@' is comment character for some architectures. Using STT_OBJECT instead that should work everywhere.
Also using HOST* variables to build resolve_btfids so it's properly build in crossbuilds (stolen from objtool's Makefile).
--- include/linux/btf_ids.h | 2 +- tools/bpf/resolve_btfids/Makefile | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-)
include/linux/btf_ids.h +1 -1
@@ -23,7 +23,7 @@ asm( \ ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ ".local " #symbol " ; \n" \ -".type " #symbol ", @object; \n" \ +".type " #symbol ", STT_OBJECT; \n" \ ".size " #symbol ", 4; \n" \ #symbol ": \n" \ ".zero 4 \n" \
tools/bpf/resolve_btfids/Makefile +14 -0
@@ -16,6 +16,20 @@ else MAKEFLAGS=--no-print-directory endif +# always use the host compiler +ifneq ($(LLVM),) +HOSTAR ?= llvm-ar +HOSTCC ?= clang +HOSTLD ?= ld.lld +else +HOSTAR ?= ar +HOSTCC ?= gcc +HOSTLD ?= ld +endif +AR = $(HOSTAR) +CC = $(HOSTCC) +LD = $(HOSTLD) + OUTPUT ?= $(srctree)/tools/bpf/resolve_btfids/ LIBBPF_SRC := $(srctree)/tools/lib/bpf/
Signature · 1 line
2.25.4
Alexei Starovoitov
AppliedQuoted 9 lines · Jiri Olsa
Stephen reported following linker warnings on powerpc build:
ld: warning: orphan section
.BTF_ids' fromkernel/trace/bpf_trace.o' being placed in section `.BTF_ids'
ld: warning: orphan section.BTF_ids' fromkernel/bpf/btf.o' being placed in section `.BTF_ids'
ld: warning: orphan section.BTF_ids' fromkernel/bpf/stackmap.o' being placed in section `.BTF_ids'
ld: warning: orphan section.BTF_ids' fromnet/core/filter.o' being placed in section `.BTF_ids'
ld: warning: orphan section.BTF_ids' fromkernel/trace/bpf_trace.o' being placed in section `.BTF_ids'
Quoted 7 lines
It's because we generated .BTF_ids section even when
CONFIG_DEBUG_INFO_BTFis not enabled. Fixing this by generating emptybtf_idarrays for this case.Reported-by Stephen Rothwell <[email protected]>Tested-by Geert Uytterhoeven <[email protected]>Signed-off-by Jiri Olsa <[email protected]>
Applied both to bpf-next. Thanks for the quick fix.