From patchwork Mon Jul 15 20:32:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 13733899 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF62713A416 for ; Mon, 15 Jul 2024 20:33:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721075630; cv=none; b=HASG0NiY9hIYGR6fgVo40HFZpcXM9BgUAQEd9vamhDmkXrKYdsypi9CMv0VZCH0bPCkienwJ+pSdXn94RY6SGrDyMk69UB29PeaZifT8N/uKufMWoHL+z3SVDE0NDZqQhE4x63Xi7eDh62D2T756Jjg7m41Ir1oXXYxHT84lDeg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721075630; c=relaxed/simple; bh=OtjVNwo381SC/keZfjeduCwHTRDWCVPReYZb0X3r5SY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HXFywl6jm5oHaruV3uqbE+Ym78o78vtsMyxVHuIgJ1mSBo7MWEMF+QdzP+0jYZCzFXgVLMRH2BFiDIzUoVfexJOBp2+b/5fLR5maFvs1GukGCHg5fEnBclf8JQTYTiBKNoFahPwjkHctA9/HpLkIwqUGDBDp4iNUg0dWpXYmanI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=RuqCN2nK; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="RuqCN2nK" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1fb4a807708so42282875ad.2 for ; Mon, 15 Jul 2024 13:33:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1721075628; x=1721680428; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fV8GQ3sNmW9UM2g7XLCappSiUKhDHjx9Q2PF1jfbifQ=; b=RuqCN2nKYmAeFZeV5ORARlvFXdYTO58s/TEUh+/PWf+++qzABqrk+aSp4p7Q5VeUXk VMB5cJ5euX2BFh0p70PjMxR6ajgFR5pjupEA2vj5+CL/HXoMC2arkEhjgEIM0GI/vPTv Q+1RldTDreJ+TNOdFBN+oVPV6cJxuKOoVvAKY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721075628; x=1721680428; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fV8GQ3sNmW9UM2g7XLCappSiUKhDHjx9Q2PF1jfbifQ=; b=wR0Yf0sXUbjSdbio/yulkKJgV2B/ZSbAKaDmrACDTdxhSebIfiaLoLLfiG0yMEnSEl ws3BHW01mnP45aZ8AjM7JN5piSvPyR6VlTvfUr7nL2Pd4lq5Wb2e2V3ixlIyvrb9D5VL uDKZfUeN/YYq47pMusERaHDq7DWvQOmjjtc07hqCH0XZ4bEUSbjcvL22J4jz6fgzW2L/ 6vnLQ0Ydzg8mHT8rbZoDsc1JkfeEcMsIv9FE70/J2RgFYq4kBOPqBxohhI0V2RzC0Ffc X6DljwAm5mK4bK6oTOJjWbGpsbzmlXAjX4VPiEDP+1P8SuuuJfn6y4O2qv73PX9cSn6c UYBg== X-Forwarded-Encrypted: i=1; AJvYcCWFEKZILD6pbIwMV1T7eGjPiHdmhCXM8tl+Qa1ccyu8ZVcquKtlZeWkNXU+XtXCV1iqwAYAZKbCCOR2cPJoEfmuygdluuSH26V4FZr2 X-Gm-Message-State: AOJu0YxYmnx1mDvY/uCeUJSV3yAIPTXh1wH95on80gpLXYNnifiekB4W RCJhGT26pc6uhTRRlpwQ5rBK4roxZmqwUVPlsMnPGntqZ7cYo+zlTVNvT8hCYD1fCsRt/wgbtyI = X-Google-Smtp-Source: AGHT+IFRhxgNHjtN3riipF2pMHlSVgaaC2CKlJ6yHHSh/TXqNehk7BJcZJvHPomUNrJFu/h5juOz3w== X-Received: by 2002:a17:902:ea07:b0:1fb:75b6:a43d with SMTP id d9443c01a7336-1fbb6d4c958mr208021045ad.32.1721075628124; Mon, 15 Jul 2024 13:33:48 -0700 (PDT) Received: from localhost ([2620:15c:9d:2:9b77:1ea5:9de2:19a3]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-1fc0bb9bf42sm45317405ad.79.2024.07.15.13.33.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 15 Jul 2024 13:33:47 -0700 (PDT) From: Brian Norris To: Arnaldo Carvalho de Melo , Namhyung Kim , Ian Rogers , Thomas Richter , Josh Poimboeuf , Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Masahiro Yamada , bpf@vger.kernel.org, linux-kbuild@vger.kernel.org, Brian Norris , Jiri Olsa Subject: [PATCH v4 1/3] tools build: Correct libsubcmd fixdep dependencies Date: Mon, 15 Jul 2024 13:32:42 -0700 Message-ID: <20240715203325.3832977-2-briannorris@chromium.org> X-Mailer: git-send-email 2.45.2.993.g49e7a77208-goog In-Reply-To: <20240715203325.3832977-1-briannorris@chromium.org> References: <20240715203325.3832977-1-briannorris@chromium.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 All built targets need fixdep to be built first, before handling object dependencies [1]. We're missing one such dependency before the libsubcmd target. This resolves .cmd file generation issues such that the following sequence produces many fewer results: $ git clean -xfd tools/ $ make tools/objtool $ grep "cannot find fixdep" $(find tools/objtool -name '*.cmd') In particular, only a buggy tools/objtool/libsubcmd/.fixdep.o.cmd remains, due to circular dependencies of fixdep on itself. Such incomplete .cmd files don't usually cause a direct problem, since they're designed to fail "open", but they can cause some subtle problems that would otherwise be handled by proper fixdep'd dependency files. [2] [1] This problem is better described in commit abb26210a395 ("perf tools: Force fixdep compilation at the start of the build"). I don't apply its solution here, because additional recursive make can be a bit of overkill. [2] Example failure case: cp -arl linux-src linux-src2 cd linux-src2 make O=/path/to/out cd ../linux-src rm -rf ../linux-src2 make O=/path/to/out Previously, we'd see errors like: make[6]: *** No rule to make target '/path/to/linux-src2/tools/include/linux/compiler.h', needed by '/path/to/out/tools/bpf/resolve_btfids/libsubcmd/exec-cmd.o'. Stop. Now, the properly-fixdep'd .cmd files will ignore a missing /path/to/linux-src2/... Link: https://lore.kernel.org/all/ZGVi9HbI43R5trN8@bhelgaas/ Link: https://lore.kernel.org/all/Zk-C5Eg84yt6_nml@google.com/ Signed-off-by: Brian Norris Acked-by: Jiri Olsa --- (no changes since v3) Changes in v3: - update notes about failure cases - add Jiri's Acked-by tools/lib/subcmd/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/lib/subcmd/Makefile b/tools/lib/subcmd/Makefile index b87213263a5e..59b09f280e49 100644 --- a/tools/lib/subcmd/Makefile +++ b/tools/lib/subcmd/Makefile @@ -76,7 +76,7 @@ include $(srctree)/tools/build/Makefile.include all: fixdep $(LIBFILE) -$(SUBCMD_IN): FORCE +$(SUBCMD_IN): fixdep FORCE @$(MAKE) $(build)=libsubcmd $(LIBFILE): $(SUBCMD_IN) From patchwork Mon Jul 15 20:32:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 13733900 Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5607213C80A for ; Mon, 15 Jul 2024 20:33:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721075631; cv=none; b=NDjcNmwt+ghjkYdtx4blBNLrCFHc1UhfcUywRUU2PIrNvV5qAxOIa2sv9Bc7VaZMr17tdMwgp9xTRLY9lYovM0AyUjvc2WQkAlj4H2wXyf1bYTBUBdL6r0eo9FHrpqXksBxfhLQjsw0LsUFCkSSSk+5WVpbfy4tt8EGcQCEFR0Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721075631; c=relaxed/simple; bh=zJomEKpkKYNnqzHoHfBCm5/jn6FvVrqd1kCQ8VySfoU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R2K2Mv/7KYOgbxojjE3CtekPWaRQ3mQlROeq8Ao5WFnpRNvUIMnvd4He2OpA446N8MChj4JjhRFvY/90GDF8QTwjRmgWtsDvQfRPkmd5pj686Hm1bUqFDDJdGO5qLHlQfsFghZWkFnGaFxCM/ekD8Y3+zNi6RkvhZ6+6v16Dy9o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=ECa9htMZ; arc=none smtp.client-ip=209.85.215.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="ECa9htMZ" Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-793a3a79a83so759171a12.3 for ; Mon, 15 Jul 2024 13:33:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1721075629; x=1721680429; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BmXJ/q72ZyRMCe7zWQfBgo3XyY9yIuyVP7WwwEY/t1k=; b=ECa9htMZTvPPFj4L7apDKo76OcnP6ZM6CeYeRnvvTZ7GuaGvb5/QWEddzyAPtITw3N K7QQpFX42SW3d+jphKeTdh2j24mTzsvokGrFK2/y6DblFOUOC2BCdXhODN9C1262OB70 zHGIBHciaJT0a9NJHWlXRkDFT/uq2UTllvN/s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721075629; x=1721680429; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BmXJ/q72ZyRMCe7zWQfBgo3XyY9yIuyVP7WwwEY/t1k=; b=thedCrhCiJZViM7Xyd+nl7nbm7xf1Q4EviN14IYmNJHfRVYm63vceWtNAob5z6O2YE 38Kscq84dOt99Do+q3iTjyQ8xc29N3Z/i86cH7tq9yuMJS8ICo2MV87xI16FMDWv1wjY 4Orc7Mt+52aADdbFpL/EX9x8ldwPYyxU1nnCrtq1fCc+fCWT47S1rGSCB3wOv13VjgAw yxfIFh8Jy+HiPc3Ihflx1PsLEe+jlxzkqu1qKvb1R+QAvvLR4gR/ky7Y9sHPXmxTlx6z eSX+MTEPd1fwgNdz8OHOBJT3fcqur1raR65GLF+KHBhAUT7UM/hRaNxISgu/vGJA3qDo NOXg== X-Forwarded-Encrypted: i=1; AJvYcCX44p1zIApVnYJzbT72Hg8coK8H94biHEnZwCLlOPTqJkcKS1UOCHgjyNQmQkDlTa7RG9GBIzj+7ZyQxfg143kEEeHjtDeW+8QqfTXP X-Gm-Message-State: AOJu0YwAYzuPQu1bzdCyD4koKFsftUdMFgUDRDI2s6UkzBTwl1DSLY6n rE/H2sYlJyje1M1iIgKOERSeIMAspMQjTetEkDjUQTHI8wYCV+QdJ+LSoutH6w== X-Google-Smtp-Source: AGHT+IFnk6iBYgvYmylTEhHv/VyQX05gg9m3qIAc6Mgy9YKCKSrAY/jDDld7K1BC1I2BGqTw6voHaQ== X-Received: by 2002:a05:6a21:9985:b0:1c0:dd3d:ef3a with SMTP id adf61e73a8af0-1c3f123ea4amr109721637.29.1721075629670; Mon, 15 Jul 2024 13:33:49 -0700 (PDT) Received: from localhost ([2620:15c:9d:2:9b77:1ea5:9de2:19a3]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-1fc0bc4ff41sm44921725ad.272.2024.07.15.13.33.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 15 Jul 2024 13:33:49 -0700 (PDT) From: Brian Norris To: Arnaldo Carvalho de Melo , Namhyung Kim , Ian Rogers , Thomas Richter , Josh Poimboeuf , Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Masahiro Yamada , bpf@vger.kernel.org, linux-kbuild@vger.kernel.org, Brian Norris Subject: [PATCH v4 2/3] tools build: Avoid circular .fixdep-in.o.cmd issues Date: Mon, 15 Jul 2024 13:32:43 -0700 Message-ID: <20240715203325.3832977-3-briannorris@chromium.org> X-Mailer: git-send-email 2.45.2.993.g49e7a77208-goog In-Reply-To: <20240715203325.3832977-1-briannorris@chromium.org> References: <20240715203325.3832977-1-briannorris@chromium.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The 'fixdep' tool is used to post-process dependency files for various reasons, and it runs after every object file generation command. This even includes 'fixdep' itself. In Kbuild, this isn't actually a problem, because it uses a single command to generate fixdep (a compile-and-link command on fixdep.c), and afterward runs the fixdep command on the accompanying .fixdep.cmd file. In tools/ builds (which notably is maintained separately from Kbuild), fixdep is generated in several phases: 1. fixdep.c -> fixdep-in.o 2. fixdep-in.o -> fixdep Thus, fixdep is not available in the post-processing for step 1, and instead, we generate .cmd files that look like: ## from tools/objtool/libsubcmd/.fixdep.o.cmd # cannot find fixdep (/path/to/linux/tools/objtool/libsubcmd//fixdep) [...] These invalid .cmd files are benign in some respects, but cause problems in others (such as the linked reports). Because the tools/ build system is rather complicated in its own right (and pointedly different than Kbuild), I choose to simply open-code the rule for building fixdep, and avoid the recursive-make indirection that produces the problem in the first place. Link: https://lore.kernel.org/all/Zk-C5Eg84yt6_nml@google.com/ Signed-off-by: Brian Norris Acked-by: Jiri Olsa Tested-by: Thorsten Leemhuis --- (no changes since v3) Changes in v3: - Drop unnecessary tools/build/Build tools/build/Build | 3 --- tools/build/Makefile | 11 ++--------- 2 files changed, 2 insertions(+), 12 deletions(-) delete mode 100644 tools/build/Build diff --git a/tools/build/Build b/tools/build/Build deleted file mode 100644 index 76d1a4960973..000000000000 --- a/tools/build/Build +++ /dev/null @@ -1,3 +0,0 @@ -hostprogs := fixdep - -fixdep-y := fixdep.o diff --git a/tools/build/Makefile b/tools/build/Makefile index 17cdf01e29a0..fea3cf647f5b 100644 --- a/tools/build/Makefile +++ b/tools/build/Makefile @@ -43,12 +43,5 @@ ifneq ($(wildcard $(TMP_O)),) $(Q)$(MAKE) -C feature OUTPUT=$(TMP_O) clean >/dev/null endif -$(OUTPUT)fixdep-in.o: FORCE - $(Q)$(MAKE) $(build)=fixdep - -$(OUTPUT)fixdep: $(OUTPUT)fixdep-in.o - $(QUIET_LINK)$(HOSTCC) $(KBUILD_HOSTLDFLAGS) -o $@ $< - -FORCE: - -.PHONY: FORCE +$(OUTPUT)fixdep: $(srctree)/tools/build/fixdep.c + $(QUIET_CC)$(HOSTCC) $(KBUILD_HOSTLDFLAGS) -o $@ $< From patchwork Mon Jul 15 20:32:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 13733901 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE40213CF86 for ; Mon, 15 Jul 2024 20:33:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721075633; cv=none; b=QLQBPHa35tChMdY78/QVGfCmkK8HotcatcPnrxjzIFqtiox2h6rEAQqchSw9FuEI4qU9+AG3rdn/4mOxS+3Vje2DpEIgQ/d++ukYATC2Rca6ZFuYw2x4AxhzlggihbfpGcDfxadZF3IuyA/7f0CJo1PxgY5vRo4xhZD7BQu49TY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721075633; c=relaxed/simple; bh=JEI8gAdqk4mZuCAVVRn/25JMk4drGzzZ8zKmP1BSQgY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CZMOa5Jx/SSkKpH48fnA+OdAUPjTkrYlLKtZxNComF8xYbKVzM154lfAs41EYuIt+1A9/5/ri/WOUwfTWmkj3KMJ0dN05hV7WIYZoL81yRHjRTyJzbbf+ppEnQRixj5F/mfqP8C9QYnHD+McnBtifvWUorbWA/LsgZ9ZwnFCDF4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=H/eEr5YL; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="H/eEr5YL" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1fc07295bb0so15797635ad.2 for ; Mon, 15 Jul 2024 13:33:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1721075631; x=1721680431; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QagJQ5EBNzZIM/flu3JEUsij3j0Y4FzDew5rj+TiVcg=; b=H/eEr5YLgBH3MkNioPcLO9CSdVqbUWfFfg88U3sb3t3l3DBdMOpxVq1iPe/Qb2hnmR 3thSX8MH1dLnr0UZtZ7NAFDmqhJZIwI2uSY/2+z7NtJQBAzPflx6HyUjYtWrazWerB8L /NP5zEDCYcC0iOzzWi9HChZTJolESWTuiNDrQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721075631; x=1721680431; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QagJQ5EBNzZIM/flu3JEUsij3j0Y4FzDew5rj+TiVcg=; b=Ie62McD8qsRsZdKrou2kd7SFQvkSwjPE2cmJ/Ec4zzkxYXq4MwOdEK+zsx8e1niY8n aqP90im++Udn6JWnwKaDw6dSuDhg5NT+j/08vHkQll6H8S8fYoh8ml/oAWj7lODFK2ka iomeS5WFdF0aJohrFyX0vD336MTT7mSiavU+TSwypSznL5uxTSjCeZgnVaAN0ERmqa1L aoCoiq8XbtuuKmMwghIzRvYMiJMbXb4IEcTiv5G50JEemYIEGiu2FtkOhPMQ2p5Ltxme oacc3fUsMCQOZOCEQasl/aJH9UlWraRfnV0xaAaGmX32c6eYe1wMPoCxGxwxsIPUYQhW AwtA== X-Forwarded-Encrypted: i=1; AJvYcCX83qdr3rdWcxWEf/DffoA6wOAt2Fuxsq71ZWXJ8cmZzQBir6JTNgJQlWSxTIHW5K84O8acP599B7Ok3O4BDIoBHcq28SrXr/4+E5JQ X-Gm-Message-State: AOJu0YzVa4geGzaqasw8vtmvUK22UAiZpCKwmqoU+TPxLt/ArUB+KokE xrqS1nc/Zki6GC1FyHO0tjMKey5yM16gDrP+AZH5FraTI0kL1pENFLNjzxzRiw== X-Google-Smtp-Source: AGHT+IFfCLt2+h56owcmhJH7aR25w4v2Rcxjnnajy6sxLj46dbJoAc0mzb1xFU/8SNiSiIhVjg88rQ== X-Received: by 2002:a17:903:27d0:b0:1fb:8419:8377 with SMTP id d9443c01a7336-1fbb6d67625mr101200875ad.61.1721075631327; Mon, 15 Jul 2024 13:33:51 -0700 (PDT) Received: from localhost ([2620:15c:9d:2:9b77:1ea5:9de2:19a3]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-1fc0bc2712csm45258775ad.176.2024.07.15.13.33.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 15 Jul 2024 13:33:51 -0700 (PDT) From: Brian Norris To: Arnaldo Carvalho de Melo , Namhyung Kim , Ian Rogers , Thomas Richter , Josh Poimboeuf , Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Masahiro Yamada , bpf@vger.kernel.org, linux-kbuild@vger.kernel.org, Brian Norris , Jiri Olsa Subject: [PATCH v4 3/3] tools build: Correct bpf fixdep dependencies Date: Mon, 15 Jul 2024 13:32:44 -0700 Message-ID: <20240715203325.3832977-4-briannorris@chromium.org> X-Mailer: git-send-email 2.45.2.993.g49e7a77208-goog In-Reply-To: <20240715203325.3832977-1-briannorris@chromium.org> References: <20240715203325.3832977-1-briannorris@chromium.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The dependencies in tools/lib/bpf/Makefile are incorrect. Before we recurse to build $(BPF_IN_STATIC), we need to build its 'fixdep' executable. I can't use the usual shortcut from Makefile.include: : fixdep because its 'fixdep' target relies on $(OUTPUT), and $(OUTPUT) differs in the parent 'make' versus the child 'make' -- so I imitate it via open-coding. I tweak a few $(MAKE) invocations while I'm at it, because 1. I'm adding a new recursive make; and 2. these recursive 'make's print spurious lines about files that are "up to date" (which isn't normally a feature in Kbuild subtargets) or "jobserver not available" (see [1]) I also need to tweak the assignment of the OUTPUT variable, so that relative path builds work. For example, for 'make tools/lib/bpf', OUTPUT is unset, and is usually treated as "cwd" -- but recursive make will change cwd and so OUTPUT has a new meaning. For consistency, I ensure OUTPUT is always an absolute path. And $(Q) gets a backup definition in tools/build/Makefile.include, because Makefile.include is sometimes included without tools/build/Makefile, so the "quiet command" stuff doesn't actually work consistently without it. After this change, top-level builds result in an empty grep result from: $ grep 'cannot find fixdep' $(find tools/ -name '*.cmd') [1] https://www.gnu.org/software/make/manual/html_node/MAKE-Variable.html If we're not using $(MAKE) directly, then we need to use more '+'. Signed-off-by: Brian Norris Acked-by: Jiri Olsa Acked-by: Andrii Nakryiko --- Changes in v4: - update tools/lib/bpf/.gitignore to exclude 'fixdep' - update tools/lib/bpf `make clean` target for fixdep - combine $(SHARED_OBJDIR) and $(STATIC_OBJDIR) rules Changes in v3: - add Jiri's Acked-by Changes in v2: - also fix libbpf shared library rules - ensure OUTPUT is always set, and always an absolute path - add backup $(Q) definition in tools/build/Makefile.include tools/build/Makefile.include | 12 +++++++++++- tools/lib/bpf/.gitignore | 1 + tools/lib/bpf/Makefile | 13 ++++++++++--- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/tools/build/Makefile.include b/tools/build/Makefile.include index 8dadaa0fbb43..0e4de83400ac 100644 --- a/tools/build/Makefile.include +++ b/tools/build/Makefile.include @@ -1,8 +1,18 @@ # SPDX-License-Identifier: GPL-2.0-only build := -f $(srctree)/tools/build/Makefile.build dir=. obj +# More than just $(Q), we sometimes want to suppress all command output from a +# recursive make -- even the 'up to date' printout. +ifeq ($(V),1) + Q ?= + SILENT_MAKE = +$(Q)$(MAKE) +else + Q ?= @ + SILENT_MAKE = +$(Q)$(MAKE) --silent +endif + fixdep: - $(Q)$(MAKE) -C $(srctree)/tools/build CFLAGS= LDFLAGS= $(OUTPUT)fixdep + $(SILENT_MAKE) -C $(srctree)/tools/build CFLAGS= LDFLAGS= $(OUTPUT)fixdep fixdep-clean: $(Q)$(MAKE) -C $(srctree)/tools/build clean diff --git a/tools/lib/bpf/.gitignore b/tools/lib/bpf/.gitignore index 0da84cb9e66d..f02725b123b3 100644 --- a/tools/lib/bpf/.gitignore +++ b/tools/lib/bpf/.gitignore @@ -5,3 +5,4 @@ TAGS tags cscope.* /bpf_helper_defs.h +fixdep diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile index 2cf892774346..1b22f0f37288 100644 --- a/tools/lib/bpf/Makefile +++ b/tools/lib/bpf/Makefile @@ -108,6 +108,8 @@ MAKEOVERRIDES= all: +OUTPUT ?= ./ +OUTPUT := $(abspath $(OUTPUT))/ export srctree OUTPUT CC LD CFLAGS V include $(srctree)/tools/build/Makefile.include @@ -141,7 +143,10 @@ all: fixdep all_cmd: $(CMD_TARGETS) check -$(BPF_IN_SHARED): force $(BPF_GENERATED) +$(SHARED_OBJDIR) $(STATIC_OBJDIR): + $(Q)mkdir -p $@ + +$(BPF_IN_SHARED): force $(BPF_GENERATED) | $(SHARED_OBJDIR) @(test -f ../../include/uapi/linux/bpf.h -a -f ../../../include/uapi/linux/bpf.h && ( \ (diff -B ../../include/uapi/linux/bpf.h ../../../include/uapi/linux/bpf.h >/dev/null) || \ echo "Warning: Kernel ABI header at 'tools/include/uapi/linux/bpf.h' differs from latest version at 'include/uapi/linux/bpf.h'" >&2 )) || true @@ -151,9 +156,11 @@ $(BPF_IN_SHARED): force $(BPF_GENERATED) @(test -f ../../include/uapi/linux/if_xdp.h -a -f ../../../include/uapi/linux/if_xdp.h && ( \ (diff -B ../../include/uapi/linux/if_xdp.h ../../../include/uapi/linux/if_xdp.h >/dev/null) || \ echo "Warning: Kernel ABI header at 'tools/include/uapi/linux/if_xdp.h' differs from latest version at 'include/uapi/linux/if_xdp.h'" >&2 )) || true + $(SILENT_MAKE) -C $(srctree)/tools/build CFLAGS= LDFLAGS= OUTPUT=$(SHARED_OBJDIR) $(SHARED_OBJDIR)fixdep $(Q)$(MAKE) $(build)=libbpf OUTPUT=$(SHARED_OBJDIR) CFLAGS="$(CFLAGS) $(SHLIB_FLAGS)" -$(BPF_IN_STATIC): force $(BPF_GENERATED) +$(BPF_IN_STATIC): force $(BPF_GENERATED) | $(STATIC_OBJDIR) + $(SILENT_MAKE) -C $(srctree)/tools/build CFLAGS= LDFLAGS= OUTPUT=$(STATIC_OBJDIR) $(STATIC_OBJDIR)fixdep $(Q)$(MAKE) $(build)=libbpf OUTPUT=$(STATIC_OBJDIR) $(BPF_HELPER_DEFS): $(srctree)/tools/include/uapi/linux/bpf.h @@ -263,7 +270,7 @@ install_pkgconfig: $(PC_FILE) install: install_lib install_pkgconfig install_headers -clean: +clean: fixdep-clean $(call QUIET_CLEAN, libbpf) $(RM) -rf $(CMD_TARGETS) \ *~ .*.d .*.cmd LIBBPF-CFLAGS $(BPF_GENERATED) \ $(SHARED_OBJDIR) $(STATIC_OBJDIR) \