Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2274220ioo; Sat, 28 May 2022 08:54:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwrGwf+8hxLMkDQk5XLYVI0A/4S00oQ1N7jwgnng6LSlZEl54WX3O8pJMt+SQ6ClIF1lPcA X-Received: by 2002:a17:90a:408f:b0:1d1:d1ba:2abb with SMTP id l15-20020a17090a408f00b001d1d1ba2abbmr13903555pjg.152.1653753262841; Sat, 28 May 2022 08:54:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653753262; cv=none; d=google.com; s=arc-20160816; b=A+yEP3e1N6suim3sQtwgHqSPcjNuBieEtbQH38W6ay6+NmBM7f6Jrm/M4vpwWgJ1ve VjDS+qVQw0/wr/0+m/p2QME36G8ouJh8U4FC+2l8tSo/K0yjDwNzczGDdqIc9LXcn0fo bTXjmeS1BENm6VHvdbp30SMWbbGFPVWom0/F0aprBN2jMPwpJIf5hDwcyQIaA+cqiqfs HinwtaUiwulZSy1zZayWOKY7sFU58NrP4tOE3z64sVz9tvFPB4w7p+qBS1hYG/QS8LF3 xi2qwwAxB/jf7UslTvJQL+ZX6WCkrog09KRHNa6JOjkyGVkYTr3N/Hqt2G/j2idQB8nD kYMw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=aeTLWp41sB2px7vbsl+AoWvoxM63JuytaCqa9JH2QLY=; b=K/pQQD9hxl0cGjzWpC1ArXUs0x0niDAIyXh+LDCX26C2GUEdUL832kIDRTbDQj8S1s fiLqva/ufokjPH6/YFy3DU1TLH+ovNXQKk6eUPYEPvGPDWwLcEvfsltREN1Ni+FEJb8/ G+omoyIBEEhzRDJRPnzgseQUTm14ThgFH76UhcYlBFmZS+usjlnv+CbXIjoLpyM1+HsK atwKb444Nm1LJcHNYWVcm0RiR9QI9MPQ0dH66XnuYaGv6m5TEcU4wVlGT3fGula9nydN wvtTFEF52YXwogzYJxBbP4rSGEveL937LasILkaXW7X4jvkmQ6yyLe0pfoWOlbzV3ewl ihxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=HNBXNGON; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c15-20020a630d0f000000b003db58038619si9414833pgl.836.2022.05.28.08.54.10; Sat, 28 May 2022 08:54:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=HNBXNGON; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1350800AbiE0KFo (ORCPT + 99 others); Fri, 27 May 2022 06:05:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350930AbiE0KFP (ORCPT ); Fri, 27 May 2022 06:05:15 -0400 Received: from conuserg-08.nifty.com (conuserg-08.nifty.com [210.131.2.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12D0110656D; Fri, 27 May 2022 03:05:14 -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 24RA2hPV029808; Fri, 27 May 2022 19:02:49 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-08.nifty.com 24RA2hPV029808 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1653645770; bh=aeTLWp41sB2px7vbsl+AoWvoxM63JuytaCqa9JH2QLY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HNBXNGONQ3XAXjEyNsT812P/sRM9yUOuKeEx6rV5MeMv1NxMHnZVXWp2u3jL3+YhO hHwEyE27UCcCCype5LopeDwcShy1TIjgvIzb35fNVES8P6DPUjAtO/oKmWQyrjKn7e bNLeFrwGDnwLBGzZ9ECYC+HfWtv1orzRaQxDXtS4bmogZCcZlcfc0L4a8I5xbtRerl AENHInpUJ2umDWLEQ3o3RVbecF3RavfGGRbduj+yTrY6zqZ1VeHFrt267AKy33Vb4M j/NpQV/JGiOhD8mPqsR5WAZPocvvNN8niceVYS/cuIu+CoXuwCESKCAm4kbrQ1JKic Dpe+I0j85Opbg== 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 5/8] kbuild: make built-in.a rule robust against too long argument error Date: Fri, 27 May 2022 19:01:52 +0900 Message-Id: <20220527100155.1996314-6-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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_SOFTFAIL, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Kbuild runs at the top of objtree instead of changing the working directory to subdirectories. I think this design is nice overall but some commands have a scalability issue. The build command of built-in.a is one of them whose length scales with: O(D * N) Here, D is the length of the directory path (i.e. $(obj)/ prefix), N is the number of objects in the Makefile, O() is the big O notation. The deeper directory the Makefile directory is located, the more easily it will hit the too long argument error. We can make it better. Trim the $(obj)/ by Make's builtin function, and restore it by a shell command (sed). With this, the command length scales with: O(D + N) 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 builtin (CONFIG_DRM_I915=y) and compare drivers/gpu/drm/i915/.built-in.a.cmd with/without this commit. 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 Changes in v2: - New patch scripts/Makefile.build | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 0135b4e7f78b..014ebee70fd6 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -376,9 +376,14 @@ $(subdir-modorder): $(obj)/%/modules.order: $(obj)/% ; # # Rule to compile a set of .o files into one .a file (without symbol table) # +# To make this rule robust against "Argument list too long" error, +# remove $(obj)/ prefix, and restore it by a shell command. quiet_cmd_ar_builtin = AR $@ - cmd_ar_builtin = rm -f $@; $(AR) cDPrST $@ $(real-prereqs) + cmd_ar_builtin = rm -f $@; \ + echo $(patsubst $(obj)/%,%,$(real-prereqs)) | \ + sed -E 's:([^ ]+):$(obj)/\1:g' | \ + xargs $(AR) cDPrST $@ $(obj)/built-in.a: $(real-obj-y) FORCE $(call if_changed,ar_builtin) -- 2.32.0