kernel: backport build fix for tools/resolve_btfids
[openwrt/staging/noltari.git] / target / linux / generic / backport-5.15 / 200-v5.18-tools-resolve_btfids-Build-with-host-flags.patch
1 From cdbc4e3399ed8cdcf234a85f7a2482b622379e82 Mon Sep 17 00:00:00 2001
2 From: Connor O'Brien <connoro@google.com>
3 Date: Wed, 12 Jan 2022 00:25:03 +0000
4 Subject: [PATCH] tools/resolve_btfids: Build with host flags
5
6 resolve_btfids is built using $(HOSTCC) and $(HOSTLD) but does not
7 pick up the corresponding flags. As a result, host-specific settings
8 (such as a sysroot specified via HOSTCFLAGS=--sysroot=..., or a linker
9 specified via HOSTLDFLAGS=-fuse-ld=...) will not be respected.
10
11 Fix this by setting CFLAGS to KBUILD_HOSTCFLAGS and LDFLAGS to
12 KBUILD_HOSTLDFLAGS.
13
14 Also pass the cflags through to libbpf via EXTRA_CFLAGS to ensure that
15 the host libbpf is built with flags consistent with resolve_btfids.
16
17 Signed-off-by: Connor O'Brien <connoro@google.com>
18 Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
19 Acked-by: Song Liu <songliubraving@fb.com>
20 Link: https://lore.kernel.org/bpf/20220112002503.115968-1-connoro@google.com
21 (cherry picked from commit 0e3a1c902ffb56e9fe4416f0cd382c97b09ecbf6)
22 Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
23 ---
24 tools/bpf/resolve_btfids/Makefile | 6 ++++--
25 1 file changed, 4 insertions(+), 2 deletions(-)
26
27 diff --git a/tools/bpf/resolve_btfids/Makefile b/tools/bpf/resolve_btfids/Makefile
28 index af9f9d3534c9..e727058bfe15 100644
29 --- a/tools/bpf/resolve_btfids/Makefile
30 +++ b/tools/bpf/resolve_btfids/Makefile
31 @@ -23,6 +23,8 @@ CC = $(HOSTCC)
32 LD = $(HOSTLD)
33 ARCH = $(HOSTARCH)
34 RM ?= rm
35 +CFLAGS := $(KBUILD_HOSTCFLAGS)
36 +LDFLAGS := $(KBUILD_HOSTLDFLAGS)
37
38 OUTPUT ?= $(srctree)/tools/bpf/resolve_btfids/
39
40 @@ -45,9 +47,9 @@ $(SUBCMDOBJ): fixdep FORCE | $(OUTPUT)/libsubcmd
41 $(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(abspath $(dir $@))/ $(abspath $@)
42
43 $(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(OUTPUT)/libbpf
44 - $(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC) OUTPUT=$(abspath $(dir $@))/ $(abspath $@)
45 + $(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC) OUTPUT=$(abspath $(dir $@))/ EXTRA_CFLAGS="$(CFLAGS)" $(abspath $@)
46
47 -CFLAGS := -g \
48 +CFLAGS += -g \
49 -I$(srctree)/tools/include \
50 -I$(srctree)/tools/include/uapi \
51 -I$(LIBBPF_SRC) \
52 --
53 2.35.1
54