Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp8263rdb; Thu, 5 Oct 2023 14:41:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IENXl/NrNp0COZcZkU635NxqJepS7lkFix98X4vrHkwd2/EOkkN5IS+GmnQlSZkL0Iem/z+ X-Received: by 2002:a17:902:9a44:b0:1c3:f4fa:b1a2 with SMTP id x4-20020a1709029a4400b001c3f4fab1a2mr6308107plv.8.1696542076645; Thu, 05 Oct 2023 14:41:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696542076; cv=none; d=google.com; s=arc-20160816; b=P+s46v07ivzH5h6jUV9HM0rTkNziZjBcE3E5f3kndl0x2tIa/VW2J9j0FUDj77Y2dA 9mKOi1obpLXZnqXVKy6rLX9Y8ZwRqlRnX5VcVp/51j1m8tTYVgPg4vXQxG/4g/5EZ259 vJcbl1Am3x4w9Kvl6LLJ+4TjaErVlHZIjujJBe4jf8bg5Djxu9h0LzIsLAf6ST3py6gu lrskRsGNfc0PV6jxUkbdzO2rPcTxP41CeigoOJSArslA3xtCTAeDdTGorfUz/4LyWj1V cmV78CSjyKcK6B+ggQOgvFcwZ0ZC9pb4pW6uJznMWxawdR4LoTYnG8kT7OcGwWBM0l2D YkRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=g+0XZ4668oG273eR0HIMNtDUIA8UJt38oxH6S2htmGo=; fh=p/kVLEESGzH6sPIvxgV/1//DeAFbRdOvZT/SsutZCWY=; b=m9m7NKvGzpTnmUVINb7rzlhCI+ie3LbHUkfpk5n3g4ieTyV42Bie62PSwVwyq9K4lF 5YlI7M5CvrrhysItYRhuoGvT2q+bFhhoyzQ2rdEZ5heOBQChvPjewD2MQxmF5MEjBceX xOpQgrUeZe1eOWX+RQz4NXsVTRePQytchAR5J8Nqd7K41zKEn3jt4NFg+Ku85IUP/z9A lwCFbax7H3fzEpXQnDi/ia6PrBU38wT2TdGHApVyTU70K5UwHKL6wMTW9iBysiZAKK// diXovf48MJ7qPxXOsBg/UMQ1fvvOBPDG9eHkZ9yMTQ2wsZa9Fz6izJgzpfAwgDSxjpUz QmkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="Cja/+lgh"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id i13-20020a17090332cd00b001c7249f5e40si2376255plr.469.2023.10.05.14.41.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 14:41:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="Cja/+lgh"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 448D38082CC6; Thu, 5 Oct 2023 14:41:14 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229750AbjJEVlE (ORCPT + 99 others); Thu, 5 Oct 2023 17:41:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229509AbjJEVlD (ORCPT ); Thu, 5 Oct 2023 17:41:03 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17EF595 for ; Thu, 5 Oct 2023 14:41:01 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-59f4f2a9ef0so21532637b3.2 for ; Thu, 05 Oct 2023 14:41:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696542060; x=1697146860; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=g+0XZ4668oG273eR0HIMNtDUIA8UJt38oxH6S2htmGo=; b=Cja/+lghjgljbAErxlP3BwLDI3j+J2IQ5EaQVZLFZTzPtuK/hqe/R4s6xAmcLSSZ60 qXaObCUB1yhjb1TOV0y3ffYAf0VlUkSAQfVARA6mAW0Vjn/M3NNPMHVQZ8w7VN2MZ+7Z wL+n0gn5ESfb+8iiYviiQtWuOdOXtDQlaNh9MLNJ7oYvkefrrPI6EPz1TO38SaN62RDC QGauHu8fIXek1KI26CWv1OlZ+yGwecMTMMD9oilwn0cEXNrWlz8esK3JAUdk/F9W/zVo x9mm6lwbLoR/f3OVZFNvXFRyPYO45I3tAzBs3u/W6dsH8DPBFMuqMqPLGwsIaNFuPbsT HkTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696542060; x=1697146860; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=g+0XZ4668oG273eR0HIMNtDUIA8UJt38oxH6S2htmGo=; b=ELhK/K9M88z0RUnSNLCr0hwSQJTFoVfUQGpJ5hmoZ34mS8gMvVEzhVLZgz9lMs2sS5 w6G24uBRd9w7Xkg5mMtID4h3efZPsJqmLTT1OWC/LmLFcPda9KzsUPrlXwGZP9alBqFF ZWCFp+gnVnZ2FfcadzLLCfqlHTrZWrWLqMcg5lzqSwwhUxHSMoQfwn6QhEvk41nVhEP7 jJsELEGZ9tfTSksfvQuKfZ/nqOd+3QchuANu+s58cN9sw2uup89Wb4i6xKxkNe1X9W5t 42BQ06IQchAgJIUJLew6/4M5chmbfWYd/M8x8n7XnhpZt6ahCwmVsNUUCvNtbW+5/I9o WRZw== X-Gm-Message-State: AOJu0YzChSk4xYYFQJ7ckGri1DAAj6gPsCfkuyCORbQK7EbZn+lHnJEC Td2ZrPBu5tx2VUNhYFZPy8apkQ2uizDe X-Received: from anyblade.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:1791]) (user=mmaurer job=sendgmr) by 2002:a81:bc47:0:b0:57a:118a:f31 with SMTP id b7-20020a81bc47000000b0057a118a0f31mr112123ywl.7.1696542060316; Thu, 05 Oct 2023 14:41:00 -0700 (PDT) Date: Thu, 5 Oct 2023 21:39:58 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.609.gbb76f46606-goog Message-ID: <20231005214057.759089-1-mmaurer@google.com> Subject: [PATCH v4] rust: Respect HOSTCC when linking for host From: Matthew Maurer To: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Masahiro Yamada , Nathan Chancellor , Nick Desaulniers Cc: Matthew Maurer , Boqun Feng , Gary Guo , "=?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?=" , Benno Lossin , Andreas Hindborg , Alice Ryhl , Nicolas Schier , Tom Rix , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, llvm@lists.linux.dev Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 05 Oct 2023 14:41:14 -0700 (PDT) Currently, rustc defaults to invoking `cc`, even if `HOSTCC` is defined, resulting in build failures in hermetic environments where `cc` does not exist. This includes both hostprogs and proc-macros. Since we are setting the linker to `HOSTCC`, we set the linker flavor to `gcc` explicitly. The linker-flavor selects both which linker to search for if the linker is unset, and which kind of linker flags to pass. Without this flag, `rustc` would attempt to determine which flags to pass based on the name of the binary passed as `HOSTCC`. `gcc` is the name of the linker-flavor used by `rustc` for all C compilers, including both `gcc` and `clang`. Signed-off-by: Matthew Maurer --- Edited to use escsq in both Makefiles, as per Masahiro Yamada's suggestion. rust/Makefile | 2 ++ scripts/Makefile.host | 2 ++ 2 files changed, 4 insertions(+) diff --git a/rust/Makefile b/rust/Makefile index 87958e864be0..2ddd821d9435 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -383,6 +383,8 @@ $(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) \ + -Clinker-flavor=gcc -Clinker=$(HOSTCC) \ + -Clink-args='$(call escsq,$(KBUILD_HOSTLDFLAGS))' \ --emit=dep-info=$(depfile) --emit=link=$@ --extern proc_macro \ --crate-type proc-macro \ --crate-name $(patsubst lib%.so,%,$(notdir $@)) $< diff --git a/scripts/Makefile.host b/scripts/Makefile.host index 8f7f842b54f9..08d83d9db31a 100644 --- a/scripts/Makefile.host +++ b/scripts/Makefile.host @@ -91,6 +91,8 @@ hostcxx_flags = -Wp,-MMD,$(depfile) \ # current working directory, which may be not accessible in the out-of-tree # modules case. hostrust_flags = --out-dir $(dir $@) --emit=dep-info=$(depfile) \ + -Clinker-flavor=gcc -Clinker=$(HOSTCC) \ + -Clink-args='$(call escsq,$(KBUILD_HOSTLDFLAGS))' \ $(KBUILD_HOSTRUSTFLAGS) $(HOST_EXTRARUSTFLAGS) \ $(HOSTRUSTFLAGS_$(target-stem)) -- 2.42.0.609.gbb76f46606-goog