Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2816985pxb; Fri, 5 Nov 2021 05:18:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxSYD58ysQhS4ush3uN9+B1bC7d0Vojrb8fM+gOcceIikfsvRdl4Fa0uNHPAOPyyfT37sIF X-Received: by 2002:a17:906:7ccf:: with SMTP id h15mr25080844ejp.386.1636114696676; Fri, 05 Nov 2021 05:18:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1636114696; cv=none; d=google.com; s=arc-20160816; b=HNmhAbZSxWd1S404dDIvy0x6ClsYK5kRvFEanT0teUwaFegqeRezjji7Ha5cnRJQcH Mu3ZZhCAcP4rIAxI5jqTc3u+qZ34P8N0Rz5wbasF2yPkrP4t7Z9Y0HuGIWxObwZdE8Xl RXE8c6Il5mdnztln1hoLRndrqoWjZOpUUm4UW8LzO0CtkskhMuf4DAz7rIC5rNXp0lap hBTg6ap/vvfQIl6sbetGiZP27WjOhl7293hP8QjwCnhv9pAGI9HWWxs1djATNAvUkFdf XqnxdKfY9qu0i+QBlAIRghMipE8lw4HJLCaK7fQ/iv2jP/Byw5U8XMI7YMklmbWWKiBe Gwgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=wwtUXxcVfpHXdAQIzKI3IC8XES60cF0Xkuhv7sOC0C0=; b=cdVF7ify+1eHZtElzqUgt7POPIrtkjA4ynnFxCHCI2SY+9Eo5zO5Nwo+jc3v6r0LhV Ck6I5PkS5yajzhmyQp45Kstrc33PQZv8+VhBPuobM2+YqvRTuijE5LWgYoDcJ+s2Filq 9Xv0ZN4uECEX1+HMUBbHg3zzjoK6yw2TJt5wH8quJ7ig7yN9qPOv6mudlstI8aCfIOJk 0irVN2r30Vi4dnYi0UB/b5UYAdw71fQpWwbquAeHTRvcieccb0vndeCls/bFzj6Q56k0 6R/T/SIayhImwM9boYGw49HpEf0CvUojhe0sWLIVgmfnsrukmfo+CRm28LVrlY1BUsA+ 61tA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=f0dNXoJm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s4si12425270edd.232.2021.11.05.05.17.48; Fri, 05 Nov 2021 05:18:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=f0dNXoJm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231868AbhKEK6D (ORCPT + 99 others); Fri, 5 Nov 2021 06:58:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:35186 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231818AbhKEK6D (ORCPT ); Fri, 5 Nov 2021 06:58:03 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 631006112D; Fri, 5 Nov 2021 10:55:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1636109723; bh=aq1MUVKkLEHWOaFoQZe0Z4p8O2u7B2hr14jr+EYsSXI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=f0dNXoJm630YIjZ+9SbxrB5wfRtRy8nCdzwALJlTS4PdfrQeU7NSs+AX5n88tUbgW spSq2X275b24coeVu2HKeaMpJZLmFDanhKNk/yMt+V8FZxmUqVdNeooHJ8GVnSLLgv o/BIrFQvdGyw+Dk/tO/16rZ8xsNvFboNR5N7fMS/X1qxfiQ0EeG3Q+UiTsdK8+SWTe IwRvW+B6A+PXaFZfHmxyLb3bNw/2OLIoqXD9a3Br0N02OYEW+ye9kgzBpF8Be/Dd0H KkvMfCq4ehKg91ighNyEI8alNKJ6o6jByzIHHIHUj1x0YzSI7dQButeQa7unKVwUfu L3L+67p+rl0Wg== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id BF384410A1; Fri, 5 Nov 2021 07:55:20 -0300 (-03) Date: Fri, 5 Nov 2021 07:55:20 -0300 From: Arnaldo Carvalho de Melo To: Quentin Monnet Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , netdev@vger.kernel.org, bpf@vger.kernel.org, Song Liu , Jiri Olsa , Namhyung Kim , Linux Kernel Mailing List Subject: Re: [PATCH bpf] bpftool: Install libbpf headers for the bootstrap version, too Message-ID: References: <20211105015813.6171-1-quentin@isovalent.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211105015813.6171-1-quentin@isovalent.com> X-Url: http://acmel.wordpress.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Fri, Nov 05, 2021 at 01:58:13AM +0000, Quentin Monnet escreveu: > We recently changed bpftool's Makefile to make it install libbpf's > headers locally instead of pulling them from the source directory of the > library. Although bpftool needs two versions of libbpf, a "regular" one > and a "bootstrap" version, we would only install headers for the regular > libbpf build. Given that this build always occurs before the bootstrap > build when building bpftool, this is enough to ensure that the bootstrap > bpftool will have access to the headers exported through the regular > libbpf build. > > However, this did not account for the case when we only want the > bootstrap version of bpftool, through the "bootstrap" target. For > example, perf needs the bootstrap version only, to generate BPF > skeletons. In that case, when are the headers installed? For some time, > the issue has been masked, because we had a step (the installation of > headers internal to libbpf) which would depend on the regular build of > libbpf and hence trigger the export of the headers, just for the sake of > creating a directory. But this changed with commit 8b6c46241c77 > ("bpftool: Remove Makefile dep. on $(LIBBPF) for > $(LIBBPF_INTERNAL_HDRS)"), where we cleaned up that stage and removed > the dependency on the regular libbpf build. As a result, when we only > want the bootstrap bpftool version, the regular libbpf is no longer > built. The bootstrap libbpf version is built, but headers are not > exported, and the bootstrap bpftool build fails because of the missing > headers. > > To fix this, we also install the library headers for the bootstrap > version of libbpf, to use them for the bootstrap bpftool and for > generating the skeletons. Reported-by: Arnaldo Carvalho de Melo Testing now. - Arnaldo > Fixes: f012ade10b34 ("bpftool: Install libbpf headers instead of including the dir") > Signed-off-by: Quentin Monnet > --- > tools/bpf/bpftool/Makefile | 32 ++++++++++++++++++++++---------- > 1 file changed, 22 insertions(+), 10 deletions(-) > > diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile > index c0c30e56988f..7cfba11c3014 100644 > --- a/tools/bpf/bpftool/Makefile > +++ b/tools/bpf/bpftool/Makefile > @@ -22,24 +22,29 @@ else > _OUTPUT := $(CURDIR) > endif > BOOTSTRAP_OUTPUT := $(_OUTPUT)/bootstrap/ > + > LIBBPF_OUTPUT := $(_OUTPUT)/libbpf/ > LIBBPF_DESTDIR := $(LIBBPF_OUTPUT) > LIBBPF_INCLUDE := $(LIBBPF_DESTDIR)/include > LIBBPF_HDRS_DIR := $(LIBBPF_INCLUDE)/bpf > +LIBBPF := $(LIBBPF_OUTPUT)libbpf.a > > -LIBBPF = $(LIBBPF_OUTPUT)libbpf.a > -LIBBPF_BOOTSTRAP_OUTPUT = $(BOOTSTRAP_OUTPUT)libbpf/ > -LIBBPF_BOOTSTRAP = $(LIBBPF_BOOTSTRAP_OUTPUT)libbpf.a > +LIBBPF_BOOTSTRAP_OUTPUT := $(BOOTSTRAP_OUTPUT)libbpf/ > +LIBBPF_BOOTSTRAP_DESTDIR := $(LIBBPF_BOOTSTRAP_OUTPUT) > +LIBBPF_BOOTSTRAP_INCLUDE := $(LIBBPF_BOOTSTRAP_DESTDIR)/include > +LIBBPF_BOOTSTRAP_HDRS_DIR := $(LIBBPF_BOOTSTRAP_INCLUDE)/bpf > +LIBBPF_BOOTSTRAP := $(LIBBPF_BOOTSTRAP_OUTPUT)libbpf.a > > # We need to copy hashmap.h and nlattr.h which is not otherwise exported by > # libbpf, but still required by bpftool. > LIBBPF_INTERNAL_HDRS := $(addprefix $(LIBBPF_HDRS_DIR)/,hashmap.h nlattr.h) > +LIBBPF_BOOTSTRAP_INTERNAL_HDRS := $(addprefix $(LIBBPF_BOOTSTRAP_HDRS_DIR)/,hashmap.h) > > ifeq ($(BPFTOOL_VERSION),) > BPFTOOL_VERSION := $(shell make -rR --no-print-directory -sC ../../.. kernelversion) > endif > > -$(LIBBPF_OUTPUT) $(BOOTSTRAP_OUTPUT) $(LIBBPF_BOOTSTRAP_OUTPUT) $(LIBBPF_HDRS_DIR): > +$(LIBBPF_OUTPUT) $(BOOTSTRAP_OUTPUT) $(LIBBPF_BOOTSTRAP_OUTPUT) $(LIBBPF_HDRS_DIR) $(LIBBPF_BOOTSTRAP_HDRS_DIR): > $(QUIET_MKDIR)mkdir -p $@ > > $(LIBBPF): $(wildcard $(BPF_DIR)/*.[ch] $(BPF_DIR)/Makefile) | $(LIBBPF_OUTPUT) > @@ -52,7 +57,12 @@ $(LIBBPF_INTERNAL_HDRS): $(LIBBPF_HDRS_DIR)/%.h: $(BPF_DIR)/%.h | $(LIBBPF_HDRS_ > > $(LIBBPF_BOOTSTRAP): $(wildcard $(BPF_DIR)/*.[ch] $(BPF_DIR)/Makefile) | $(LIBBPF_BOOTSTRAP_OUTPUT) > $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIBBPF_BOOTSTRAP_OUTPUT) \ > - ARCH= CC=$(HOSTCC) LD=$(HOSTLD) $@ > + DESTDIR=$(LIBBPF_BOOTSTRAP_DESTDIR) prefix= \ > + ARCH= CC=$(HOSTCC) LD=$(HOSTLD) $@ install_headers > + > +$(LIBBPF_BOOTSTRAP_INTERNAL_HDRS): $(LIBBPF_BOOTSTRAP_HDRS_DIR)/%.h: $(BPF_DIR)/%.h | $(LIBBPF_BOOTSTRAP_HDRS_DIR) > + $(call QUIET_INSTALL, $@) > + $(Q)install -m 644 -t $(LIBBPF_BOOTSTRAP_HDRS_DIR) $< > > $(LIBBPF)-clean: FORCE | $(LIBBPF_OUTPUT) > $(call QUIET_CLEAN, libbpf) > @@ -172,11 +182,11 @@ else > $(Q)cp "$(VMLINUX_H)" $@ > endif > > -$(OUTPUT)%.bpf.o: skeleton/%.bpf.c $(OUTPUT)vmlinux.h $(LIBBPF) > +$(OUTPUT)%.bpf.o: skeleton/%.bpf.c $(OUTPUT)vmlinux.h $(LIBBPF_BOOTSTRAP) > $(QUIET_CLANG)$(CLANG) \ > -I$(if $(OUTPUT),$(OUTPUT),.) \ > -I$(srctree)/tools/include/uapi/ \ > - -I$(LIBBPF_INCLUDE) \ > + -I$(LIBBPF_BOOTSTRAP_INCLUDE) \ > -g -O2 -Wall -target bpf -c $< -o $@ && $(LLVM_STRIP) -g $@ > > $(OUTPUT)%.skel.h: $(OUTPUT)%.bpf.o $(BPFTOOL_BOOTSTRAP) > @@ -209,8 +219,10 @@ $(BPFTOOL_BOOTSTRAP): $(BOOTSTRAP_OBJS) $(LIBBPF_BOOTSTRAP) > $(OUTPUT)bpftool: $(OBJS) $(LIBBPF) > $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) > > -$(BOOTSTRAP_OUTPUT)%.o: %.c $(LIBBPF_INTERNAL_HDRS) | $(BOOTSTRAP_OUTPUT) > - $(QUIET_CC)$(HOSTCC) $(CFLAGS) -c -MMD -o $@ $< > +$(BOOTSTRAP_OUTPUT)%.o: %.c $(LIBBPF_BOOTSTRAP_INTERNAL_HDRS) | $(BOOTSTRAP_OUTPUT) > + $(QUIET_CC)$(HOSTCC) \ > + $(subst -I$(LIBBPF_INCLUDE),-I$(LIBBPF_BOOTSTRAP_INCLUDE),$(CFLAGS)) \ > + -c -MMD -o $@ $< > > $(OUTPUT)%.o: %.c > $(QUIET_CC)$(CC) $(CFLAGS) -c -MMD -o $@ $< > @@ -257,6 +269,6 @@ doc-uninstall: > FORCE: > > .SECONDARY: > -.PHONY: all FORCE clean install-bin install uninstall > +.PHONY: all FORCE bootstrap clean install-bin install uninstall > .PHONY: doc doc-clean doc-install doc-uninstall > .DEFAULT_GOAL := all > -- > 2.32.0 -- - Arnaldo