From patchwork Fri May 27 10:01:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 12863199 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3865C4332F for ; Fri, 27 May 2022 10:05:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350537AbiE0KF1 (ORCPT ); Fri, 27 May 2022 06:05:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350936AbiE0KFT (ORCPT ); Fri, 27 May 2022 06:05:19 -0400 Received: from conuserg-08.nifty.com (conuserg-08.nifty.com [210.131.2.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BCB110656D; Fri, 27 May 2022 03:05:17 -0700 (PDT) Received: from grover.sesame (133-32-177-133.west.xps.vectant.ne.jp [133.32.177.133]) (authenticated) by conuserg-08.nifty.com with ESMTP id 24RA2hPW029808; Fri, 27 May 2022 19:02:50 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-08.nifty.com 24RA2hPW029808 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1653645771; bh=3Oj1DhJn8CmLNtWlFeZrpT6DZfeTSEt5AwsBsBHThdw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v0PffPwf03F/kuXj7tkaHCU736AoC3p/iSQGFT4EuXdSk7N4AHNFlo+HaQjmoyMK5 MYXLldeol6bR3qKJAaweMayW9SJ7L6Ol6Gx2LFBAz6wUIBmKQeNtVMh+l6om88wy+U 9sXkPMptAwV2mpoMEItMwB2cESfr5Y0wkSPl1NUMRVGd1ntYQ/pbDemHSt8Yc71iwX ZDOd7CzWE/FqZ/+GM1ZY3esJH3uCAuKs1WCrHQ7JXPKRhsYCDRAqY01YdQQusFIhY8 jXOfjZIOwRY7MZIVVBUlPLoYWmd/bZ5dq9bXs3v3fdYJ4Uu2NTj8B9IZyukH/7O3RK JL/jIbsOZOSlQ== X-Nifty-SrcIP: [133.32.177.133] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Josh Poimboeuf , llvm@lists.linux.dev, Helge Deller , linux-parisc@vger.kernel.org, Masahiro Yamada , Nicolas Schier , Nathan Chancellor , Sedat Dilek , Michal Marek , Nick Desaulniers , Tom Rix Subject: [PATCH v7 6/8] kbuild: make *.mod rule robust against too long argument error Date: Fri, 27 May 2022 19:01:53 +0900 Message-Id: <20220527100155.1996314-7-masahiroy@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220527100155.1996314-1-masahiroy@kernel.org> References: <20220527100155.1996314-1-masahiroy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-parisc@vger.kernel.org Like built-in.a, the command length of the *.mod rule scales with the depth of the directory times the number of objects in the Makefile. Add $(obj)/ by the shell command (awk) instead of by Make's builtin function. In-tree modules still have some room to the limit (ARG_MAX=2097152), but this is more future-proof for big modules in a deep directory. For example, you can build i915 as a module (CONFIG_DRM_I915=m) and compare drivers/gpu/drm/i915/.i915.mod.cmd with/without this commit. The issue is more critical for external modules because the M= path can be very long as Jeff Johnson reported before [1]. [1] https://lore.kernel.org/linux-kbuild/4c02050c4e95e4cb8cc04282695f8404@codeaurora.org/ Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier Tested-by: Nathan Chancellor Tested-by: Sedat Dilek # LLVM-14 (x86-64) --- Changes in v7: - Add comment to the code scripts/Makefile.build | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 014ebee70fd6..31feb798e16e 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -274,8 +274,10 @@ $(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE $(call if_changed_rule,cc_o_c) $(call cmd,force_checksrc) -cmd_mod = echo $(addprefix $(obj)/, $(call real-search, $*.o, .o, -objs -y -m)) | \ - $(AWK) -v RS='( |\n)' '!x[$$0]++' > $@ +# To make this rule robust against "Argument list too long" error, +# ensure to add $(obj)/ prefix by a shell command. +cmd_mod = echo $(call real-search, $*.o, .o, -objs -y -m) | \ + $(AWK) -v RS='( |\n)' '!x[$$0]++ { print("$(obj)/"$$0) }' > $@ $(obj)/%.mod: FORCE $(call if_changed,mod)