input-i8042-add-quirk-for-tuxedo-gemini-17-gen1-clevo-pd70pn.patch
revert-pci-tegra194-enable-support-for-256-byte-payload.patch
revert-net-macsec-preserve-ingress-frame-ordering.patch
+tools-lib-subcmd-add-install-target.patch
+tools-lib-subcmd-make-install_headers-clearer.patch
+tools-lib-subcmd-add-dependency-test-to-install_headers.patch
+tools-resolve_btfids-use-pkg-config-to-locate-libelf.patch
+tools-resolve_btfids-install-subcmd-headers.patch
+tools-resolve_btfids-alter-how-hostcc-is-forced.patch
+tools-resolve_btfids-compile-resolve_btfids-as-host-program.patch
+tools-resolve_btfids-tidy-host_overrides.patch
+tools-resolve_btfids-pass-hostcflags-as-extra_cflags-to-prepare-targets.patch
+tools-resolve_btfids-fix-setting-hostcflags.patch
--- /dev/null
+From 5d890591db6bed8ca69bd4bfe0cdaca372973033 Mon Sep 17 00:00:00 2001
+From: Ian Rogers <irogers@google.com>
+Date: Thu, 1 Dec 2022 20:57:41 -0800
+Subject: tools lib subcmd: Add dependency test to install_headers
+
+From: Ian Rogers <irogers@google.com>
+
+commit 5d890591db6bed8ca69bd4bfe0cdaca372973033 upstream.
+
+Compute the headers to be installed from their source headers and make
+each have its own build target to install it. Using dependencies
+avoids headers being reinstalled and getting a new timestamp which
+then causes files that depend on the header to be rebuilt.
+
+Signed-off-by: Ian Rogers <irogers@google.com>
+Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
+Cc: Ingo Molnar <mingo@redhat.com>
+Cc: Jiri Olsa <jolsa@kernel.org>
+Cc: Josh Poimboeuf <jpoimboe@kernel.org>
+Cc: Mark Rutland <mark.rutland@arm.com>
+Cc: Masahiro Yamada <masahiroy@kernel.org>
+Cc: Namhyung Kim <namhyung@kernel.org>
+Cc: Nathan Chancellor <nathan@kernel.org>
+Cc: Nick Desaulniers <ndesaulniers@google.com>
+Cc: Nicolas Schier <nicolas@fjasle.eu>
+Cc: Peter Zijlstra <peterz@infradead.org>
+Cc: Stephane Eranian <eranian@google.com>
+Cc: Tom Rix <trix@redhat.com>
+Cc: bpf@vger.kernel.org
+Cc: llvm@lists.linux.dev
+Link: https://lore.kernel.org/r/20221202045743.2639466-4-irogers@google.com
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Cc: Nathan Chancellor <nathan@kernel.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ tools/lib/subcmd/Makefile | 23 +++++++++++++----------
+ 1 file changed, 13 insertions(+), 10 deletions(-)
+
+--- a/tools/lib/subcmd/Makefile
++++ b/tools/lib/subcmd/Makefile
+@@ -89,10 +89,10 @@ define do_install_mkdir
+ endef
+
+ define do_install
+- if [ ! -d '$(DESTDIR_SQ)$2' ]; then \
+- $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
++ if [ ! -d '$2' ]; then \
++ $(INSTALL) -d -m 755 '$2'; \
+ fi; \
+- $(INSTALL) $1 $(if $3,-m $3,) '$(DESTDIR_SQ)$2'
++ $(INSTALL) $1 $(if $3,-m $3,) '$2'
+ endef
+
+ install_lib: $(LIBFILE)
+@@ -100,13 +100,16 @@ install_lib: $(LIBFILE)
+ $(call do_install_mkdir,$(libdir_SQ)); \
+ cp -fpR $(LIBFILE) $(DESTDIR)$(libdir_SQ)
+
+-install_headers:
+- $(call QUIET_INSTALL, libsubcmd_headers) \
+- $(call do_install,exec-cmd.h,$(prefix)/include/subcmd,644); \
+- $(call do_install,help.h,$(prefix)/include/subcmd,644); \
+- $(call do_install,pager.h,$(prefix)/include/subcmd,644); \
+- $(call do_install,parse-options.h,$(prefix)/include/subcmd,644); \
+- $(call do_install,run-command.h,$(prefix)/include/subcmd,644);
++HDRS := exec-cmd.h help.h pager.h parse-options.h run-command.h
++INSTALL_HDRS_PFX := $(DESTDIR)$(prefix)/include/subcmd
++INSTALL_HDRS := $(addprefix $(INSTALL_HDRS_PFX)/, $(HDRS))
++
++$(INSTALL_HDRS): $(INSTALL_HDRS_PFX)/%.h: %.h
++ $(call QUIET_INSTALL, $@) \
++ $(call do_install,$<,$(INSTALL_HDRS_PFX)/,644)
++
++install_headers: $(INSTALL_HDRS)
++ $(call QUIET_INSTALL, libsubcmd_headers)
+
+ install: install_lib install_headers
+
--- /dev/null
+From 630ae80ea1dd253609cb50cff87f3248f901aca3 Mon Sep 17 00:00:00 2001
+From: Ian Rogers <irogers@google.com>
+Date: Wed, 9 Nov 2022 10:49:02 -0800
+Subject: tools lib subcmd: Add install target
+
+From: Ian Rogers <irogers@google.com>
+
+commit 630ae80ea1dd253609cb50cff87f3248f901aca3 upstream.
+
+This allows libsubcmd to be installed as a dependency.
+
+Signed-off-by: Ian Rogers <irogers@google.com>
+Acked-by: Namhyung Kim <namhyung@kernel.org>
+Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
+Cc: Andrii Nakryiko <andrii.nakryiko@gmail.com>
+Cc: Jiri Olsa <jolsa@kernel.org>
+Cc: Mark Rutland <mark.rutland@arm.com>
+Cc: Masahiro Yamada <masahiroy@kernel.org>
+Cc: Nick Desaulniers <ndesaulniers@google.com>
+Cc: Nicolas Schier <nicolas@fjasle.eu>
+Cc: Peter Zijlstra <peterz@infradead.org>
+Cc: Stephane Eranian <eranian@google.com>
+Cc: bpf@vger.kernel.org
+Link: http://lore.kernel.org/lkml/20221109184914.1357295-3-irogers@google.com
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Cc: Nathan Chancellor <nathan@kernel.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ tools/lib/subcmd/Makefile | 49 ++++++++++++++++++++++++++++++++++++++++++++++
+ 1 file changed, 49 insertions(+)
+
+--- a/tools/lib/subcmd/Makefile
++++ b/tools/lib/subcmd/Makefile
+@@ -17,6 +17,15 @@ RM = rm -f
+
+ MAKEFLAGS += --no-print-directory
+
++INSTALL = install
++
++# Use DESTDIR for installing into a different root directory.
++# This is useful for building a package. The program will be
++# installed in this directory as if it was the root directory.
++# Then the build tool can move it later.
++DESTDIR ?=
++DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
++
+ LIBFILE = $(OUTPUT)libsubcmd.a
+
+ CFLAGS := -ggdb3 -Wall -Wextra -std=gnu99 -fPIC
+@@ -48,6 +57,18 @@ CFLAGS += $(EXTRA_WARNINGS) $(EXTRA_CFLA
+
+ SUBCMD_IN := $(OUTPUT)libsubcmd-in.o
+
++ifeq ($(LP64), 1)
++ libdir_relative = lib64
++else
++ libdir_relative = lib
++endif
++
++prefix ?=
++libdir = $(prefix)/$(libdir_relative)
++
++# Shell quotes
++libdir_SQ = $(subst ','\'',$(libdir))
++
+ all:
+
+ export srctree OUTPUT CC LD CFLAGS V
+@@ -61,6 +82,34 @@ $(SUBCMD_IN): FORCE
+ $(LIBFILE): $(SUBCMD_IN)
+ $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(SUBCMD_IN)
+
++define do_install_mkdir
++ if [ ! -d '$(DESTDIR_SQ)$1' ]; then \
++ $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
++ fi
++endef
++
++define do_install
++ if [ ! -d '$(DESTDIR_SQ)$2' ]; then \
++ $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
++ fi; \
++ $(INSTALL) $1 $(if $3,-m $3,) '$(DESTDIR_SQ)$2'
++endef
++
++install_lib: $(LIBFILE)
++ $(call QUIET_INSTALL, $(LIBFILE)) \
++ $(call do_install_mkdir,$(libdir_SQ)); \
++ cp -fpR $(LIBFILE) $(DESTDIR)$(libdir_SQ)
++
++install_headers:
++ $(call QUIET_INSTALL, headers) \
++ $(call do_install,exec-cmd.h,$(prefix)/include/subcmd,644); \
++ $(call do_install,help.h,$(prefix)/include/subcmd,644); \
++ $(call do_install,pager.h,$(prefix)/include/subcmd,644); \
++ $(call do_install,parse-options.h,$(prefix)/include/subcmd,644); \
++ $(call do_install,run-command.h,$(prefix)/include/subcmd,644);
++
++install: install_lib install_headers
++
+ clean:
+ $(call QUIET_CLEAN, libsubcmd) $(RM) $(LIBFILE); \
+ find $(or $(OUTPUT),.) -name \*.o -or -name \*.o.cmd -or -name \*.o.d | xargs $(RM)
--- /dev/null
+From 77dce6890a2a715b186bdc149c843571a5bb47df Mon Sep 17 00:00:00 2001
+From: Ian Rogers <irogers@google.com>
+Date: Wed, 16 Nov 2022 16:43:55 -0800
+Subject: tools lib subcmd: Make install_headers clearer
+
+From: Ian Rogers <irogers@google.com>
+
+commit 77dce6890a2a715b186bdc149c843571a5bb47df upstream.
+
+Add libsubcmd to the name so that this install_headers build appears
+different to similar targets in different libraries.
+
+Signed-off-by: Ian Rogers <irogers@google.com>
+Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
+Cc: Alexei Starovoitov <ast@kernel.org>
+Cc: Andrii Nakryiko <andrii@kernel.org>
+Cc: Daniel Borkmann <daniel@iogearbox.net>
+Cc: Hao Luo <haoluo@google.com>
+Cc: Ingo Molnar <mingo@redhat.com>
+Cc: Jiri Olsa <jolsa@kernel.org>
+Cc: John Fastabend <john.fastabend@gmail.com>
+Cc: KP Singh <kpsingh@kernel.org>
+Cc: Mark Rutland <mark.rutland@arm.com>
+Cc: Martin KaFai Lau <martin.lau@linux.dev>
+Cc: Masahiro Yamada <masahiroy@kernel.org>
+Cc: Namhyung Kim <namhyung@kernel.org>
+Cc: Nicolas Schier <nicolas@fjasle.eu>
+Cc: Peter Zijlstra <peterz@infradead.org>
+Cc: Song Liu <song@kernel.org>
+Cc: Stanislav Fomichev <sdf@google.com>
+Cc: Stephane Eranian <eranian@google.com>
+Cc: Yonghong Song <yhs@fb.com>
+Cc: bpf@vger.kernel.org
+Link: https://lore.kernel.org/r/20221117004356.279422-6-irogers@google.com
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Cc: Nathan Chancellor <nathan@kernel.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ tools/lib/subcmd/Makefile | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/tools/lib/subcmd/Makefile
++++ b/tools/lib/subcmd/Makefile
+@@ -101,7 +101,7 @@ install_lib: $(LIBFILE)
+ cp -fpR $(LIBFILE) $(DESTDIR)$(libdir_SQ)
+
+ install_headers:
+- $(call QUIET_INSTALL, headers) \
++ $(call QUIET_INSTALL, libsubcmd_headers) \
+ $(call do_install,exec-cmd.h,$(prefix)/include/subcmd,644); \
+ $(call do_install,help.h,$(prefix)/include/subcmd,644); \
+ $(call do_install,pager.h,$(prefix)/include/subcmd,644); \
--- /dev/null
+From 13e07691a16ff31b209fbfce25c01ff296b05e45 Mon Sep 17 00:00:00 2001
+From: Ian Rogers <irogers@google.com>
+Date: Mon, 23 Jan 2023 22:43:24 -0800
+Subject: tools/resolve_btfids: Alter how HOSTCC is forced
+
+From: Ian Rogers <irogers@google.com>
+
+commit 13e07691a16ff31b209fbfce25c01ff296b05e45 upstream.
+
+HOSTCC is always wanted when building. Setting CC to HOSTCC happens
+after tools/scripts/Makefile.include is included, meaning flags are
+set assuming say CC is gcc, but then it can be later set to HOSTCC
+which may be clang. tools/scripts/Makefile.include is needed for host
+set up and common macros in objtool's Makefile. Rather than override
+CC to HOSTCC, just pass CC as HOSTCC to Makefile.build, the libsubcmd
+builds and the linkage step. This means the Makefiles don't see things
+like CC changing and tool flag determination, and similar, work
+properly.
+
+Also, clear the passed subdir as otherwise an outer build may break by
+inadvertently passing an inappropriate value.
+
+Signed-off-by: Ian Rogers <irogers@google.com>
+Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
+Acked-by: Jiri Olsa <jolsa@kernel.org>
+Link: https://lore.kernel.org/bpf/20230124064324.672022-2-irogers@google.com
+Cc: Nathan Chancellor <nathan@kernel.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ tools/bpf/resolve_btfids/Makefile | 17 +++++++----------
+ 1 file changed, 7 insertions(+), 10 deletions(-)
+
+--- a/tools/bpf/resolve_btfids/Makefile
++++ b/tools/bpf/resolve_btfids/Makefile
+@@ -18,14 +18,11 @@ else
+ endif
+
+ # always use the host compiler
+-AR = $(HOSTAR)
+-CC = $(HOSTCC)
+-LD = $(HOSTLD)
+-ARCH = $(HOSTARCH)
++HOST_OVERRIDES := AR="$(HOSTAR)" CC="$(HOSTCC)" LD="$(HOSTLD)" ARCH="$(HOSTARCH)" \
++ EXTRA_CFLAGS="$(HOSTCFLAGS) $(KBUILD_HOSTCFLAGS)"
++
+ RM ?= rm
+ CROSS_COMPILE =
+-CFLAGS := $(KBUILD_HOSTCFLAGS)
+-LDFLAGS := $(KBUILD_HOSTLDFLAGS)
+
+ OUTPUT ?= $(srctree)/tools/bpf/resolve_btfids/
+
+@@ -56,12 +53,12 @@ $(OUTPUT) $(OUTPUT)/libsubcmd $(LIBBPF_O
+
+ $(SUBCMDOBJ): fixdep FORCE | $(OUTPUT)/libsubcmd
+ $(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(SUBCMD_OUT) \
+- DESTDIR=$(SUBCMD_DESTDIR) prefix= \
++ DESTDIR=$(SUBCMD_DESTDIR) $(HOST_OVERRIDES) prefix= subdir= \
+ $(abspath $@) install_headers
+
+ $(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(LIBBPF_OUT)
+ $(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC) OUTPUT=$(LIBBPF_OUT) \
+- DESTDIR=$(LIBBPF_DESTDIR) prefix= EXTRA_CFLAGS="$(CFLAGS)" \
++ DESTDIR=$(LIBBPF_DESTDIR) $(HOST_OVERRIDES) prefix= subdir= \
+ $(abspath $@) install_headers
+
+ LIBELF_FLAGS := $(shell $(HOSTPKG_CONFIG) libelf --cflags 2>/dev/null)
+@@ -80,11 +77,11 @@ export srctree OUTPUT CFLAGS Q
+ include $(srctree)/tools/build/Makefile.include
+
+ $(BINARY_IN): fixdep FORCE prepare | $(OUTPUT)
+- $(Q)$(MAKE) $(build)=resolve_btfids
++ $(Q)$(MAKE) $(build)=resolve_btfids $(HOST_OVERRIDES)
+
+ $(BINARY): $(BPFOBJ) $(SUBCMDOBJ) $(BINARY_IN)
+ $(call msg,LINK,$@)
+- $(Q)$(CC) $(BINARY_IN) $(LDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS)
++ $(Q)$(HOSTCC) $(BINARY_IN) $(KBUILD_HOSTLDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS)
+
+ clean_objects := $(wildcard $(OUTPUT)/*.o \
+ $(OUTPUT)/.*.o.cmd \
--- /dev/null
+From 56a2df7615fa050cc67b89245b2a482849077939 Mon Sep 17 00:00:00 2001
+From: Jiri Olsa <jolsa@kernel.org>
+Date: Thu, 2 Feb 2023 12:28:39 +0100
+Subject: tools/resolve_btfids: Compile resolve_btfids as host program
+
+From: Jiri Olsa <jolsa@kernel.org>
+
+commit 56a2df7615fa050cc67b89245b2a482849077939 upstream.
+
+Making resolve_btfids to be compiled as host program so
+we can avoid cross compile issues as reported by Nathan.
+
+Also we no longer need HOST_OVERRIDES for BINARY target,
+just for 'prepare' targets.
+
+Fixes: 13e07691a16f ("tools/resolve_btfids: Alter how HOSTCC is forced")
+Reported-by: Nathan Chancellor <nathan@kernel.org>
+Signed-off-by: Jiri Olsa <jolsa@kernel.org>
+Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
+Tested-by: Nathan Chancellor <nathan@kernel.org>
+Acked-by: Ian Rogers <irogers@google.com>
+Link: https://lore.kernel.org/bpf/20230202112839.1131892-1-jolsa@kernel.org
+Cc: Nathan Chancellor <nathan@kernel.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ tools/bpf/resolve_btfids/Build | 4 +++-
+ tools/bpf/resolve_btfids/Makefile | 9 ++++++---
+ 2 files changed, 9 insertions(+), 4 deletions(-)
+
+--- a/tools/bpf/resolve_btfids/Build
++++ b/tools/bpf/resolve_btfids/Build
+@@ -1,3 +1,5 @@
++hostprogs := resolve_btfids
++
+ resolve_btfids-y += main.o
+ resolve_btfids-y += rbtree.o
+ resolve_btfids-y += zalloc.o
+@@ -7,4 +9,4 @@ resolve_btfids-y += str_error_r.o
+
+ $(OUTPUT)%.o: ../../lib/%.c FORCE
+ $(call rule_mkdir)
+- $(call if_changed_dep,cc_o_c)
++ $(call if_changed_dep,host_cc_o_c)
+--- a/tools/bpf/resolve_btfids/Makefile
++++ b/tools/bpf/resolve_btfids/Makefile
+@@ -22,6 +22,9 @@ HOST_OVERRIDES := AR="$(HOSTAR)" CC="$(H
+ EXTRA_CFLAGS="$(HOSTCFLAGS) $(KBUILD_HOSTCFLAGS)"
+
+ RM ?= rm
++HOSTCC ?= gcc
++HOSTLD ?= ld
++HOSTAR ?= ar
+ CROSS_COMPILE =
+
+ OUTPUT ?= $(srctree)/tools/bpf/resolve_btfids/
+@@ -64,7 +67,7 @@ $(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[c
+ LIBELF_FLAGS := $(shell $(HOSTPKG_CONFIG) libelf --cflags 2>/dev/null)
+ LIBELF_LIBS := $(shell $(HOSTPKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf)
+
+-CFLAGS += -g \
++HOSTCFLAGS += -g \
+ -I$(srctree)/tools/include \
+ -I$(srctree)/tools/include/uapi \
+ -I$(LIBBPF_INCLUDE) \
+@@ -73,11 +76,11 @@ CFLAGS += -g \
+
+ LIBS = $(LIBELF_LIBS) -lz
+
+-export srctree OUTPUT CFLAGS Q
++export srctree OUTPUT HOSTCFLAGS Q HOSTCC HOSTLD HOSTAR
+ include $(srctree)/tools/build/Makefile.include
+
+ $(BINARY_IN): fixdep FORCE prepare | $(OUTPUT)
+- $(Q)$(MAKE) $(build)=resolve_btfids $(HOST_OVERRIDES)
++ $(Q)$(MAKE) $(build)=resolve_btfids
+
+ $(BINARY): $(BPFOBJ) $(SUBCMDOBJ) $(BINARY_IN)
+ $(call msg,LINK,$@)
--- /dev/null
+From edd75c802855271c8610f58a2fc9e54aefc49ce5 Mon Sep 17 00:00:00 2001
+From: Viktor Malik <vmalik@redhat.com>
+Date: Tue, 30 May 2023 14:33:52 +0200
+Subject: tools/resolve_btfids: Fix setting HOSTCFLAGS
+
+From: Viktor Malik <vmalik@redhat.com>
+
+commit edd75c802855271c8610f58a2fc9e54aefc49ce5 upstream.
+
+Building BPF selftests with custom HOSTCFLAGS yields an error:
+
+ # make HOSTCFLAGS="-O2"
+ [...]
+ HOSTCC ./tools/testing/selftests/bpf/tools/build/resolve_btfids/main.o
+ main.c:73:10: fatal error: linux/rbtree.h: No such file or directory
+ 73 | #include <linux/rbtree.h>
+ | ^~~~~~~~~~~~~~~~
+
+The reason is that tools/bpf/resolve_btfids/Makefile passes header
+include paths by extending HOSTCFLAGS which is overridden by setting
+HOSTCFLAGS in the make command (because of Makefile rules [1]).
+
+This patch fixes the above problem by passing the include paths via
+`HOSTCFLAGS_resolve_btfids` which is used by tools/build/Build.include
+and can be combined with overridding HOSTCFLAGS.
+
+[1] https://www.gnu.org/software/make/manual/html_node/Overriding.html
+
+Fixes: 56a2df7615fa ("tools/resolve_btfids: Compile resolve_btfids as host program")
+Signed-off-by: Viktor Malik <vmalik@redhat.com>
+Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
+Acked-by: Jiri Olsa <jolsa@kernel.org>
+Link: https://lore.kernel.org/bpf/20230530123352.1308488-1-vmalik@redhat.com
+Cc: Nathan Chancellor <nathan@kernel.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ tools/bpf/resolve_btfids/Makefile | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+--- a/tools/bpf/resolve_btfids/Makefile
++++ b/tools/bpf/resolve_btfids/Makefile
+@@ -67,7 +67,7 @@ $(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[c
+ LIBELF_FLAGS := $(shell $(HOSTPKG_CONFIG) libelf --cflags 2>/dev/null)
+ LIBELF_LIBS := $(shell $(HOSTPKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf)
+
+-HOSTCFLAGS += -g \
++HOSTCFLAGS_resolve_btfids += -g \
+ -I$(srctree)/tools/include \
+ -I$(srctree)/tools/include/uapi \
+ -I$(LIBBPF_INCLUDE) \
+@@ -76,7 +76,7 @@ HOSTCFLAGS += -g \
+
+ LIBS = $(LIBELF_LIBS) -lz
+
+-export srctree OUTPUT HOSTCFLAGS Q HOSTCC HOSTLD HOSTAR
++export srctree OUTPUT HOSTCFLAGS_resolve_btfids Q HOSTCC HOSTLD HOSTAR
+ include $(srctree)/tools/build/Makefile.include
+
+ $(BINARY_IN): fixdep FORCE prepare | $(OUTPUT)
--- /dev/null
+From af03299d8536d62b49c7f3cb929349eb2d66bcd5 Mon Sep 17 00:00:00 2001
+From: Ian Rogers <irogers@google.com>
+Date: Mon, 23 Jan 2023 22:43:23 -0800
+Subject: tools/resolve_btfids: Install subcmd headers
+
+From: Ian Rogers <irogers@google.com>
+
+commit af03299d8536d62b49c7f3cb929349eb2d66bcd5 upstream.
+
+Previously tools/lib/subcmd was added to the include path, switch to
+installing the headers and then including from that directory. This
+avoids dependencies on headers internal to tools/lib/subcmd. Add the
+missing subcmd directory to the affected #include.
+
+Signed-off-by: Ian Rogers <irogers@google.com>
+Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
+Acked-by: Jiri Olsa <jolsa@kernel.org>
+Link: https://lore.kernel.org/bpf/20230124064324.672022-1-irogers@google.com
+Cc: Nathan Chancellor <nathan@kernel.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ tools/bpf/resolve_btfids/Makefile | 19 ++++++++++++++-----
+ tools/bpf/resolve_btfids/main.c | 2 +-
+ 2 files changed, 15 insertions(+), 6 deletions(-)
+
+--- a/tools/bpf/resolve_btfids/Makefile
++++ b/tools/bpf/resolve_btfids/Makefile
+@@ -35,21 +35,29 @@ SUBCMD_SRC := $(srctree)/tools/lib/subcm
+ BPFOBJ := $(OUTPUT)/libbpf/libbpf.a
+ LIBBPF_OUT := $(abspath $(dir $(BPFOBJ)))/
+ SUBCMDOBJ := $(OUTPUT)/libsubcmd/libsubcmd.a
++SUBCMD_OUT := $(abspath $(dir $(SUBCMDOBJ)))/
+
+ LIBBPF_DESTDIR := $(LIBBPF_OUT)
+ LIBBPF_INCLUDE := $(LIBBPF_DESTDIR)include
+
++SUBCMD_DESTDIR := $(SUBCMD_OUT)
++SUBCMD_INCLUDE := $(SUBCMD_DESTDIR)include
++
+ BINARY := $(OUTPUT)/resolve_btfids
+ BINARY_IN := $(BINARY)-in.o
+
+ all: $(BINARY)
+
++prepare: $(BPFOBJ) $(SUBCMDOBJ)
++
+ $(OUTPUT) $(OUTPUT)/libsubcmd $(LIBBPF_OUT):
+ $(call msg,MKDIR,,$@)
+ $(Q)mkdir -p $(@)
+
+ $(SUBCMDOBJ): fixdep FORCE | $(OUTPUT)/libsubcmd
+- $(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(abspath $(dir $@))/ $(abspath $@)
++ $(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(SUBCMD_OUT) \
++ DESTDIR=$(SUBCMD_DESTDIR) prefix= \
++ $(abspath $@) install_headers
+
+ $(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(LIBBPF_OUT)
+ $(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC) OUTPUT=$(LIBBPF_OUT) \
+@@ -63,7 +71,7 @@ CFLAGS += -g \
+ -I$(srctree)/tools/include \
+ -I$(srctree)/tools/include/uapi \
+ -I$(LIBBPF_INCLUDE) \
+- -I$(SUBCMD_SRC) \
++ -I$(SUBCMD_INCLUDE) \
+ $(LIBELF_FLAGS)
+
+ LIBS = $(LIBELF_LIBS) -lz
+@@ -71,7 +79,7 @@ LIBS = $(LIBELF_LIBS) -lz
+ export srctree OUTPUT CFLAGS Q
+ include $(srctree)/tools/build/Makefile.include
+
+-$(BINARY_IN): $(BPFOBJ) fixdep FORCE | $(OUTPUT)
++$(BINARY_IN): fixdep FORCE prepare | $(OUTPUT)
+ $(Q)$(MAKE) $(build)=resolve_btfids
+
+ $(BINARY): $(BPFOBJ) $(SUBCMDOBJ) $(BINARY_IN)
+@@ -83,7 +91,8 @@ clean_objects := $(wildcard $(OUTPUT)/*.
+ $(OUTPUT)/.*.o.d \
+ $(LIBBPF_OUT) \
+ $(LIBBPF_DESTDIR) \
+- $(OUTPUT)/libsubcmd \
++ $(SUBCMD_OUT) \
++ $(SUBCMD_DESTDIR) \
+ $(OUTPUT)/resolve_btfids)
+
+ ifneq ($(clean_objects),)
+@@ -100,4 +109,4 @@ tags:
+
+ FORCE:
+
+-.PHONY: all FORCE clean tags
++.PHONY: all FORCE clean tags prepare
+--- a/tools/bpf/resolve_btfids/main.c
++++ b/tools/bpf/resolve_btfids/main.c
+@@ -75,7 +75,7 @@
+ #include <linux/err.h>
+ #include <bpf/btf.h>
+ #include <bpf/libbpf.h>
+-#include <parse-options.h>
++#include <subcmd/parse-options.h>
+
+ #define BTF_IDS_SECTION ".BTF_ids"
+ #define BTF_ID "__BTF_ID__"
--- /dev/null
+From 2531ba0e4ae67d6d0219400af27805fe52cd28e8 Mon Sep 17 00:00:00 2001
+From: Jiri Olsa <jolsa@kernel.org>
+Date: Thu, 9 Feb 2023 15:37:35 +0100
+Subject: tools/resolve_btfids: Pass HOSTCFLAGS as EXTRA_CFLAGS to prepare targets
+
+From: Jiri Olsa <jolsa@kernel.org>
+
+commit 2531ba0e4ae67d6d0219400af27805fe52cd28e8 upstream.
+
+Thorsten reported build issue with command line that defined extra
+HOSTCFLAGS that were not passed into 'prepare' targets, but were
+used to build resolve_btfids objects.
+
+This results in build fail when these objects are linked together:
+
+ /usr/bin/ld: /build.../tools/bpf/resolve_btfids//libbpf/libbpf.a(libbpf-in.o):
+ relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE \
+ object; recompile with -fPIE
+
+Fixing this by passing HOSTCFLAGS in EXTRA_CFLAGS as part of
+HOST_OVERRIDES variable for prepare targets.
+
+[1] https://lore.kernel.org/bpf/f7922132-6645-6316-5675-0ece4197bfff@leemhuis.info/
+
+Fixes: 56a2df7615fa ("tools/resolve_btfids: Compile resolve_btfids as host program")
+Reported-by: Thorsten Leemhuis <linux@leemhuis.info>
+Signed-off-by: Jiri Olsa <jolsa@kernel.org>
+Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
+Tested-by: Thorsten Leemhuis <linux@leemhuis.info>
+Acked-by: Ian Rogers <irogers@google.com>
+Link: https://lore.kernel.org/bpf/20230209143735.4112845-1-jolsa@kernel.org
+Cc: Nathan Chancellor <nathan@kernel.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ tools/bpf/resolve_btfids/Makefile | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/tools/bpf/resolve_btfids/Makefile
++++ b/tools/bpf/resolve_btfids/Makefile
+@@ -19,7 +19,7 @@ endif
+
+ # Overrides for the prepare step libraries.
+ HOST_OVERRIDES := AR="$(HOSTAR)" CC="$(HOSTCC)" LD="$(HOSTLD)" ARCH="$(HOSTARCH)" \
+- CROSS_COMPILE=""
++ CROSS_COMPILE="" EXTRA_CFLAGS="$(HOSTCFLAGS)"
+
+ RM ?= rm
+ HOSTCC ?= gcc
--- /dev/null
+From e0975ab92f2406fd3e12834f62dc57cb10404f85 Mon Sep 17 00:00:00 2001
+From: Ian Rogers <irogers@google.com>
+Date: Thu, 2 Feb 2023 14:42:53 -0800
+Subject: tools/resolve_btfids: Tidy HOST_OVERRIDES
+
+From: Ian Rogers <irogers@google.com>
+
+commit e0975ab92f2406fd3e12834f62dc57cb10404f85 upstream.
+
+Don't set EXTRA_CFLAGS to HOSTCFLAGS, ensure CROSS_COMPILE isn't
+passed through.
+
+Signed-off-by: Ian Rogers <irogers@google.com>
+Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
+Acked-by: Jiri Olsa <jolsa@kernel.org>
+Link: https://lore.kernel.org/bpf/20230202224253.40283-1-irogers@google.com
+Cc: Nathan Chancellor <nathan@kernel.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ tools/bpf/resolve_btfids/Makefile | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+--- a/tools/bpf/resolve_btfids/Makefile
++++ b/tools/bpf/resolve_btfids/Makefile
+@@ -17,9 +17,9 @@ else
+ MAKEFLAGS=--no-print-directory
+ endif
+
+-# always use the host compiler
++# Overrides for the prepare step libraries.
+ HOST_OVERRIDES := AR="$(HOSTAR)" CC="$(HOSTCC)" LD="$(HOSTLD)" ARCH="$(HOSTARCH)" \
+- EXTRA_CFLAGS="$(HOSTCFLAGS) $(KBUILD_HOSTCFLAGS)"
++ CROSS_COMPILE=""
+
+ RM ?= rm
+ HOSTCC ?= gcc
--- /dev/null
+From 0e43662e61f2569500ab83b8188c065603530785 Mon Sep 17 00:00:00 2001
+From: Shen Jiamin <shen_jiamin@comp.nus.edu.sg>
+Date: Thu, 15 Dec 2022 12:47:03 +0800
+Subject: tools/resolve_btfids: Use pkg-config to locate libelf
+
+From: Shen Jiamin <shen_jiamin@comp.nus.edu.sg>
+
+commit 0e43662e61f2569500ab83b8188c065603530785 upstream.
+
+When libelf was not installed in the standard location, it cannot be
+located by the current building config.
+
+Use pkg-config to help locate libelf in such cases.
+
+Signed-off-by: Shen Jiamin <shen_jiamin@comp.nus.edu.sg>
+Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
+Acked-by: Jiri Olsa <jolsa@kernel.org>
+Link: https://lore.kernel.org/bpf/20221215044703.400139-1-shen_jiamin@comp.nus.edu.sg
+Cc: Nathan Chancellor <nathan@kernel.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ tools/bpf/resolve_btfids/Makefile | 8 ++++++--
+ 1 file changed, 6 insertions(+), 2 deletions(-)
+
+--- a/tools/bpf/resolve_btfids/Makefile
++++ b/tools/bpf/resolve_btfids/Makefile
+@@ -56,13 +56,17 @@ $(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[c
+ DESTDIR=$(LIBBPF_DESTDIR) prefix= EXTRA_CFLAGS="$(CFLAGS)" \
+ $(abspath $@) install_headers
+
++LIBELF_FLAGS := $(shell $(HOSTPKG_CONFIG) libelf --cflags 2>/dev/null)
++LIBELF_LIBS := $(shell $(HOSTPKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf)
++
+ CFLAGS += -g \
+ -I$(srctree)/tools/include \
+ -I$(srctree)/tools/include/uapi \
+ -I$(LIBBPF_INCLUDE) \
+- -I$(SUBCMD_SRC)
++ -I$(SUBCMD_SRC) \
++ $(LIBELF_FLAGS)
+
+-LIBS = -lelf -lz
++LIBS = $(LIBELF_LIBS) -lz
+
+ export srctree OUTPUT CFLAGS Q
+ include $(srctree)/tools/build/Makefile.include