Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2423134pxb; Thu, 4 Nov 2021 20:51:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzioSxpif5qF+L/T6AkBGHduxl2Qpw9vyJqC15bQLgCu5P+Tpo68/41D8sYHKqepAOzJula X-Received: by 2002:a17:906:c9d0:: with SMTP id hk16mr67608250ejb.109.1636084278257; Thu, 04 Nov 2021 20:51:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1636084278; cv=none; d=google.com; s=arc-20160816; b=svr1wslIlF4EHwu1YpL+e12liEGiNPpyucRsxJwAqHPVmDW6sZwuCifQVjHmiC6Yla lyAItH5FcAM/Mfp4+yOTZAyoGqJ5lrmWXsU3zTubjIwPRHWw15eYzjZnZfknKyJZVmN+ tC5ZHkitPHrgbAEkzdq7LprgZ4INf68soOa0m5mwQYcC26gERH2XCe4U/HGvDTmRPJ9r U0DrA2EaB7K0fcocdFoDcBEQrgiphR9L6CVsQAUJICkP4qDcGLf1AHyIYJNOFSYB/C6L d4rgT6i39IOwSlbPURRq/RTAQtYIxSbjNBtyamFP2U1txw8/g+TgyHfo65I8nYP+x4/d dHxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=5Ov9WNcUS7VnCpB+C4+JiV+oY3dJctzolS44UUkDjME=; b=SzVL9oMRKcxC9H17J4qqtLyvu6lLvLzDR6j7NI27i9s32jo9yTYh26fTxssv+6GP2U KS49JBc+jz43C0tN1Um/eyoeR8MwOHhDIVwsHNWrAnMS/7AGAdYpB/9aUqeQ57l1f3Sp zfvVRWIOaFiAFyiew0W6RXGZqksdfeQ3lXV1k2d3RtTpJiQcSmSAjAJ9k3FCmvMEmwpf lDT+DdPzi+lAuw0MEtcMLNKQ2iYaTQAEUlh1Qsj7rMKjz5JOumUFS+PEljQfxgxy6r6q PShPh3DW8/I2Or3cbQe9x8r/AUSF7elliOGsvpOdlGPjbo4n4PsoBrAoGjOk+S0CNscR CKgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@isovalent-com.20210112.gappssmtp.com header.s=20210112 header.b=Jews42yl; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qa43si14270881ejc.76.2021.11.04.20.50.54; Thu, 04 Nov 2021 20:51:18 -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=@isovalent-com.20210112.gappssmtp.com header.s=20210112 header.b=Jews42yl; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231651AbhKECBC (ORCPT + 99 others); Thu, 4 Nov 2021 22:01:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231236AbhKECBB (ORCPT ); Thu, 4 Nov 2021 22:01:01 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95313C061714 for ; Thu, 4 Nov 2021 18:58:22 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id z11-20020a1c7e0b000000b0030db7b70b6bso8539711wmc.1 for ; Thu, 04 Nov 2021 18:58:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=isovalent-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=5Ov9WNcUS7VnCpB+C4+JiV+oY3dJctzolS44UUkDjME=; b=Jews42ylp46dhX/NQ9J0y43txE+GTZFxNE6nAT5vFWmZpWydV3ySCbDMNelaAEdpif 0ruQzRZnPM7RCt8yAbq5rKle/5bi053EaG88eQHznpuWhR5AOweZhc9598H91CLFLqK7 BkcQLHZW4rWCLy1B1p/+nBOOmZ0frKap4wGD6RjnecaRRzYMbHrt3LY4Pq3QLDP0qguF PVwZc6AZ7ZmrvaCPNdyJsRuVtRS+jzszB/z7qAifSiBa8gkEv9cW4aIu/rgSqYJcHFR4 1pQ8HfpGSAI3oBlFKjK4+Wu0nUJ68Nvlp4/nMJqzQedoYQ1yBPM+myIwalDeRxMYwlF/ JK0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=5Ov9WNcUS7VnCpB+C4+JiV+oY3dJctzolS44UUkDjME=; b=MdsKqRo9RLjy57n3ehO4jCUdtVFM4ofAUtrJFDwCyixD6s/0L5JFUOhYl4p9JSWa/L BarO4xfwT0WPvx2RC6APp99A6+498Pw5q8snV4npKxcRQgEeIPiq93llJvnq84Ty4zS9 hdu1zgEafYyK5Z5JmWsDbE+Cqd1n67vnH9cudWe81L8hdQrhNjfeBxHT0nnDdJfZarC2 LMPuMzjb2PhqoBPV0bYNlZvnR2YJAs+bqm7w8UhbGriiQYnkEAeEHqG2VCtYqqDFFRzg SN0WVaP0xn7NLgNZBSzod6h1Y+klwqlR/fcq21Bw95BaloKM9ie+yBMuWryRsTr8OPsq 0Juw== X-Gm-Message-State: AOAM531vI8cdUFTXpoquUhjOHET1gFvJ+TX4dKvZSkhYt1tZAY0Kmegq G1OAg2+AuohbwKwPewTiekds9g== X-Received: by 2002:a1c:98ca:: with SMTP id a193mr27600896wme.162.1636077501130; Thu, 04 Nov 2021 18:58:21 -0700 (PDT) Received: from localhost.localdomain ([149.86.66.250]) by smtp.gmail.com with ESMTPSA id z15sm6628850wrr.65.2021.11.04.18.58.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Nov 2021 18:58:20 -0700 (PDT) From: Quentin Monnet To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Arnaldo Carvalho de Melo Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, Song Liu , Jiri Olsa , Namhyung Kim , Linux Kernel Mailing List , Quentin Monnet Subject: [PATCH bpf] bpftool: Install libbpf headers for the bootstrap version, too Date: Fri, 5 Nov 2021 01:58:13 +0000 Message-Id: <20211105015813.6171-1-quentin@isovalent.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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