From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C2298F4B for ; Tue, 31 Jan 2023 17:20:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 49748C433EF; Tue, 31 Jan 2023 17:20:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675185659; bh=+pvUZxvhRwxJP5MRWV/FG2QALpGhPM4yg4kJFt4ZFlI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=FPKZBNkr4YMaum4++SVy1d+KjqgdDu04hJDzmRHOeWM9Rw4g69HGsE+J50iv0S43P 052q+53XWlexnd48eQqCpsIJNW1uEY7PVJhPoNzXFw2DiD04IXHXB0faQNuLHaSuPS smV8LoJamcPlIQuTxPiKxxEKhyj0NdF9NuypU1FuTHfDnNzma/AfnksxfnhP5Y4LVV w9d2T0xHZWqXIz3nqK2rmYe4yx1tiSzdBBmXLj3vR6waNmcPhyc+MT3Vv3bVGkPzvn sQdaiCVDl566Z+33gbNAQX8emOTxTkm8eUac3GQTTfup+SH+Lit1/NHy5rX/WOiy0a sJYZdK5NKel9A== Date: Tue, 31 Jan 2023 10:20:56 -0700 From: Nathan Chancellor To: Ian Rogers Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Connor OBrien , Kumar Kartikeya Dwivedi , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: Re: [PATCH v4 2/2] tools/resolve_btfids: Alter how HOSTCC is forced Message-ID: References: <20230124064324.672022-1-irogers@google.com> <20230124064324.672022-2-irogers@google.com> Precedence: bulk X-Mailing-List: llvm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230124064324.672022-2-irogers@google.com> Hi Ian, On Mon, Jan 23, 2023 at 10:43:24PM -0800, Ian Rogers wrote: > 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 > --- > tools/bpf/resolve_btfids/Makefile | 17 +++++++---------- > 1 file changed, 7 insertions(+), 10 deletions(-) > > diff --git a/tools/bpf/resolve_btfids/Makefile b/tools/bpf/resolve_btfids/Makefile > index 1fe0082b2ecc..daed388aa5d7 100644 > --- 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_OUT): > > $(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 \ > -- > 2.39.0.246.g2a6d74b583-goog > I just bisected a linking failure when building resolve_btfids with clang to this change as commit 13e07691a16f ("tools/resolve_btfids: Alter how HOSTCC is forced") in the bpf-next tree. It appears to be related to whether or not CROSS_COMPILE is specified, which we have to do for certain architectures and configurations still. arm64 is not one of those but it helps demonstrate the issue. # Turn off CONFIG_DEBUG_INFO_REDUCED and turn on CONFIG_DEBUG_INFO_BTF $ make -skj"$(nproc)" ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- HOSTLDFLAGS=-fuse-ld=lld LLVM=1 defconfig menuconfig $ make -skj"$(nproc)" ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- HOSTLDFLAGS=-fuse-ld=lld LLVM=1 prepare ld.lld: error: $LINUX_SRC/tools/bpf/resolve_btfids//resolve_btfids-in.o is incompatible with elf64-x86-64 clang-17: error: linker command failed with exit code 1 (use -v to see invocation) ... Before your change, with V=1, I see: clang -Wp,-MD,$LINUX_SRC/tools/bpf/resolve_btfids/.main.o.d -Wp,-MT,$LINUX_SRC/tools/bpf/resolve_btfids/main.o -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -std=gnu11 -Wdeclaration-after-statement -g -I$LINUX_SRC/tools/include -I$LINUX_SRC/tools/include/uapi -I$LINUX_SRC/tools/bpf/resolve_btfids/libbpf/include -I$LINUX_SRC/tools/bpf/resolve_btfids/libsubcmd/include -D"BUILD_STR(s)=#s" -c -o $LINUX_SRC/tools/bpf/resolve_btfids/main.o main.c After, I see: clang -Wp,-MD,$LINUX_SRC/tools/bpf/resolve_btfids/.main.o.d -Wp,-MT,$LINUX_SRC/tools/bpf/resolve_btfids/main.o --target=aarch64-linux-gnu -g -I$LINUX_SRC/tools/include -I$LINUX_SRC/tools/include/uapi -I$LINUX_SRC/tools/bpf/resolve_btfids/libbpf/include -I$LINUX_SRC/tools/bpf/resolve_btfids/libsubcmd/include -D"BUILD_STR(s)=#s" -c -o $LINUX_SRC/tools/bpf/resolve_btfids/main.o main.c We seem to have taken on a '--target=aarch64-linux-gnu' (changing the target of resolve_btfids-in.o) and we dropped the warning flags. I think this comes from the clang block in tools/scripts/Makefile.include, which is included into the resolve_btfids Makefile via tools/lib/bpf/Makefile. I am not super familiar with the tools build system, otherwise I would try to provide a patch. I tried moving CROSS_COMPILE from a recursive to simple variable ('=' -> ':=') and moving it to HOST_OVERRIDES but those did not appear to resolve it for me. If there is any other information I can provide or patches I can test, please let me know. Cheers, Nathan