From patchwork Sat Dec 31 06:41:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 37800 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3223676wrt; Fri, 30 Dec 2022 22:43:07 -0800 (PST) X-Google-Smtp-Source: AMrXdXuYQVF408clqMaFGqOJHiKY8Dq9tKtWZLA0PpQwQQZkKiTnhkgYHMTW3WtOIbCSMsr+qmvm X-Received: by 2002:a17:907:b686:b0:7c1:7c3a:ffba with SMTP id vm6-20020a170907b68600b007c17c3affbamr34139903ejc.35.1672468987571; Fri, 30 Dec 2022 22:43:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672468987; cv=none; d=google.com; s=arc-20160816; b=FK9LToeJbWadeM3Ic5Y27P+8jYP3kkQRhBdD119hVPw+WpfVO4izBSpewFKE/gypDl ++YpTeg/Npv1TB7q/uUQ9d7BkRbazCNiP3Xz5ZeCPD5ewl35rAGIAjtmZYsJ37YpD8hr 5KDsUsB40o1Opnd6gWW5OYEjwy3vg+ZKHRHUBdhHfm5kM4quMqLfOFIEmZ2xUbSjERYl xLel9Zpi1uen2Q0Q0LUoj4Zub/pGdrtYwQ4wZegsM12WXaZPIDxT4kRWVNCgqjDwgfKg s276i/pBt5UHiwiPT+VRGfDcuwc5V0lp5CHqYG9wie02mqPyu6ycQFIP9t+pgPg0Abld oXMw== 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; bh=Nuox2driElhcfDUVxnOmACV/olS8bWf2Z9T6SHUIK88=; b=vlepowD5ZZ1u7DtPqUsS8QHclN+s5rejuUDEnbgV8OrIdOnm2dQvHb6VW8XK4a/Wh+ HYwgeF/O2jGh8wqP7gUTtlNQu0tb8btPrWwe8t4S1Wu978OTH/Tca/1n6SFG2Dq/4UnG SVocW8XM/XlO4Iaa78MGmUq/7OYjoF0nvhkAJHqFRKzfKmspPHU6vuem6Hv37xIGkc+2 qCWz75HvvdW7rWQ1Tb9YcCm/LPvOi9F2fv1tjq6ScfrLMGyHJSpyf4UvFRmLwuoogYU1 HOuOQLn+uiHeZFm9PsfmA2s5lw1RuEC5LUQ0v6VDo0OF/oVJquKP8E5sUOyiQz0zzdwl Q8qQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Bs41Jdsr; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j27-20020a170906279b00b00797670441desi14925277ejc.911.2022.12.30.22.42.43; Fri, 30 Dec 2022 22:43:07 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=Bs41Jdsr; 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 S231256AbiLaGma (ORCPT + 99 others); Sat, 31 Dec 2022 01:42:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229551AbiLaGmY (ORCPT ); Sat, 31 Dec 2022 01:42:24 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69A425586; Fri, 30 Dec 2022 22:42:23 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 2FDA9CE19E5; Sat, 31 Dec 2022 06:42:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55F09C43392; Sat, 31 Dec 2022 06:42:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672468939; bh=Qwa4D3ZgQJV7RbwjTglMo37xuB4TaUBPhfzfEDpEJ1U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bs41JdsrVkkub8Q3Y0otDXtekhXGSUv3AYLsCbaWhHk2xqyq4fQLRsVebwEJQsDCn rXRKyJrk0q2aG5emQsqh7r8DBH5NBXy+SlIgtiI24vAlJYTtcoet8Dk2wg65GFV2Go D6gs3Ld2j/rwRxT6PbbPuKu/6tBsy1IL6gMKjwHAuPFZQ5NjrbYsbQfhwib2mE6sma +hSK3BgD0ISPkPJiZNWhwTkkRdwn/9lKWC/2BE78a7r1rMr4Ogm/pGeE0jAUowsoX8 HnvAPavf3Lvrfxm+1GmSOXx3JqkcYlAAzjmKLL1sy+4P2q3VhhTQSQlfCYdeWwlHim o8LxSeE73eM/Q== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Miguel Ojeda , Masahiro Yamada , Alex Gaynor , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Boqun Feng , Gary Guo , Nathan Chancellor , Nick Desaulniers , Nicolas Schier , Tom Rix , Wedson Almeida Filho , llvm@lists.linux.dev, rust-for-linux@vger.kernel.org Subject: [PATCH 1/6] kbuild: specify output names separately for each emission type from rustc Date: Sat, 31 Dec 2022 15:41:58 +0900 Message-Id: <20221231064203.1623793-2-masahiroy@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221231064203.1623793-1-masahiroy@kernel.org> References: <20221231064203.1623793-1-masahiroy@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753710840977511422?= X-GMAIL-MSGID: =?utf-8?q?1753710840977511422?= In Kbuild, two different rules must not write to the same file, but it happens when compiling rust source files. For example, set CONFIG_SAMPLE_RUST_MINIMAL=m and run the following: $ make -j$(nproc) samples/rust/rust_minimal.o samples/rust/rust_minimal.rsi \ samples/rust/rust_minimal.s samples/rust/rust_minimal.ll [snip] RUSTC [M] samples/rust/rust_minimal.o RUSTC [M] samples/rust/rust_minimal.rsi RUSTC [M] samples/rust/rust_minimal.s RUSTC [M] samples/rust/rust_minimal.ll mv: cannot stat 'samples/rust/rust_minimal.d': No such file or directory make[3]: *** [scripts/Makefile.build:334: samples/rust/rust_minimal.ll] Error 1 make[3]: *** Waiting for unfinished jobs.... mv: cannot stat 'samples/rust/rust_minimal.d': No such file or directory make[3]: *** [scripts/Makefile.build:309: samples/rust/rust_minimal.o] Error 1 mv: cannot stat 'samples/rust/rust_minimal.d': No such file or directory make[3]: *** [scripts/Makefile.build:326: samples/rust/rust_minimal.s] Error 1 make[2]: *** [scripts/Makefile.build:504: samples/rust] Error 2 make[1]: *** [scripts/Makefile.build:504: samples] Error 2 make: *** [Makefile:2008: .] Error 2 The reason for the error is that 4 threads running in parallel creates and renames the same file path, samples/rust/rust_minimal.d. This does not happen when compiling C or assembly files because we explicitly specify the dependency filename by using the preprocessor option, -Wp,-MMD,$(depfile). $(depfile) is a unique path for each target. Currently, rustc is only given --out-dir and the list of emitted types. So, all the rust build rules output the dep-info into the default .d, causing the conflict. Fortunately, the --emit option is able to specify the output path individually, with the form --emit==. Add --emit=dep-info=$(depfile) to the common command part. Also, remove the redundant --out-dir because we specify the output path for each type. The code gets much cleaner because we do not need to rename *.d files. Signed-off-by: Masahiro Yamada Reviewed-by: Miguel Ojeda Tested-by: Miguel Ojeda Reviewed-by: Vincenzo Palazzo --- rust/Makefile | 10 ++++------ scripts/Makefile.build | 14 +++++++------- scripts/Makefile.host | 9 +++------ 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/rust/Makefile b/rust/Makefile index ff70c4c916f8..0e2a32f4b3e9 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -331,10 +331,9 @@ $(obj)/exports_kernel_generated.h: $(obj)/kernel.o FORCE quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@ cmd_rustc_procmacro = \ $(RUSTC_OR_CLIPPY) $(rust_common_flags) \ - --emit=dep-info,link --extern proc_macro \ - --crate-type proc-macro --out-dir $(objtree)/$(obj) \ + --emit=dep-info=$(depfile) --emit=link=$@ --extern proc_macro \ + --crate-type proc-macro \ --crate-name $(patsubst lib%.so,%,$(notdir $@)) $<; \ - mv $(objtree)/$(obj)/$(patsubst lib%.so,%,$(notdir $@)).d $(depfile); \ sed -i '/^\#/d' $(depfile) # Procedural macros can only be used with the `rustc` that compiled it. @@ -348,10 +347,9 @@ quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L OBJTREE=$(abspath $(objtree)) \ $(if $(skip_clippy),$(RUSTC),$(RUSTC_OR_CLIPPY)) \ $(filter-out $(skip_flags),$(rust_flags) $(rustc_target_flags)) \ - --emit=dep-info,obj,metadata --crate-type rlib \ - --out-dir $(objtree)/$(obj) -L$(objtree)/$(obj) \ + --emit=dep-info=$(depfile) --emit=obj=$@ --emit=metadata=$(dir $@)$(patsubst %.o,lib%.rmeta,$(notdir $@)) \ + --crate-type rlib -L$(objtree)/$(obj) \ --crate-name $(patsubst %.o,%,$(notdir $@)) $<; \ - mv $(objtree)/$(obj)/$(patsubst %.o,%,$(notdir $@)).d $(depfile); \ sed -i '/^\#/d' $(depfile) \ $(if $(rustc_objcopy),;$(OBJCOPY) $(rustc_objcopy) $@) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index a0d5c6cca76d..40de20246e50 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -285,11 +285,11 @@ rust_common_cmd = \ -Zcrate-attr=no_std \ -Zcrate-attr='feature($(rust_allowed_features))' \ --extern alloc --extern kernel \ - --crate-type rlib --out-dir $(obj) -L $(objtree)/rust/ \ - --crate-name $(basename $(notdir $@)) + --crate-type rlib -L $(objtree)/rust/ \ + --crate-name $(basename $(notdir $@)) \ + --emit=dep-info=$(depfile) rust_handle_depfile = \ - mv $(obj)/$(basename $(notdir $@)).d $(depfile); \ sed -i '/^\#/d' $(depfile) # `--emit=obj`, `--emit=asm` and `--emit=llvm-ir` imply a single codegen unit @@ -302,7 +302,7 @@ rust_handle_depfile = \ quiet_cmd_rustc_o_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@ cmd_rustc_o_rs = \ - $(rust_common_cmd) --emit=dep-info,obj $<; \ + $(rust_common_cmd) --emit=obj=$@ $<; \ $(rust_handle_depfile) $(obj)/%.o: $(src)/%.rs FORCE @@ -310,7 +310,7 @@ $(obj)/%.o: $(src)/%.rs FORCE quiet_cmd_rustc_rsi_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@ cmd_rustc_rsi_rs = \ - $(rust_common_cmd) --emit=dep-info -Zunpretty=expanded $< >$@; \ + $(rust_common_cmd) -Zunpretty=expanded $< >$@; \ command -v $(RUSTFMT) >/dev/null && $(RUSTFMT) $@; \ $(rust_handle_depfile) @@ -319,7 +319,7 @@ $(obj)/%.rsi: $(src)/%.rs FORCE quiet_cmd_rustc_s_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@ cmd_rustc_s_rs = \ - $(rust_common_cmd) --emit=dep-info,asm $<; \ + $(rust_common_cmd) --emit=asm=$@ $<; \ $(rust_handle_depfile) $(obj)/%.s: $(src)/%.rs FORCE @@ -327,7 +327,7 @@ $(obj)/%.s: $(src)/%.rs FORCE quiet_cmd_rustc_ll_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@ cmd_rustc_ll_rs = \ - $(rust_common_cmd) --emit=dep-info,llvm-ir $<; \ + $(rust_common_cmd) --emit=llvm-ir=$@ $<; \ $(rust_handle_depfile) $(obj)/%.ll: $(src)/%.rs FORCE diff --git a/scripts/Makefile.host b/scripts/Makefile.host index da133780b751..4434cdbf7b8e 100644 --- a/scripts/Makefile.host +++ b/scripts/Makefile.host @@ -84,8 +84,8 @@ _hostc_flags = $(KBUILD_HOSTCFLAGS) $(HOST_EXTRACFLAGS) \ $(HOSTCFLAGS_$(target-stem).o) _hostcxx_flags = $(KBUILD_HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \ $(HOSTCXXFLAGS_$(target-stem).o) -_hostrust_flags = $(KBUILD_HOSTRUSTFLAGS) $(HOST_EXTRARUSTFLAGS) \ - $(HOSTRUSTFLAGS_$(target-stem)) +hostrust_flags = $(KBUILD_HOSTRUSTFLAGS) $(HOST_EXTRARUSTFLAGS) \ + $(HOSTRUSTFLAGS_$(target-stem)) --emit=dep-info=$(depfile) # $(objtree)/$(obj) for including generated headers from checkin source files ifeq ($(KBUILD_EXTMOD),) @@ -97,7 +97,6 @@ endif hostc_flags = -Wp,-MMD,$(depfile) $(_hostc_flags) hostcxx_flags = -Wp,-MMD,$(depfile) $(_hostcxx_flags) -hostrust_flags = $(_hostrust_flags) ##### # Compile programs on the host @@ -149,9 +148,7 @@ $(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE # host-rust -> Executable quiet_cmd_host-rust = HOSTRUSTC $@ cmd_host-rust = \ - $(HOSTRUSTC) $(hostrust_flags) --emit=dep-info,link \ - --out-dir=$(obj)/ $<; \ - mv $(obj)/$(target-stem).d $(depfile); \ + $(HOSTRUSTC) $(hostrust_flags) --emit=link=$@ $<; \ sed -i '/^\#/d' $(depfile) $(host-rust): $(obj)/%: $(src)/%.rs FORCE $(call if_changed_dep,host-rust) From patchwork Sat Dec 31 06:41:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 37802 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3224066wrt; Fri, 30 Dec 2022 22:44:51 -0800 (PST) X-Google-Smtp-Source: AMrXdXv/9AXAfrtvwwQGKVxY37phb2uC5M/tb/+e2M/yh7FaOnXMj2V16yJnd7kaO7hnlIrx0Smw X-Received: by 2002:a17:907:7ea1:b0:7c4:f752:e95c with SMTP id qb33-20020a1709077ea100b007c4f752e95cmr36507101ejc.1.1672469091650; Fri, 30 Dec 2022 22:44:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672469091; cv=none; d=google.com; s=arc-20160816; b=eN+OcLecf6DO9X5uCM919I0nEXTu1WZLtKAloWlaPm78DemenZtn6ZQ6zwGcvj11nh W+NTk7CRBN+djCK+U9ZuEGAGQ2XlbvtBRxg1L9CsS4buAm/oXajWw2w4IAc4xf7vSNjO F7FKQLxJLq6sKpkz2IIvNF1KxPJl/0ncAtoF4uKypLagayKoG8w+slOMmVVhHhplBDuV ka2rGYjMDNveOZlHQSnOcNthTn9hFHzyR8rSH77MkcewH8cRzjEO/ce8nnrqgxsu4qoX M9ki8eg+l1awj1rqdElVQnQ3OfePFLonrasUuh9cwsYndJcVYYCtN8f/BpZRD0hJDYUL 0+uw== 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; bh=jaQ41iifk0Js8d8fq9+mmUq1MvLpQqyAthZoyNr0Tks=; b=caMitrZ1iV7ZYJ1rf70zotIAu8db7kSj/dPJ+LqPXEl4Qbrrbdb5r0thcvPULFl6mx cSHwpxJNcCzkg745DIFfhASHSOpdxN/6/p2UylQsRtAXtJZ6xtAakiz7TieqCDXA2xNu XzDm40kFRgBGwhdpgxcHQfTgsP8d6NhTmie946qXviKltQOtVeFUi1//DbBOMymvswhf Ef+0s4NZ3IC1zBC3QxB6WSJLVBgGo2eKFoR7IWxDJuPErV7Z9W67+vFTAIO0Canu9dRq pKtCmr2mU8/wF9bLRTuWurlZ/Avh3alYG0xcAOrMofxdHvDC3+hgEvxARCUjpdqDEhnM r6pA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ELv3wuu9; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m20-20020aa7d354000000b0047866149cdasi17326255edr.388.2022.12.30.22.44.27; Fri, 30 Dec 2022 22:44:51 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=ELv3wuu9; 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 S231530AbiLaGmd (ORCPT + 99 others); Sat, 31 Dec 2022 01:42:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230117AbiLaGmZ (ORCPT ); Sat, 31 Dec 2022 01:42:25 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFBD1DF8C; Fri, 30 Dec 2022 22:42:23 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 99397B80159; Sat, 31 Dec 2022 06:42:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9675C433F0; Sat, 31 Dec 2022 06:42:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672468941; bh=8dy6ygawxzO2uAw8j/hkzj2kvk+GhsocxBamrrWrVEo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ELv3wuu9GOFCKYT4i6h4Wy8eOtGd8UnqGUDBHTU7+m5ZBsaomyuiBDio5cuIqxUqF JtpYUisJWLcyTbgwxj341Pm5pxIeuwahr4mdeKVuHrT105YvQLr7DvkcBw8JEc2cTh 8G3TKYINBiHvw/Q4N+pi68mU5xheO7gQIhbBHlsvOjnHcxWWcvp93C7V50hZ2K436k XHFm7e2U7l959yT8FYSjDoHdJ5zb6N17PSlHlhVfIQnx3XjyVjZy33HODuB+isv/A9 Vp9SlpEtpFVW6lOSC6S6Fa6o4Iyf9w+lvP+vPzMFOqHO09zvim7Xrrh2WqQzj/81dZ tntzJj4Wr70FQ== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Miguel Ojeda , Masahiro Yamada , Nathan Chancellor , Nick Desaulniers , Nicolas Schier , Tom Rix , llvm@lists.linux.dev Subject: [PATCH 2/6] fixdep: parse Makefile more correctly to handle comments etc. Date: Sat, 31 Dec 2022 15:41:59 +0900 Message-Id: <20221231064203.1623793-3-masahiroy@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221231064203.1623793-1-masahiroy@kernel.org> References: <20221231064203.1623793-1-masahiroy@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753710950352696945?= X-GMAIL-MSGID: =?utf-8?q?1753710950352696945?= fixdep parses dependency files (*.d) emitted by the compiler. *.d files are Makefiles describing the dependencies of the main source file. fixdep understands minimal Makefile syntax. It works well enough for GCC and Clang, but not for rustc. This commit improves the parser a little more for better processing comments, escape sequences, etc. My main motivation is to drop comments. rustc may output comments (e.g. env-dep). Currentyly, rustc build rules invoke sed to remove comments, but it is more efficient to do it in fixdep. Signed-off-by: Masahiro Yamada Acked-by: Miguel Ojeda Tested-by: Miguel Ojeda --- scripts/basic/fixdep.c | 173 ++++++++++++++++++++++++++++------------- 1 file changed, 117 insertions(+), 56 deletions(-) diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c index 37782a632494..37a40520686f 100644 --- a/scripts/basic/fixdep.c +++ b/scripts/basic/fixdep.c @@ -94,6 +94,7 @@ #include #include #include +#include #include #include #include @@ -251,75 +252,135 @@ static int is_ignored_file(const char *s, int len) * assignments are parsed not only by make, but also by the rather simple * parser in scripts/mod/sumversion.c. */ -static void parse_dep_file(char *m, const char *target) +static void parse_dep_file(char *p, const char *target) { - char *p; - int is_last, is_target; - int saw_any_target = 0; - int is_first_dep = 0; - void *buf; - - while (1) { - /* Skip any "white space" */ - while (*m == ' ' || *m == '\\' || *m == '\n') - m++; - - if (!*m) - break; - - /* Find next "white space" */ - p = m; - while (*p && *p != ' ' && *p != '\\' && *p != '\n') - p++; - is_last = (*p == '\0'); - /* Is the token we found a target name? */ - is_target = (*(p-1) == ':'); - /* Don't write any target names into the dependency file */ - if (is_target) { - /* The /next/ file is the first dependency */ - is_first_dep = 1; - } else if (!is_ignored_file(m, p - m)) { - *p = '\0'; - + bool saw_any_target = false; + bool is_source = false; + bool searching_colon = true; + bool need_parse; + char *q, saved_c; + + while (*p) { + /* handle some special characters first. */ + switch (*p) { + case '#': /* - * Do not list the source file as dependency, so that - * kbuild is not confused if a .c file is rewritten - * into .S or vice versa. Storing it in source_* is - * needed for modpost to compute srcversions. + * skip comments. + * rustc may emit comments to dep-info. */ - if (is_first_dep) { + p++; + while (*p != '\0' && *p != '\n') { /* - * If processing the concatenation of multiple - * dependency files, only process the first - * target name, which will be the original - * source name, and ignore any other target - * names, which will be intermediate temporary - * files. + * escaped newlines continue the comment across + * multiple lines. */ - if (!saw_any_target) { - saw_any_target = 1; - printf("source_%s := %s\n\n", - target, m); - printf("deps_%s := \\\n", target); + if (*p == '\\') + p++; + p++; + } + continue; + case ' ': + case '\t': + /* skip whitespaces */ + p++; + continue; + case '\\': + /* + * backslash/newline combinations continue the + * statement. Skip it just like a whitespace. + */ + if (*(p + 1) == '\n') { + p += 2; + continue; + } + break; + case '\n': + /* + * Makefiles use a line-based syntax, where the newline + * is the end of a statement. After seeing a newline, + * we expect the next token is a target. + */ + p++; + searching_colon = true; + continue; + case ':': + /* + * assume the first dependency after a colon as the + * source file. + */ + p++; + searching_colon = false; + is_source = true; + continue; + } + + /* find the end of the token */ + q = p; + while (*q != ' ' && *q != '\t' && *q != '\n' && *q != '#' && *q != ':') { + if (*q == '\\') { + if (*(q + 1) == '\n') + break; + + /* escaped special characters */ + if (*(q + 1) == '#' || *(q + 1) == ':') { + memmove(p + 1, p, q - p); + p++; } - is_first_dep = 0; - } else { - printf(" %s \\\n", m); + + q++; } - buf = read_file(m); - parse_config_file(buf); - free(buf); + if (*q == '\0') + break; + q++; } - if (is_last) - break; + /* Just discard the target */ + if (searching_colon) { + p = q; + continue; + } + + saved_c = *q; + *q = '\0'; + need_parse = false; /* - * Start searching for next token immediately after the first - * "whitespace" character that follows this token. + * Do not list the source file as dependency, so that kbuild is + * not confused if a .c file is rewritten into .S or vice versa. + * Storing it in source_* is needed for modpost to compute + * srcversions. */ - m = p + 1; + if (is_source) { + /* + * The DT build rule concatenates multiple dep files. + * When processing them, only process the first source + * name, which will be the original one, and ignore any + * other source names, which will be intermediate + * temporary files. + */ + if (!saw_any_target) { + saw_any_target = true; + printf("source_%s := %s\n\n", target, p); + printf("deps_%s := \\\n", target); + need_parse = true; + } + } else if (!is_ignored_file(p, q - p)) { + printf(" %s \\\n", p); + need_parse = true; + } + + if (need_parse) { + void *buf; + + buf = read_file(p); + parse_config_file(buf); + free(buf); + } + + is_source = false; + *q = saved_c; + p = q; } if (!saw_any_target) { From patchwork Sat Dec 31 06:42:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 37803 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3224079wrt; Fri, 30 Dec 2022 22:44:55 -0800 (PST) X-Google-Smtp-Source: AMrXdXv1jeSfEfUHPp5R2rjpp3CkFwa19sDlHns1lcSnjZPfol7e4uCf4PFzV76W3UwSAHHpNs1l X-Received: by 2002:a17:907:a641:b0:7c1:4e8f:df2f with SMTP id vu1-20020a170907a64100b007c14e8fdf2fmr33712849ejc.17.1672469095359; Fri, 30 Dec 2022 22:44:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672469095; cv=none; d=google.com; s=arc-20160816; b=EvpsDDR1FFeCzR2Sr1dH1DwBMcUQyWh3vmYn1cu+w9I2/TIUYsouK+JndaVhEg0oi3 WsV2SrYGULBO47ESYflDCeTTD++3XXAETndVQpsJeF2i6pJlg8WQsVl0QM6FZAvBgvSq e/7ha3kREOcJfh6aEEVDr9jjGj+fkC0cr0xAHxuCdULukyyJndxaHejiy6LabCBnaNQc MlEJaPrzDFyyvPxdLypjPH6h8oqaV49IJAICQ+7EHb4kBlEkoZ3eoKpZj9gJRE7A/eHz suAkuHgdNlk3Vmylc7fRSzzBYFR1/6UV2aKSfQubIh709H7/zeBccOOPmObCkUMsi/Ph 1QIg== 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; bh=0mJ+T42KgU6nJVsdVNiVPLcN8TFAHUtGEon3oBt0/bY=; b=QiZDDie8AAOR3cuSs533JRGyD2d+OPLf25EFA6bEAhQ/h923X9Lqjuj7eLajjoiroW tX+S3jibUcX5PalycySbQcrejhSHdR+hIy/5+k0YLbNcJrdljp3q5iZwa7F3j64aXG3B 0TC9GvNjhCgY+evhvJG/rBbFjszxAmKAJmBFnc0BkK5GDPhsXfPKxJVw3qgEMdGX2Y09 +Fb+tTeSDYDuY7ChMeXEeuACvJrMlfZzvT+S9bzYf8BF9Y9K0XL/kvaGSDCPtD0Kf4JX OUZ2g7m3hk3HGOmqObTNWUHjvdsO7atPwBYSH5M+LQJIwCX8rV02+ziOmF0PNekwyZQA B/uQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jbLzN1vL; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gt34-20020a1709072da200b007c0f7afccccsi21715289ejc.696.2022.12.30.22.44.31; Fri, 30 Dec 2022 22:44:55 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=jbLzN1vL; 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 S231612AbiLaGmi (ORCPT + 99 others); Sat, 31 Dec 2022 01:42:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230149AbiLaGm1 (ORCPT ); Sat, 31 Dec 2022 01:42:27 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F0EADF1E; Fri, 30 Dec 2022 22:42:25 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1F2176090C; Sat, 31 Dec 2022 06:42:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A9997C4339B; Sat, 31 Dec 2022 06:42:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672468944; bh=TYz0+owbHpGu+NR39J76tZxgsfupHoR+sq24KGH4hCc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jbLzN1vLnGdFxz6Adw0JsfkXLylFO2Yig/xSLeltOj76v04uIB0qr8w9U8fC9yxc0 zX/ExraGY59B6/wRZCqtE4FRXMznLSiawWCGDPxaK1Rqfe/O8bCyTBT8ijswIXPO8h Rc4bsePiBpvGj05fLuy9yMDOiBFGme1U9hSfHW6FpdM7Jw+tvUtvb3Has1BC8lcN1t 9RKEWr4RwkS8I6bjKGZTMayzkuNN6D6EvonR+4c90Lc9bnoAezKjx9Z44hYHdrZszG O9Whunggbozgl1J5x0pouDZoezTbClazpvb9qgmN1LFDf9W6dsP+pIWrWMagvK+DCt gHyST7dx9MB3Q== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Miguel Ojeda , Masahiro Yamada , Alex Gaynor , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Boqun Feng , Gary Guo , Nathan Chancellor , Nick Desaulniers , Nicolas Schier , Tom Rix , Wedson Almeida Filho , llvm@lists.linux.dev, rust-for-linux@vger.kernel.org Subject: [PATCH 3/6] kbuild: remove sed commands after rustc rules Date: Sat, 31 Dec 2022 15:42:00 +0900 Message-Id: <20221231064203.1623793-4-masahiroy@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221231064203.1623793-1-masahiroy@kernel.org> References: <20221231064203.1623793-1-masahiroy@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753710953894217001?= X-GMAIL-MSGID: =?utf-8?q?1753710953894217001?= rustc may put comments in dep-info, so sed is used to drop them before passing it to fixdep. Now that fixdep can remove comments, Makefiles do not need to run sed. Signed-off-by: Masahiro Yamada Reviewed-by: Miguel Ojeda Tested-by: Miguel Ojeda Reviewed-by: Vincenzo Palazzo --- rust/Makefile | 6 ++---- scripts/Makefile.build | 18 ++++-------------- scripts/Makefile.host | 3 +-- 3 files changed, 7 insertions(+), 20 deletions(-) diff --git a/rust/Makefile b/rust/Makefile index 0e2a32f4b3e9..c8941fec6955 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -333,8 +333,7 @@ quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@ $(RUSTC_OR_CLIPPY) $(rust_common_flags) \ --emit=dep-info=$(depfile) --emit=link=$@ --extern proc_macro \ --crate-type proc-macro \ - --crate-name $(patsubst lib%.so,%,$(notdir $@)) $<; \ - sed -i '/^\#/d' $(depfile) + --crate-name $(patsubst lib%.so,%,$(notdir $@)) $< # Procedural macros can only be used with the `rustc` that compiled it. # Therefore, to get `libmacros.so` automatically recompiled when the compiler @@ -349,8 +348,7 @@ quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L $(filter-out $(skip_flags),$(rust_flags) $(rustc_target_flags)) \ --emit=dep-info=$(depfile) --emit=obj=$@ --emit=metadata=$(dir $@)$(patsubst %.o,lib%.rmeta,$(notdir $@)) \ --crate-type rlib -L$(objtree)/$(obj) \ - --crate-name $(patsubst %.o,%,$(notdir $@)) $<; \ - sed -i '/^\#/d' $(depfile) \ + --crate-name $(patsubst %.o,%,$(notdir $@)) $< \ $(if $(rustc_objcopy),;$(OBJCOPY) $(rustc_objcopy) $@) rust-analyzer: diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 40de20246e50..76323201232a 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -289,9 +289,6 @@ rust_common_cmd = \ --crate-name $(basename $(notdir $@)) \ --emit=dep-info=$(depfile) -rust_handle_depfile = \ - sed -i '/^\#/d' $(depfile) - # `--emit=obj`, `--emit=asm` and `--emit=llvm-ir` imply a single codegen unit # will be used. We explicitly request `-Ccodegen-units=1` in any case, and # the compiler shows a warning if it is not 1. However, if we ever stop @@ -301,9 +298,7 @@ rust_handle_depfile = \ # would not match each other. quiet_cmd_rustc_o_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@ - cmd_rustc_o_rs = \ - $(rust_common_cmd) --emit=obj=$@ $<; \ - $(rust_handle_depfile) + cmd_rustc_o_rs = $(rust_common_cmd) --emit=obj=$@ $< $(obj)/%.o: $(src)/%.rs FORCE $(call if_changed_dep,rustc_o_rs) @@ -311,24 +306,19 @@ $(obj)/%.o: $(src)/%.rs FORCE quiet_cmd_rustc_rsi_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@ cmd_rustc_rsi_rs = \ $(rust_common_cmd) -Zunpretty=expanded $< >$@; \ - command -v $(RUSTFMT) >/dev/null && $(RUSTFMT) $@; \ - $(rust_handle_depfile) + command -v $(RUSTFMT) >/dev/null && $(RUSTFMT) $@ $(obj)/%.rsi: $(src)/%.rs FORCE $(call if_changed_dep,rustc_rsi_rs) quiet_cmd_rustc_s_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@ - cmd_rustc_s_rs = \ - $(rust_common_cmd) --emit=asm=$@ $<; \ - $(rust_handle_depfile) + cmd_rustc_s_rs = $(rust_common_cmd) --emit=asm=$@ $< $(obj)/%.s: $(src)/%.rs FORCE $(call if_changed_dep,rustc_s_rs) quiet_cmd_rustc_ll_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@ - cmd_rustc_ll_rs = \ - $(rust_common_cmd) --emit=llvm-ir=$@ $<; \ - $(rust_handle_depfile) + cmd_rustc_ll_rs = $(rust_common_cmd) --emit=llvm-ir=$@ $< $(obj)/%.ll: $(src)/%.rs FORCE $(call if_changed_dep,rustc_ll_rs) diff --git a/scripts/Makefile.host b/scripts/Makefile.host index 4434cdbf7b8e..bc782655d09e 100644 --- a/scripts/Makefile.host +++ b/scripts/Makefile.host @@ -148,8 +148,7 @@ $(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE # host-rust -> Executable quiet_cmd_host-rust = HOSTRUSTC $@ cmd_host-rust = \ - $(HOSTRUSTC) $(hostrust_flags) --emit=link=$@ $<; \ - sed -i '/^\#/d' $(depfile) + $(HOSTRUSTC) $(hostrust_flags) --emit=link=$@ $< $(host-rust): $(obj)/%: $(src)/%.rs FORCE $(call if_changed_dep,host-rust) From patchwork Sat Dec 31 06:42:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 37804 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3224249wrt; Fri, 30 Dec 2022 22:45:47 -0800 (PST) X-Google-Smtp-Source: AMrXdXu34rydKYrdrUfHH7ogS2aqxlEYKbc1QYWhiDyoP/G9lGGgSxcT5rNnQtncbQsQpx3CCWsK X-Received: by 2002:a05:6402:754:b0:485:9d0f:6193 with SMTP id p20-20020a056402075400b004859d0f6193mr15398456edy.38.1672469147158; Fri, 30 Dec 2022 22:45:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672469147; cv=none; d=google.com; s=arc-20160816; b=Dl1ka//uvRhNO3BrQ3T2uogb1Wx9rBTZE3gr4jUZi+EciH0irsW6EBv2dSGhODtQsi vPsfEAqbfBFWAw0XrEX+kr3KVKUr2iS6Qxz2Y8bEeO7Jg2Wb+MoYYrchNBpCnDOaJv77 2a8Ee51qyrOxQzwy7R7vEQ1yszi4cpFv9GgTZy/35tclFCjTtr9qZYJJ00DE56rSvHBN DLuDAS0YR8HMegXbHhtvLf2wMgFSkzHVJ5CoLM8qOqVHq/mx1xRAEM3y7LhlWLQifUNM CJaYJllZ/7IY0u8O1XUz6sMkPnuZSfO257WQp4RQPA4lijSqEjSOoO4AwR1K1FUhnqoA +2sQ== 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; bh=XH7QD3qmAV7vg3U5rOlxdGXmTZVJVo9k8NC3VIYNhN4=; b=CvIPvo/t4lgKXE0WBd+KZrMb3RR/PbU4ZnYtavfBQp1zDP882fLrXfkpIbrn62BGPL yUYapo7XfhM0YhhqZmdxTA4xnpsA4d/fur13Ea5nrOQE4GPwddrcn/PNVPX8YHWGhVkk d2iB/UIBMMsDA2Td1V4IdfM2tGMdUbZB5DTwVRYaeHjPfWB1+q7oPa0RjsBUwKFGicly ZvfSUzoDsnlqkVoR58R5kUIMLE07uJjWIIcxcRtOeMR+8CavO1cX49Nz0Rfa+z5fKRBD aW1oTSWgzFxR9aY/WGGPIPT7moW3YW+6oZjVHFp1JmjviW63acs2l/JhyxSNtvgIzFHU a/yQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FySsNjOR; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o15-20020a056402038f00b00481f6b77528si16808866edv.392.2022.12.30.22.45.23; Fri, 30 Dec 2022 22:45:47 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=FySsNjOR; 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 S235574AbiLaGml (ORCPT + 99 others); Sat, 31 Dec 2022 01:42:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231341AbiLaGm2 (ORCPT ); Sat, 31 Dec 2022 01:42:28 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C8F3DF42; Fri, 30 Dec 2022 22:42:27 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 262A460684; Sat, 31 Dec 2022 06:42:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EE19BC433EF; Sat, 31 Dec 2022 06:42:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672468946; bh=gnYVbwrikIqFSC/3hQA0CyfeKXskxX2NMICVYZNaQhY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FySsNjORsocFCVs5MWPxbxZ/uUwAg1Ao0xxcSeEsF3GF26Nwp8FZovO1GLe1oRPYd tPKFUgmYCWIwCR0m2sSU72bZrdxdr/vbCj91BdLFTgz9gPe5bAwD8BI00gW1R/oySu j2sIYHF32rx0pujmkwACAMsaaXOwB/3cCFI8aX7DgiveDz9wvaBfzocZ/xZ/zylclf 0kwNK9ASZdOjJmvutFLsR71ltsSGNm1lmsZF0rUhPLOIh5T2Ddyh/o/4LPa3/8EdVa A8EO8b+jAf2Bk0KGIKSERliCqbeH3gfFmPDuLwh6Mdmcfspne2wLX81bIkWwoBgT99 KQymK2rgel9cQ== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Miguel Ojeda , Masahiro Yamada , Nathan Chancellor , Nick Desaulniers , Nicolas Schier Subject: [PATCH 4/6] fixdep: refactor hash table lookup Date: Sat, 31 Dec 2022 15:42:01 +0900 Message-Id: <20221231064203.1623793-5-masahiroy@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221231064203.1623793-1-masahiroy@kernel.org> References: <20221231064203.1623793-1-masahiroy@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753711008857704335?= X-GMAIL-MSGID: =?utf-8?q?1753711008857704335?= Change the hash table code so it will be easier to add the second table. Signed-off-by: Masahiro Yamada Reviewed-by: Miguel Ojeda Tested-by: Miguel Ojeda --- scripts/basic/fixdep.c | 47 ++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c index 37a40520686f..b20777b888d7 100644 --- a/scripts/basic/fixdep.c +++ b/scripts/basic/fixdep.c @@ -113,7 +113,7 @@ struct item { }; #define HASHSZ 256 -static struct item *hashtab[HASHSZ]; +static struct item *config_hashtab[HASHSZ]; static unsigned int strhash(const char *str, unsigned int sz) { @@ -125,25 +125,11 @@ static unsigned int strhash(const char *str, unsigned int sz) return hash; } -/* - * Lookup a value in the configuration string. - */ -static int is_defined_config(const char *name, int len, unsigned int hash) -{ - struct item *aux; - - for (aux = hashtab[hash % HASHSZ]; aux; aux = aux->next) { - if (aux->hash == hash && aux->len == len && - memcmp(aux->name, name, len) == 0) - return 1; - } - return 0; -} - /* * Add a new value to the configuration string. */ -static void define_config(const char *name, int len, unsigned int hash) +static void add_to_hashtable(const char *name, int len, unsigned int hash, + struct item *hashtab[]) { struct item *aux = malloc(sizeof(*aux) + len); @@ -158,17 +144,34 @@ static void define_config(const char *name, int len, unsigned int hash) hashtab[hash % HASHSZ] = aux; } +/* + * Lookup a string in the hash table. If found, just return true. + * If not, add it to the hashtable and return false. + */ +static bool in_hashtable(const char *name, int len, struct item *hashtab[]) +{ + struct item *aux; + unsigned int hash = strhash(name, len); + + for (aux = hashtab[hash % HASHSZ]; aux; aux = aux->next) { + if (aux->hash == hash && aux->len == len && + memcmp(aux->name, name, len) == 0) + return true; + } + + add_to_hashtable(name, len, hash, hashtab); + + return false; +} + /* * Record the use of a CONFIG_* word. */ static void use_config(const char *m, int slen) { - unsigned int hash = strhash(m, slen); - - if (is_defined_config(m, slen, hash)) - return; + if (in_hashtable(m, slen, config_hashtab)) + return; - define_config(m, slen, hash); /* Print out a dependency path from a symbol name. */ printf(" $(wildcard include/config/%.*s) \\\n", slen, m); } From patchwork Sat Dec 31 06:42:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 37801 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3223979wrt; Fri, 30 Dec 2022 22:44:27 -0800 (PST) X-Google-Smtp-Source: AMrXdXuASzslQZbG2IuP6S3S3qmsiElkk5IjamVM/AI8uWw2LqV5LwGBfP5VIdVv1EC1J9qmspBh X-Received: by 2002:a05:6402:501f:b0:460:5706:d1fa with SMTP id p31-20020a056402501f00b004605706d1famr30511423eda.18.1672469067271; Fri, 30 Dec 2022 22:44:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672469067; cv=none; d=google.com; s=arc-20160816; b=SNowiH44ly9ckrYnll4MUIbllL64vQMVQ+o5+qUqK8CiXLPN2yndByT+j0VPn70sVT eRTviiEBsv3dg0DH6y3yMFjDcJQUKNyqeQZk53E2PTuXmnSYxl+2GKNR6nnzI/hbD/ZC XNfhW2TxwCLMByOi+HuMawRLrCaMk6IXlRwPYrRFtZN8636JZvXXaS+iPr+GIH3zG6Og 9RrwA/lvuXHRphk4F06eivGGY/xn9q2BkMXeWJvYWUCKDWAXgsj/7y95AZgi0yuwzj96 sa5ySACANRsqJcyfJm8uUyruxiJXR9EodW0WIEDK38PvWhiNPrg3oso89+xQCBX0eFHD +Xrw== 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; bh=DyvBvZjd+CYM/B16zyuDoXPa9QvQw53x3uoHqOi2jzI=; b=KeXb7FetpkJbNcUEqqEqG5exqo4VgS/N6iae5lxGgVwVxlXOSebZ7RFjWtqCU+CkAz sqqM7PB4x1OW5MAdhqWcYkqTzorrDdKmLq2+5Z3Ol+DtiXHDiSIr7rv7uauPmbvKlK4Q CEOEAxqGafb/UUTz5zsuBjJygPdKA4Fbbo8lh1uJY553NFzB8vAaIqYKd8DitBcB9gLZ Ok2c2AiZ3fBWLGVegRpr6f1nv8xCxR2MTCl/paROXV2rl+rlzwnG05CKDAUo3Ur9mYFX RVns1aZIKcVJORdPPcghmwhGfHLEZJDTIJu9rLT8F19/jgg8+h34gI9se7gEIMqTl+bo DBOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CjVgtKIE; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x5-20020a056402414500b00484e95ad48bsi12823836eda.115.2022.12.30.22.44.03; Fri, 30 Dec 2022 22:44:27 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=CjVgtKIE; 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 S235614AbiLaGmq (ORCPT + 99 others); Sat, 31 Dec 2022 01:42:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231508AbiLaGmb (ORCPT ); Sat, 31 Dec 2022 01:42:31 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88FE0DF1E; Fri, 30 Dec 2022 22:42:30 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 18E8060907; Sat, 31 Dec 2022 06:42:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05A2DC43398; Sat, 31 Dec 2022 06:42:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672468949; bh=pPtNFbrwZDEe7R9hGihgBI1Cy7TXHMHG4P1tYoFNjZ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CjVgtKIEuSKQV5RCpmNW/O1yoF8JI3xd4McrQbIA1czpfqaWgRrk6xd17BGHx0PCm DFolHEM19x+a1P2/nb6IRjgHxdQ8jIa4JXX7AlN3oWWhy7oYUZ6IDqVWRWnxdn3lT+ asNw5BnhqGchSuGcSLoup/1h6PO6BKWS0EVdJye5wpTpFPNymP3pn5cjdKHPre+bd9 i35/ppuKtMFTmAhI3VmsvfST7UgTpDXRHbURyPRtzHGmFoOYYzhDhHX3By9gt+HH3z YhVjAzGUxc7HxAFwbKQKjw8jiN3dmx4LDphYdntmnQp1Q9PG2Z4nQZg5z9mLoJDfwK 8aJdtTZBiB4Jw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Miguel Ojeda , Masahiro Yamada , Alex Gaynor , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Boqun Feng , Gary Guo , Nathan Chancellor , Nick Desaulniers , Nicolas Schier , Wedson Almeida Filho , rust-for-linux@vger.kernel.org Subject: [PATCH 5/6] fixdep: avoid parsing the same file over again Date: Sat, 31 Dec 2022 15:42:02 +0900 Message-Id: <20221231064203.1623793-6-masahiroy@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221231064203.1623793-1-masahiroy@kernel.org> References: <20221231064203.1623793-1-masahiroy@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753710924394491779?= X-GMAIL-MSGID: =?utf-8?q?1753710924394491779?= The dep files (*.d files) emitted by C compilers usually contain the deduplicated list of included files. There is an exceptional case; if a header is included by the -include command line option, and also by #include directive, it appears twice in the *.d file. For example, the top Makefile specifies the command line option, -include $(srctree)/include/linux/kconfig.h. You do not need to add #include in every source file. In fact, include/linux/kconfig.h is listed twice in many .*.cmd files due to include/linux/xarray.h including . I did not fix that since it is a small redundancy. However, this is more annoying for rustc. rustc emits the dependency for each emission type. For example, cmd_rustc_library emits dep-info, obj, and metadata. So, the emitted *.d file contains the dependency for those 3 targets, which makes fixdep parse the same file 3 times. $ grep rust/alloc/raw_vec.rs rust/.alloc.o.cmd rust/alloc/raw_vec.rs \ rust/alloc/raw_vec.rs \ rust/alloc/raw_vec.rs \ To skip the second parsing, this commit adds a hash table for parsed files, just like we did for CONFIG options. Signed-off-by: Masahiro Yamada Acked-by: Miguel Ojeda Tested-by: Miguel Ojeda Reviewed-by: Vincenzo Palazzo --- scripts/basic/fixdep.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c index b20777b888d7..cc8f6d34c2ca 100644 --- a/scripts/basic/fixdep.c +++ b/scripts/basic/fixdep.c @@ -113,7 +113,7 @@ struct item { }; #define HASHSZ 256 -static struct item *config_hashtab[HASHSZ]; +static struct item *config_hashtab[HASHSZ], *file_hashtab[HASHSZ]; static unsigned int strhash(const char *str, unsigned int sz) { @@ -361,6 +361,10 @@ static void parse_dep_file(char *p, const char *target) * name, which will be the original one, and ignore any * other source names, which will be intermediate * temporary files. + * + * rustc emits the same dependency list for each + * emission type. It is enough to list the source name + * just once. */ if (!saw_any_target) { saw_any_target = true; @@ -368,7 +372,8 @@ static void parse_dep_file(char *p, const char *target) printf("deps_%s := \\\n", target); need_parse = true; } - } else if (!is_ignored_file(p, q - p)) { + } else if (!is_ignored_file(p, q - p) && + !in_hashtable(p, q - p, file_hashtab)) { printf(" %s \\\n", p); need_parse = true; } From patchwork Sat Dec 31 06:42:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 37805 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3225042wrt; Fri, 30 Dec 2022 22:49:40 -0800 (PST) X-Google-Smtp-Source: AMrXdXtKgAbrc9Pord1ZNgOJpsnKdPTvumVtDFw2aFdbgygz1oAUhINZU3jPP/3raQNh+0UMhDk3 X-Received: by 2002:a05:6402:a55:b0:475:9918:37ce with SMTP id bt21-20020a0564020a5500b00475991837cemr29565601edb.13.1672469379972; Fri, 30 Dec 2022 22:49:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672469379; cv=none; d=google.com; s=arc-20160816; b=uiKylXbdAAYmfGHKk0ZY/JbM8WRlfYbUIQj6Jn9O9J2+xSd5FtfzmHIe8kv1JZvV07 yK7RGX+DjQcN7ai8TA99ODnU/udtui7VpU9tkxXDTN7Q6zg0OAUtg0inl6xaot4/WK/5 Hzvij40/oz/A2h1CWorpiwd2hggGG3R4FNYOynuMIlyQ09VJERlHSz2Lci2ONJrVkOgV 5mbdQG5RPIlG62KhcpAIJKc1PQdY2MFzz5CKjVyE6x+mC83vAKJh/W6Ef/JMZD8tu5Lb sn0oNb8ARX4AZbZIYXpa3tBYhecsTu6szZM4SQeIAMSsV/BLr3OKCN6WqHWLr/pU3dHa V2QQ== 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; bh=mS+QwM2C48TKR4S1u/eqCDmgzkfx5YUcl5DAJhuEy/E=; b=zVGK9O9jVJQ26vukpP6Pf5nYUAkNyQRLTjiUeOshI8UAiwFfsqfC2JwVo0X8q5zf8z Wb9BFkQVxj2DPD/tZ9JGHr0KnqEnfDTFJBU5Wi11RbGHFvQe3IS0oJUpZC73NH60mtTl z/V1v67WUB8J0vtcKYs/mZ38q+b6SlnLAlDUNyfNkE4VwTKX3ZBkVZsjDZeLwrZeE2eV hqkXcTnO0+ngD8ViYn3t+aFyAnKiMQYBfW3ulS4RpcFNBlK2KV7aQ5jL2xt56c7U9Ouh da4d0H6bgB/rYPrXI420PIpArAa4cc4z3C5qfRX6aHbggWnmG53/RHBNGFl3oYiocCJ/ UnnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YQpteJpG; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xc3-20020a170907074300b007825337afeesi19339631ejb.273.2022.12.30.22.49.13; Fri, 30 Dec 2022 22:49:39 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=YQpteJpG; 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 S235623AbiLaGmt (ORCPT + 99 others); Sat, 31 Dec 2022 01:42:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231553AbiLaGmj (ORCPT ); Sat, 31 Dec 2022 01:42:39 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D406A13FA1; Fri, 30 Dec 2022 22:42:34 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 34DA8CE19E5; Sat, 31 Dec 2022 06:42:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2D05C433D2; Sat, 31 Dec 2022 06:42:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672468951; bh=5OrrSG3HnFPsNx647A+ePC6NFhN8w9ptOuEE6V18iio=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YQpteJpGRVv60LnIO7ahIvfLcIxAKn74971cR7DTRmsYTY33XJHnS08UUG+84IoBP pVe1xO14P/bla6/4BYWc98HdAwu0NndZIrktvbokoATjjIaAqJzurUacaFvULcpVxu 96Mys0LKaInJn01urGD9T/qbvbrNiy6+3s6ZuRtZuOBC3AmChrsbrxDHYBqe+32EQX j3bKXf4V+KVbLIo+9LILeLLZtrzjCCQDGav8oSIFbKmjBrg4Ww4IH2qQaS36CBFioS VUHm9N4+9+h7hrukuvytq1Zlv9F1qGNgUhEbQoEeXIWa4sT+EQanqf+yRoRXDFkdhJ xxxM0M6O6iV5g== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Miguel Ojeda , Masahiro Yamada , Nathan Chancellor , Nick Desaulniers , Nicolas Schier Subject: [PATCH 6/6] fixdep: do not parse *.so, *.rmeta, *.rlib Date: Sat, 31 Dec 2022 15:42:03 +0900 Message-Id: <20221231064203.1623793-7-masahiroy@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221231064203.1623793-1-masahiroy@kernel.org> References: <20221231064203.1623793-1-masahiroy@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753711252634247743?= X-GMAIL-MSGID: =?utf-8?q?1753711252634247743?= fixdep is designed only for parsing text files. read_file() appends a terminating null byte ('\0') and parse_config_file() calls strstr() to search for CONFIG options. rustc outputs *.so, *.rmeta, *rlib to dep-info. fixdep needs them in the dependency, but there is no point to parse such binary files. Signed-off-by: Masahiro Yamada Reviewed-by: Miguel Ojeda Tested-by: Miguel Ojeda --- scripts/basic/fixdep.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c index cc8f6d34c2ca..b70885116ed2 100644 --- a/scripts/basic/fixdep.c +++ b/scripts/basic/fixdep.c @@ -250,6 +250,15 @@ static int is_ignored_file(const char *s, int len) str_ends_with(s, len, "include/generated/autoksyms.h"); } +/* Do not parse these files */ +static int is_no_parse_file(const char *s, int len) +{ + /* rustc may output binary files into dep-info */ + return str_ends_with(s, len, ".rlib") || + str_ends_with(s, len, ".rmeta") || + str_ends_with(s, len, ".so"); +} + /* * Important: The below generated source_foo.o and deps_foo.o variable * assignments are parsed not only by make, but also by the rather simple @@ -378,7 +387,7 @@ static void parse_dep_file(char *p, const char *target) need_parse = true; } - if (need_parse) { + if (need_parse && !is_no_parse_file(p, q - p)) { void *buf; buf = read_file(p);