From patchwork Sat Jan 7 09:18:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 40319 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1223927wrt; Sat, 7 Jan 2023 01:19:33 -0800 (PST) X-Google-Smtp-Source: AMrXdXu5hhqNP+QD7KsszrJwwohC++R0WyTQeuIehVaD2ZTIX15g/6s86rEWXeD8DVYNP+1q7Vw8 X-Received: by 2002:a05:6a21:6da7:b0:a3:22f3:27ca with SMTP id wl39-20020a056a216da700b000a322f327camr90077631pzb.56.1673083173558; Sat, 07 Jan 2023 01:19:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673083173; cv=none; d=google.com; s=arc-20160816; b=mcL906sIkN0e75Xa/4KITbbo/cMIQFYcT/YAPzFxKTMJHPt1OUoU7mSGj+CFZE4KB6 ycvB064jyV0C9tKTjtW7PjVp6h++/z57fpa1OjTPYEUlyRxRYXC0wigJPYld7gV1mE1e yK+pKzXUFN8HWsGBk/rjAw6LDICcW1mhkYagPbr6inFwuZEj6wRHO47whiYOXfRJsjjb OaG84evHqNK0uHjHi3UqgqoP8Da//4i2CczkWWGXVmgXcAc+99utwEH8k4VP8j5tYB8m hs4+OGc7jJB+FyRxQRisTmrUQVbkb9e8VQgdTkIzFhiV7BpDFbRvHxBF50a6x5Gkl8V/ xIww== 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=AEU+4bheOkRNAJ150Vzv/+gwlcT8QApV6Jp+aFTGLQQ=; b=y84ObAtLVTv4akOv19gPgvCkDlix/RAoErCFL3HiHfYIyNBcTt+sgQc+nJjhXbU9pS QrTrUNCm0CusKHlrXs8Q8prwrZ/AjsCc/VCO6WrMUOQYaYhr/xlYm/TEdzpC2Xe44hJR XV7uKNusu/Yki3KBue68AunplLe9kquZfcVgaAtHz5Hs4J92pcVDGdiHpR1ETkGrubSl Z9lR54vQqrnpbsVlmT3ANfLvdnotzhSfwQixoTr7y0JfhoKJ407EQk2JTl0vTKp2c57b 4/E8k9Y/FrgDtOIqnCJupCWf1cU0OsnN+eT8L9666dyInUb/zJnSUL+Xrn0w5ardBGuU F6nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fsnwGHOw; 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 p32-20020a634f60000000b00479337c8eabsi3779872pgl.581.2023.01.07.01.19.20; Sat, 07 Jan 2023 01:19:33 -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=fsnwGHOw; 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 S230102AbjAGJSb (ORCPT + 99 others); Sat, 7 Jan 2023 04:18:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231580AbjAGJSa (ORCPT ); Sat, 7 Jan 2023 04:18:30 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 271F984616; Sat, 7 Jan 2023 01:18:29 -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 B3CF160A09; Sat, 7 Jan 2023 09:18:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BFE6AC433D2; Sat, 7 Jan 2023 09:18:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673083108; bh=fj9DjQEVF1RKNJP+CRcGEz388dyhnFsoR6WMjCFOqHU=; h=From:To:Cc:Subject:Date:From; b=fsnwGHOwZfHklgbqUSUyhatDVeC/fUYvpEDJMNQxgVOQa4EYHFlP0FZ7ZRauoYCdX IpGQN1psHERmx+1zIf9RLUp06ul2FFJFOa2eUDhX4gI85FnQ2rCBWYYCOZC1hQ/1oZ 8uKJHkCfJPT+833hRcyH1DiXBY5hddItC9XZVAtJ7cAhFyQdCjwZKFwVJ+xAW8gxa4 Pj9mide8PomsgUFps2lGfhH26NNnh8eLALU3cH/n8GiNkcOlTiUuFo6cZW1sfFx9k+ 90YmPES4SXDPNTCbLzspB3O5hvamFGeGjRxr9lH5jnPlltDtwPLN+QrNx/pGzG1c9I BgoOAey0DXt4g== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , rust-for-linux@vger.kernel.org, Masahiro Yamada , Nathan Chancellor , Nick Desaulniers , Nicolas Schier Subject: [PATCH v2 1/7] kbuild: refactor host*_flags Date: Sat, 7 Jan 2023 18:18:14 +0900 Message-Id: <20230107091820.3382134-1-masahiroy@kernel.org> X-Mailer: git-send-email 2.34.1 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?1754354861777616072?= X-GMAIL-MSGID: =?utf-8?q?1754354861777616072?= Remove _host*_flags. This will change the -Wp,-MMD,$(depfile) order in the command line but no functional change is intended. Signed-off-by: Masahiro Yamada Reviewed-by: Miguel Ojeda Tested-by: Miguel Ojeda --- Changes in v2: - New patch scripts/Makefile.host | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/scripts/Makefile.host b/scripts/Makefile.host index da133780b751..dea494ef55d5 100644 --- a/scripts/Makefile.host +++ b/scripts/Makefile.host @@ -80,25 +80,21 @@ host-rust := $(addprefix $(obj)/,$(host-rust)) ##### # Handle options to gcc. Support building with separate output directory -_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)) +hostc_flags = $(KBUILD_HOSTCFLAGS) $(HOST_EXTRACFLAGS) \ + $(HOSTCFLAGS_$(target-stem).o) -Wp,-MMD,$(depfile) +hostcxx_flags = $(KBUILD_HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \ + $(HOSTCXXFLAGS_$(target-stem).o) -Wp,-MMD,$(depfile) +hostrust_flags = $(KBUILD_HOSTRUSTFLAGS) $(HOST_EXTRARUSTFLAGS) \ + $(HOSTRUSTFLAGS_$(target-stem)) # $(objtree)/$(obj) for including generated headers from checkin source files ifeq ($(KBUILD_EXTMOD),) ifdef building_out_of_srctree -_hostc_flags += -I $(objtree)/$(obj) -_hostcxx_flags += -I $(objtree)/$(obj) +hostc_flags += -I $(objtree)/$(obj) +hostcxx_flags += -I $(objtree)/$(obj) endif endif -hostc_flags = -Wp,-MMD,$(depfile) $(_hostc_flags) -hostcxx_flags = -Wp,-MMD,$(depfile) $(_hostcxx_flags) -hostrust_flags = $(_hostrust_flags) - ##### # Compile programs on the host From patchwork Sat Jan 7 09:18:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 40321 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1223993wrt; Sat, 7 Jan 2023 01:19:48 -0800 (PST) X-Google-Smtp-Source: AMrXdXu990HN1Yg++w6ms0rn8gX362WKY2ILqQBw9XOA9Xc7InkecV409LzwMxgQUtQ+8biydHmG X-Received: by 2002:a05:6a20:3c8a:b0:af:8128:757 with SMTP id b10-20020a056a203c8a00b000af81280757mr93126345pzj.61.1673083188618; Sat, 07 Jan 2023 01:19:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673083188; cv=none; d=google.com; s=arc-20160816; b=b/5aFbaSWp+WCu7uXO4zbfeMLlJZCHrQtqM7ESGJ/zYgmirSewmQMLwvbacAMPxI3O la8z+SByuH/OoolRzfYPOgkvOc/+1cXVJpmjP9HBSxXV6nl0ra/yIyFkDBzpuxXS+MvS Gp3wZwrueXBg5J8iVP7/y/xkxTk6IYMF0Esap6HCBk5C5FmHVJlsq/G9aQ63JrGO5xoY +LtjRR5CT+o+TucdSI3t8u3BclL/cR8uyLVHxlkZ3Gts3QVDc6ThLovqBxhhLpfSL6xw coNNvUVpjYjBx4uxt5XLdbFaEQiV2Fxwk3ri4zPwCTZykzBTy813tiSj2hlrqFRUvYnW wxhA== 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=71hA3CCf/FiDLnsrouVdDFMs12whvv+k5+S69bMF6HY=; b=SIM76wpNIurdKitdzU2QxCBxkkHfTUrODEzNyKncjWB1CqK8l/R1tgAfDDz8KIXmF3 gNuY6bcwnd+F0UpktuszaQJE1ne+Y9K0kfYrtbl6Bz8KPaSGxZG+MddofdeAS84wCRT5 s9/IEDLTpd/rRg7TJDATp+lvoc1+4SVWk1AoHheu7dmqb1ATr/SyTNrP4uyGfxnuqS3j y50ZcsLRAeiQFNDarscbUcC6jePxdDt1f6rDh7U6HSd446vi4gF/BQW4/+MF2bNee8gL VoCOADQkmyn+M9q0kLD4qgf9yDxvS17cpWafgz0MWcQ1UZW/EpcxkHlvzo4ysycoCDFF NeWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="bn/zBTlN"; 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 24-20020aa79218000000b00572ee9a0c46si3291998pfo.346.2023.01.07.01.19.36; Sat, 07 Jan 2023 01:19:48 -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="bn/zBTlN"; 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 S231580AbjAGJSk (ORCPT + 99 others); Sat, 7 Jan 2023 04:18:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230236AbjAGJSe (ORCPT ); Sat, 7 Jan 2023 04:18:34 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D5CD85CB0; Sat, 7 Jan 2023 01:18:33 -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 0CF0F606A0; Sat, 7 Jan 2023 09:18:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A2752C433F0; Sat, 7 Jan 2023 09:18:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673083112; bh=0QF2lzNN/SLn4tIfGJY0no6diuyNZkG0xSiunadzdwQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bn/zBTlN/qu9/Q/toTAoVwwdm6H665REKlxjr9NaCH1ds7yhrw8wNfqpK5mi/hmXm 8V6WJcyVYjKjzfmz98tYnt9GRa9QtdWkn6qWYYTD8Unid/lPiFkq+XYGR/oVY2Vlf+ Or5h7tt6tjJV0PpKZlrD9lTzQtKRjiZUkHtXc5+nuRnWer9NAs+GCDS8LOOYpd1GM+ V6CWuvEIeEJeFr6Kv1i9QY/f7R7hviBYNBTOw6fNq3R3mb1y3zB1ng2p/E83deCxl8 LOG6TXnLlfI75hyHZHBEPfWQFDMsQPK02bJmMf311q2zcMOxy7LZbALbKGzISwZCtr n2BZ7OwHKyRyA== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , rust-for-linux@vger.kernel.org, Masahiro Yamada , Vincenzo Palazzo , Nathan Chancellor , Nick Desaulniers , Nicolas Schier , Tom Rix , llvm@lists.linux.dev Subject: [PATCH v2 2/7] kbuild: specify output names separately for each emission type from rustc Date: Sat, 7 Jan 2023 18:18:15 +0900 Message-Id: <20230107091820.3382134-2-masahiroy@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230107091820.3382134-1-masahiroy@kernel.org> References: <20230107091820.3382134-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?1754354877568292023?= X-GMAIL-MSGID: =?utf-8?q?1754354877568292023?= 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 renames the same file, samples/rust/rust_minimal.d. This does not happen when compiling C or assembly files because -Wp,-MMD,$(depfile) explicitly specifies the dependency filepath. $(depfile) is a unique path for each target. Currently, rustc is only given --out-dir and --emit= So, all the rust build rules output the dep-info into the default .d, which causes the path 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 part. Also, remove the redundant --out-dir because the output path is specified 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 --- Changes in v2: - Wrap a too long line rust/Makefile | 11 +++++------ scripts/Makefile.build | 14 +++++++------- scripts/Makefile.host | 6 ++---- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/rust/Makefile b/rust/Makefile index ff70c4c916f8..865afb87bc9b 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,10 @@ 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 dea494ef55d5..67ef852712d4 100644 --- a/scripts/Makefile.host +++ b/scripts/Makefile.host @@ -85,7 +85,7 @@ hostc_flags = $(KBUILD_HOSTCFLAGS) $(HOST_EXTRACFLAGS) \ hostcxx_flags = $(KBUILD_HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \ $(HOSTCXXFLAGS_$(target-stem).o) -Wp,-MMD,$(depfile) hostrust_flags = $(KBUILD_HOSTRUSTFLAGS) $(HOST_EXTRARUSTFLAGS) \ - $(HOSTRUSTFLAGS_$(target-stem)) + $(HOSTRUSTFLAGS_$(target-stem)) --emit=dep-info=$(depfile) # $(objtree)/$(obj) for including generated headers from checkin source files ifeq ($(KBUILD_EXTMOD),) @@ -145,9 +145,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 Jan 7 09:18:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 40320 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1223949wrt; Sat, 7 Jan 2023 01:19:37 -0800 (PST) X-Google-Smtp-Source: AMrXdXsfD8Bz3V9jCk+590ejMW1cUL2Pkvgmh4+aPjbyRQzwtbmZeNmal9ta63eqh354VKa5HWe4 X-Received: by 2002:a05:6a20:a682:b0:af:fcb6:2ef6 with SMTP id ba2-20020a056a20a68200b000affcb62ef6mr83292412pzb.23.1673083177315; Sat, 07 Jan 2023 01:19:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673083177; cv=none; d=google.com; s=arc-20160816; b=GKso0qcBl3t1MHg9OlCSA/zglNqVMccQv1HQ676MBA1NLZDhHy2hgF6cg0WSPR5DXG ZEkd+gNgjsF6pkrUQxqzahxRSYcm2XYuUqzx/lgWxl70lU/EYa/T1Ys1tnysBp3lRme8 07Y/Pp/phqnynex7FN1Bm9bWPDjCiPaaI2DYgJJ440yhh7WAe5LmbMA60QGp67B+epzR 3ZyV0N7lsAb7RG86A4ZjUqW6X3jj+3aO/re4+zWgcVgQhvCaMYjAPiSu1OflTjvrEl3i oxI+aGwc1ASez/LcsqU4T+xmwDg66HeZMqKkBv3c3N2GgyBvWBlKBY/lSowWD+YG4W7g oNmg== 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=OB4CFK3nK+oCk+u14+YPIOOZlvzOJA40r7rsLKMNFj8=; b=GJkQKNPo2J7AX558su/Vhg/zfeCCr7CMfLSdaz4gqfyd7eSz7qRtHBcfg8utFbPtMF 8nb1prrGzSd+w0rJGnj8uEehvTBX9TexqjiSYRGmSNjT7a5581Qttr8CgZmV7c2//eF3 C1nSd3QbpzwOzdM6OVovPKdWaniyRAz5n5JthJLXWTKOzU8d/9bDhvd/fZLuHbs3DdTH DCkkmBYq/melmgIGtkpg0H4UApWqbiFQdic8EM0+O5OkeFHnVRw6iMQj8/AdzIjCy7pE uHqcEcYWxZfRPleU01VvhtxvkBVvrr1MDTf6AGJm1MlWRi05pN/ZBZxyUvX75Gs+kcQt BBUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aYFrVZsS; 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 i13-20020a63540d000000b00476deba079fsi3640581pgb.507.2023.01.07.01.19.24; Sat, 07 Jan 2023 01:19:37 -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=aYFrVZsS; 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 S232019AbjAGJS5 (ORCPT + 99 others); Sat, 7 Jan 2023 04:18:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231749AbjAGJSu (ORCPT ); Sat, 7 Jan 2023 04:18:50 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2C8885CA1; Sat, 7 Jan 2023 01:18:38 -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 890F4B81E27; Sat, 7 Jan 2023 09:18:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EBDF0C433EF; Sat, 7 Jan 2023 09:18:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673083116; bh=3blh9oSLoNamYh9NWhbTPvhef5a0zDqGldGZ48E9Mzo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aYFrVZsSxtozAFBliQDD+/luTh0CNzwFpi7rWPds/UZKlSWGjyYgOvdKxJhDSQ+np gJM4hFTHTQEF8rKIc7gkHohVr+/7cisXwIeURF3GCQHRHB0igW58rslk9dz4Xr/HOE x7Nm8wYipQLXGRATGpDsBoqBe4OPy2PwwXgxk6LvNeC158W2le0NVcoTBs21inxxgc yGZZOwEJEXiXiyJo2wXUDrZEOBh9jEe763vpel6hjZ3AT2xumHeNdnGNF9GFk0VLxn FDWv/ESfxPMgZ7lHMR3XEuE1yJxcQOAxLyx1+C4d6Bfn0WOoKfX0xeeir0x1S9lUvV erLPkTGrfvgGQ== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , rust-for-linux@vger.kernel.org, Masahiro Yamada , Nathan Chancellor , Nick Desaulniers , Nicolas Schier , Tom Rix , llvm@lists.linux.dev Subject: [PATCH v2 3/7] fixdep: parse Makefile more correctly to handle comments etc. Date: Sat, 7 Jan 2023 18:18:16 +0900 Message-Id: <20230107091820.3382134-3-masahiroy@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230107091820.3382134-1-masahiroy@kernel.org> References: <20230107091820.3382134-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?1754354865568648464?= X-GMAIL-MSGID: =?utf-8?q?1754354865568648464?= 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 --- Changes in v2: - Rename searching_colon -> is_target - More comments scripts/basic/fixdep.c | 173 ++++++++++++++++++++++++++++------------- 1 file changed, 119 insertions(+), 54 deletions(-) diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c index 37782a632494..f5a51770eb74 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,139 @@ 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) + bool saw_any_target = false; + bool is_target = true; + bool is_source = false; + bool need_parse; + char *q, saved_c; + + while (*p) { + /* handle some special characters first. */ + switch (*p) { + case '#': + /* + * skip comments. + * rustc may emit comments to dep-info. + */ + p++; + while (*p != '\0' && *p != '\n') { + /* + * escaped newlines continue the comment across + * multiple lines. + */ + 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; - - /* Find next "white space" */ - p = m; - while (*p && *p != ' ' && *p != '\\' && *p != '\n') + 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++; - 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'; - + is_target = true; + continue; + 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. + * assume the first dependency after a colon as the + * source file. */ - if (is_first_dep) { + p++; + is_target = false; + is_source = true; + continue; + } + + /* find the end of the token */ + q = p; + while (*q != ' ' && *q != '\t' && *q != '\n' && *q != '#' && *q != ':') { + if (*q == '\\') { /* - * 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. + * backslash/newline combinations work like as + * a whitespace, so this is the end of token. */ - if (!saw_any_target) { - saw_any_target = 1; - printf("source_%s := %s\n\n", - target, m); - printf("deps_%s := \\\n", target); + 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 (is_target) { + 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 Jan 7 09:18:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 40323 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1224126wrt; Sat, 7 Jan 2023 01:20:21 -0800 (PST) X-Google-Smtp-Source: AMrXdXs9eHjwQL/P5/DSywFaDlZLtNNHp/I0BWPUmf1sDYf7oB3IVTk/XvXHbrda3+Ajf3+237S4 X-Received: by 2002:a17:902:aa96:b0:18e:8223:6447 with SMTP id d22-20020a170902aa9600b0018e82236447mr57073078plr.22.1673083220810; Sat, 07 Jan 2023 01:20:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673083220; cv=none; d=google.com; s=arc-20160816; b=fjezQcDUoAcgXia6LAb5QC1MMgiJ42zv7tDS/e8DbJZkWjeGZlltQeuA/y7KP0sDcH NIZKfe5ALsSWfFYs4lOyDd1wdpXmJAaDt5QrTG5mohu6R4U0Qbck+7fgqApnbgQZuUjc z63FRgnN933JLQzRVY4va/wO7Ga9Qbphye2HentDP3BeKO18yefWC5Tr/I+5JwMKa/yK 13hSfyLjXdbpcmo2ro8QiDJwABSDXsIocbnJxgyMfTAXfELwx1CXYWB2UsVbnX+jP2// 9Ah9F2DdgBcz9vXARLIWVPUwpR8F0D3UpaF/R7od9ZrOHAYsD0B2HU3MnApsI1gApKU+ mH3Q== 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=SruosgFiPV5303uHQRvtkt+TtpeX7iXv/PL8yxYUTQA=; b=Yn9cG9vRkAzhJQtVHmUE2kjxgbdWs2j7VF35uHi75nG/LjjNKR6K2xefPb3oDS8q9M Q8z2p+QpbHlRZF1HG3hye6tS7PDdCWpfFCKp6aTOlOj6P2I1OqHKs8hR+W5Qdg5s3GmB QbGNsiVAV90bKv2Z8KCCmLrz1yKLaa7YWwF9gNtYQF8P4qJc0YzQt2ZS/HQyOIwTglg/ KocMIa401MPR6EsEVp5iQDlE68c++VrULS5AulmtZYlM1BuCsf+Dk6v5ieZ8HhMCUEAK 7jLEuC+0w5SBju4R+MWV/sAoEuzaSYDM/aLgP0K8WeSH/h2kUJZGZy69DvZ/pMpQHX5z +Wag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="U/ETtaOt"; 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 y24-20020a634958000000b004790510bfe5si3753772pgk.692.2023.01.07.01.20.07; Sat, 07 Jan 2023 01:20:20 -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="U/ETtaOt"; 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 S231915AbjAGJT2 (ORCPT + 99 others); Sat, 7 Jan 2023 04:19:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231905AbjAGJSy (ORCPT ); Sat, 7 Jan 2023 04:18:54 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D654B87902; Sat, 7 Jan 2023 01:18:43 -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 844F2B81F74; Sat, 7 Jan 2023 09:18:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9051C433F1; Sat, 7 Jan 2023 09:18:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673083121; bh=Gydwsigs3s+UcKgjKjO+8mlNk6k/2GkoKY1BjgMibbo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U/ETtaOtHHRMupIDCoDQClmyyS1Xhi7LQgTA/ixQVGgyw8c7DHOZtx+gNMx3DDmQ9 xo/N5kdIQXblY+sPnJ5sBRNscHwtKeFIGhMFT4KXlE2Nd9f+nD1erBi9Y36Z6DC8e2 8RkM7W1ZlyFFyuMFNURCGw7VXAXQ9EZQaJ44EOOyUgZCyJbCzWY64HU2IhqnJzuAGx z2uv8RXGSTMB9JNa3J6davMmbPHg+QLczxGW6gIco0M8p/58/y8P1siTuJcj76M3uN m0RuNWtzKjQgLWm8vsT67Vc9XhyowUTj9TitP7fWWyMtmfli9Db/on3obOHHp3q0je gJtnVpU6JFa4A== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , rust-for-linux@vger.kernel.org, Masahiro Yamada , Vincenzo Palazzo , Nathan Chancellor , Nick Desaulniers , Nicolas Schier , Tom Rix , llvm@lists.linux.dev Subject: [PATCH v2 4/7] kbuild: remove sed commands after rustc rules Date: Sat, 7 Jan 2023 18:18:17 +0900 Message-Id: <20230107091820.3382134-4-masahiroy@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230107091820.3382134-1-masahiroy@kernel.org> References: <20230107091820.3382134-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?1754354911316895953?= X-GMAIL-MSGID: =?utf-8?q?1754354911316895953?= 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 --- (no changes since v1) 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 865afb87bc9b..f403b79cae5a 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 @@ -350,8 +349,7 @@ quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L --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 67ef852712d4..a45a97b027d1 100644 --- a/scripts/Makefile.host +++ b/scripts/Makefile.host @@ -145,8 +145,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 Jan 7 09:18:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 40322 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1224034wrt; Sat, 7 Jan 2023 01:19:57 -0800 (PST) X-Google-Smtp-Source: AMrXdXtz7yFHGzt2n8acb5flEvl6NvIgBJkbO1cAIVk4A4Np9iEu8JG921bb1BLWcRPLoWHPtleb X-Received: by 2002:a05:6a20:6699:b0:a7:e65:2b65 with SMTP id o25-20020a056a20669900b000a70e652b65mr65624797pzh.23.1673083197552; Sat, 07 Jan 2023 01:19:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673083197; cv=none; d=google.com; s=arc-20160816; b=Jwq/FQDboikEyNygicOi9xcI0nUDjxeXglH8xtOuQ2C71PdEKz22HM50TnAynOnmWh E1Mof9ALmrzpsou1bex1Q+6kNFcuTm3huACVEqgygNnbzfACRRQ6fEizY5jNU3gA5hBs CdHCAnUWQDbyMWQ4s56Jlh+piEFvXqpi/k9lsJPMTV4AT9Spn66rg8jcaKl9apuYZfqM zgh/czqwY7ftVhaZTmdotq3L5WUqFhIi2816q4dkpMAC8rf0kbTyA6RC70m/ImpWYjNn 5eXDFjROuBy/FEAcG7GMUtCH2mqi+YR1UHEI6yQ9/6pFdgM69QFcQTRX38hcMdTuMeYc a5cg== 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=c8QtFh55HKZ6z/B4W3R9DkJBELx4eHi8lzaai01M7Qs=; b=MsGJFaGQXgeXhCM277KZ7YnewJVpbjmEHJDdCkgY+xD7FNeP7RCTBjFel2gjcKDrYC b8tE4ooV6QeqGmm+mx05QjyO3j2eq0UGnbtvoVVVY41hi3DRLr1d2mYYG1eNVK0XhUc4 pXATsBZzrrVlzZb3UcaWfQZ8iYtv4bGetMWG1Y57/dXgSBwOyTIhxYm/htMcdB7vshNl msc/fi527ZSFUCkIZBV4SIT+xCZvX+uSMX2kEP5oR9guHysxbhS4JZ4wc7oCWIi28SVU Sh2I8hyFZTHQFydkZWJpembnbxwpsS79/SjUuNpZH+8n7lDtb762K2W5M3fDFhj1XXIV wLZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=USGRmCPj; 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 e21-20020a637455000000b004795c10a6c6si3727632pgn.665.2023.01.07.01.19.45; Sat, 07 Jan 2023 01:19:57 -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=USGRmCPj; 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 S231770AbjAGJTW (ORCPT + 99 others); Sat, 7 Jan 2023 04:19:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231748AbjAGJSw (ORCPT ); Sat, 7 Jan 2023 04:18:52 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0A3387F21; Sat, 7 Jan 2023 01:18:46 -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 CD2FD606A0; Sat, 7 Jan 2023 09:18:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12214C433F2; Sat, 7 Jan 2023 09:18:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673083125; bh=KHt1EK26ZGiCZ+hM8+UAROr2DkypHQCMEzGlrsxrzJs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=USGRmCPjYNX6ogQJTnr+bdgvTdiqwjDgydRFPehzZrcxPQrTVeokqOwv+Avf4WktR vFW8sKGqXKrXZaGi++fWsdr7nsu84MdtzoXbGZKylLXPVT9HiDTLo44c86Q7q6zpz2 DpvYAaUDsYSV92YSHwQL095ySj2XQWIRlYhJAwB/tF8Z4uLSW4L3hbbCEVay8AYaao Dol9xUemVNxo70aRvkzGDds2LpbWIVOVH4+4cpHyK5wIq9DNO1MDdH1zsogel1m4IJ xzipdFimzMgUqb42WFYasicdrmUxqYOpwSDDh2JrWUxKUjIe/A9X4rC2+k7WXwXoYb eYSWNNye95KgA== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , rust-for-linux@vger.kernel.org, Masahiro Yamada , Nathan Chancellor , Nick Desaulniers , Nicolas Schier Subject: [PATCH v2 5/7] fixdep: refactor hash table lookup Date: Sat, 7 Jan 2023 18:18:18 +0900 Message-Id: <20230107091820.3382134-5-masahiroy@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230107091820.3382134-1-masahiroy@kernel.org> References: <20230107091820.3382134-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?1754354887043040537?= X-GMAIL-MSGID: =?utf-8?q?1754354887043040537?= 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 --- (no changes since v1) 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 f5a51770eb74..74f90a0deeb9 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 Jan 7 09:18:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 40324 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1224128wrt; Sat, 7 Jan 2023 01:20:21 -0800 (PST) X-Google-Smtp-Source: AMrXdXsNRRoaGs1FjDewASXw+b59O1yIFZnzluTIwRygEHa1t/7XjNQlh4cfRP22I7IhHGIOom4j X-Received: by 2002:a17:902:da86:b0:186:865c:ea17 with SMTP id j6-20020a170902da8600b00186865cea17mr81900177plx.38.1673083220997; Sat, 07 Jan 2023 01:20:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673083220; cv=none; d=google.com; s=arc-20160816; b=YPYLribLcIZRm6KwD+yV5NodGUYw0Pt3UCTbIOXWNdB70NGdbrnr0An0LZoPogQceW kUzfYd1CZn9f0sqYLXRox67d6cQLyuwT8nJC2pzBgiOyEy4eQvkVnb04Uupk0YQ9J19+ KdNyJO8/IPIWvLtjcWmtL7GdNii/yDaHrDQ5xpI9hMaXmG4X7YELdvFwGURKmlL3OspI dOj5r+FpW+QS3iXQTIECL622dn1n+cW6Nk17driG2k2UZWAnHtIrnlP5R3Tmnxrsc/cQ 8KVvlUCa7tznWnrnXGJPiOZ3opk7Oxb3cTtZDwhhgwOKZ25AZaLTp/Y5B3D3G1pDXDnw J0aA== 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=i8QaQpw+KNn8CVATgFyevhog29Udafa4VeKhlcsfiIk=; b=W0uTiMRy/jwbj6hlLgNjGO+d3GwxNpsAcxIEqM9s3V4p+6Gdk3B9R7c/BAvPDzcTWk 0Gariqt7SWNoxqsQvzaVA6UZW3kXeBQQkXlzL4FNrnb6BS35RrbPPblC5Js1yKx0FxWP +Cy3/rtJesV6F9u4e03nMxuEjrM7rdyKQG5U3Qy5zkR+NLNWr+PC83qthGwljCXBDYAw F6pKHtXWrrULnVzXB8LVpuhZQTyegU/7gJKix2QWB9WgHrwh0hEi3jq+VQYr00AriBQj YpAgTga1V3796PuPqvm4MEwbRT9t9X1VEkJKZwRIiNHQsIqNn1mtr2faIUiF720VLZm1 u5Fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eJ8U3AN+; 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 a3-20020a170902900300b0017f791f52c3si3136533plp.88.2023.01.07.01.20.08; Sat, 07 Jan 2023 01:20:20 -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=eJ8U3AN+; 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 S235751AbjAGJTb (ORCPT + 99 others); Sat, 7 Jan 2023 04:19:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232070AbjAGJS6 (ORCPT ); Sat, 7 Jan 2023 04:18:58 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46CD687F36; Sat, 7 Jan 2023 01:18:49 -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 653B960A1F; Sat, 7 Jan 2023 09:18:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B34C2C43392; Sat, 7 Jan 2023 09:18:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673083128; bh=cZp3/f8g3cCc0UPJMUJ/mOB550SUSwktxIGn/lu/TWg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eJ8U3AN+n5hzQC3fHvtMDG/wqdaGph5cgla581EymJqOg9fAhTZyi3A+UT2Rm550z uPzXjzPdf85fEqQFs3DQ8unVm0dh5HqWYUmxEGg/V2AqfMTRznkW6CTe5nhbXrjfw/ 14Qr+bMktdGTaI20vVCcCZr3EVPhxjrsUhbbMFSm9KQwBzOtpld5E83oQOFrsXN2FN wLFAwP3IXq3+2ghWWA7/ceOXpvfHWFa7W2AU659tC3KE8aMn96zM+xVyPKBbF9vfyn DG8ynn+16sv1qWVuHGhDMNpCQoi9czA+fNYjAqJR+1XWgeIe+HGJMeowFgiLlC6xk7 GYQ+2LFQ574HQ== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , rust-for-linux@vger.kernel.org, Masahiro Yamada , Vincenzo Palazzo , Nathan Chancellor , Nick Desaulniers , Nicolas Schier Subject: [PATCH v2 6/7] fixdep: avoid parsing the same file over again Date: Sat, 7 Jan 2023 18:18:19 +0900 Message-Id: <20230107091820.3382134-6-masahiroy@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230107091820.3382134-1-masahiroy@kernel.org> References: <20230107091820.3382134-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?1754354911228550123?= X-GMAIL-MSGID: =?utf-8?q?1754354911228550123?= The dep files (*.d files) emitted by C compilers usually contain the deduplicated list of included files. One exceptional case is when a header is included by the -include command line option, and also by #include directive. For example, the top Makefile adds the command line option, "-include $(srctree)/include/linux/kconfig.h". You do not need to include in every source file. In fact, include/linux/kconfig.h is listed twice in many .*.cmd files due to include/linux/xarray.h having "#include ". 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 --- (no changes since v1) 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 74f90a0deeb9..e22e689de61e 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) { @@ -365,6 +365,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; @@ -372,7 +376,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 Jan 7 09:18:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 40325 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1224344wrt; Sat, 7 Jan 2023 01:21:08 -0800 (PST) X-Google-Smtp-Source: AMrXdXvveaqIT/dr77mWdTfEP1zxakHarpPLI0L7IHaH1t3B0NdeQ1hv7gVkIq0u+wBW8K4Hx8n/ X-Received: by 2002:a17:903:41cf:b0:192:a69d:11f7 with SMTP id u15-20020a17090341cf00b00192a69d11f7mr41342974ple.27.1673083268239; Sat, 07 Jan 2023 01:21:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673083268; cv=none; d=google.com; s=arc-20160816; b=L84BwlT/A36d2+HT8HluD7h5Y5JPYPgaBCigTc5Wp3IRCdhs/fWiaQPwXPIpDU/X3X tlY3IQEstj5rOLuYMbNiGaqgr+TV+dqekYiKaa6NdqApv0QuOF2PlzqnSAdB9JMQRkNs humAZfsH0Xn1r55/We3JaPucFhU5NuNZfc6U34t49HYyZvK8nhRY/XDeweNJCcAtI0Gf GOMuSrYT8b7X3z2taumimoT5synoXteQv6gCR0wxpG9XkwpknUe4qcokK0ST70YrLd3M T6LiaLAHAe1h+ulpFQkHMaBklvX5dlPqXuRR/4jN8tCK1oCI2M3zYPrnGaIctE5hWVOa kvOg== 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=9/weooVElI7qYIc3lQHhjS5VFoGYLqQ1OIDgBdezcyE=; b=VgGWWVV6RH9gTe5S60jreI+Hdu13gQ+YNmLxq6xkgc/sGwWL7dml1GoNAw9spQWYTH wcoyd1Rgg06vYVpG6ZYytcRvqmQIJBKbvmyMKNjHAeifKvZ2VRM3MAMqXwkuG7+u8JRI fO5NHC80BC9mNVG1XJXZqrY9n7URxVx8rWaSyetbWm5DEHE+jhBJ3XiVgbUunY8+70sa Dq9nGti3YRFQsqttPk1NVo1V8d2imsAwD1E9U7vWXAS+duLCTvf4g+8AH/npW8ypVE/c kPPYdcScSK5Lv4D8XSZJzBC4vRnPtdr9+H+EVH3KZg0pX/sam+cVHubU8Q/GRTslS63x 3Xnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="W1/C1SDC"; 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 z17-20020a170902d55100b001897545cb86si3496041plf.76.2023.01.07.01.20.55; Sat, 07 Jan 2023 01:21:08 -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="W1/C1SDC"; 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 S236751AbjAGJTg (ORCPT + 99 others); Sat, 7 Jan 2023 04:19:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236444AbjAGJTD (ORCPT ); Sat, 7 Jan 2023 04:19:03 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0736872B6; Sat, 7 Jan 2023 01:18:53 -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 5CEFC6090C; Sat, 7 Jan 2023 09:18:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C345C433EF; Sat, 7 Jan 2023 09:18:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673083132; bh=HDunvAi4h/6vbPRGpgqV3uOp71+s45kzLihxASdER6k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W1/C1SDC7NEjkzK2S71h54G7aOxc8q6IPPHLAda71lSvw44xzbVWUe7EGjQNB+eI8 pbMmD9fNrbItRnBLyKZcJeLRyleV8hCJYM0O6fcYvuyvb+ad5vl0r/S7nOzs/feQiB h4Q8LGa1tHQ5nSVPyaoEfQuAzd6daToA4Fi4BDnSvlSD3i71a6cjw1tvV9x8HG1lPS Yyfuo4KAHhPDY4upAhA0rQ/t7IlJ47HdDrZ1pyVt4w9EoqgsHo1Mrz2qJ4sPXYGZju JSres/MKNjUUZkE6lwV6dPB2Tu8vt5aEoO/xQzSObiu5NzWloGAHqTh129pAJZtRYs DHX6rCD+a/U4Q== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , rust-for-linux@vger.kernel.org, Masahiro Yamada , Nathan Chancellor , Nick Desaulniers , Nicolas Schier Subject: [PATCH v2 7/7] fixdep: do not parse *.rlib, *.rmeta, *.so Date: Sat, 7 Jan 2023 18:18:20 +0900 Message-Id: <20230107091820.3382134-7-masahiroy@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230107091820.3382134-1-masahiroy@kernel.org> References: <20230107091820.3382134-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?1754354961341718880?= X-GMAIL-MSGID: =?utf-8?q?1754354961341718880?= 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 *.rlib, *.rmeta, *.so to dep-info. fixdep needs them in the dependency, but there is no point in parsing such binary files. Signed-off-by: Masahiro Yamada Reviewed-by: Miguel Ojeda Tested-by: Miguel Ojeda --- (no changes since v1) 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 e22e689de61e..3a61b037d5ba 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 @@ -382,7 +391,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);