Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3578480rdh; Thu, 28 Sep 2023 16:40:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGd0SCtdjTPr3ZqhQfEWg3CxkmSOG7LU3OFRW4XRzx3oUqqB/AT9X9ELR3x7npUlU1KE7YI X-Received: by 2002:a05:6358:e49f:b0:142:d097:3725 with SMTP id by31-20020a056358e49f00b00142d0973725mr2946278rwb.9.1695944435423; Thu, 28 Sep 2023 16:40:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695944435; cv=none; d=google.com; s=arc-20160816; b=KOMw0BoNSz6aNxYQGt8DD5aJEyo3ZjUbp9pntvn/v3iF4ZEWTbBzEqW8JpwnAimv7r SPQeleIonJ5mbySoo+FbkHXYBxKHT22TZUPfLNXC/NVf/Ut64SMtonqHHtklDRMI03ul mnATM3TQhrzbBak9KIy+Hb3bcLbcUfZLGUBgzmm1Fayc1JdvMIJ9WE2lJHwFh4OxSHEk q9Ezjym+hzUzoaFuC1TCfY7aQVa+a7aaYue/IWgNRuGBxpGG9j+Tg3tZ4cPlv/bIKmWz A9i7yrV42A1/3Q4HQxyb5sbqZXmOawT2esePx0llVFdY5fJEMm4ufqUsz25OvEf6Ktuy QVDg== 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=8iFw0tvjrP+bKthnM1Ar6RitIykCJfydYWlbU6QKJSo=; fh=p/kVLEESGzH6sPIvxgV/1//DeAFbRdOvZT/SsutZCWY=; b=HPG1znR2aJzavdvR1TvEfpdeeLjalzzXlSjwyJ0YUNTAfMFyscN61y8hCGr6oYh1Bn tK4HaCCrEQhVOoyOXZYT9FQ8D7JyMBV3imNXpMKrTvIlBNSuS2UEjoH6KxXGOqR5/JWt fvRLm1s6z9690VZVtWVXARI5PfcvVXXlrb22IrHMGC64585eEjmyNjWdK9HDqBdm4Urh INx8UOPSWCY3p+pYQbBrzzkqoUxzQmwk1wiBD2JnYYb3t28hbGakVV7bCNjE+Y95i/BY kzaHjzBh/hLhrh4t45vSBoV+mMoHD826wXnU1t4EJHU47VuTjGvlbWLf714b62s1V2w/ rG1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="d/ucrjuX"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id v10-20020a63610a000000b0057c7341d562si18069078pgb.70.2023.09.28.16.40.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 16:40:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="d/ucrjuX"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id EBA978314419; Thu, 28 Sep 2023 12:48:30 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232046AbjI1TsN (ORCPT + 99 others); Thu, 28 Sep 2023 15:48:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230251AbjI1TsM (ORCPT ); Thu, 28 Sep 2023 15:48:12 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EA1E1A1 for ; Thu, 28 Sep 2023 12:48:10 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-59bdb9fe821so261506637b3.0 for ; Thu, 28 Sep 2023 12:48:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695930489; x=1696535289; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=8iFw0tvjrP+bKthnM1Ar6RitIykCJfydYWlbU6QKJSo=; b=d/ucrjuXJ2acKPT9XyrckOG9VoH40jdz8VyKFE7DQXm2BED4MRhVmA2So4637mpIeb xkrOHP2k0Cl1rBg8EO6FsWtuNo8jp/D0f8/dUuvdQACV7IRF2yCgsslE3aAmjPnVwqnC 5F5RhgoQT3hBr4pPQpPudmqNfnY3xCgUYPo2f7zK6tvfLKxQaDcqYwtQh/CUmq+vke4F V4KY7H5Xh7kCf2LpE3ANnCpTDdEAEQBHsrKlE+L8X4NXYt4kOr2iGy54wxX9oEwftqtt s8RqlnxQqt4lHkirnVXAtmo+iok4JQqf84L4UITpyK3RJukCQZd7GDIYdJHmCHMibs6I rlxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695930489; x=1696535289; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=8iFw0tvjrP+bKthnM1Ar6RitIykCJfydYWlbU6QKJSo=; b=kDAGo1G+sJV7ZTUgIpzzWhsuBYgULyMencpfzE8nKQK2h9FwxYX6gw98QkoyGqaNUd jeguvMyL83VBm17VkS03/S3HT0x4+8qG0uFNyvWMnfyX8QmmUok/tMq6C+8/ufY2PtYj nl0Y34uZ5puD/GtgVLp2eC09Y5vBt+ynWFwuVi9U+VB4nz60lXaABV6q4BTKtQfLhpCi mGeOMvTLuFwdj6wE75u8W4rTnyeQx38Ej74inMzz9GbnLbWnKQZV2hmJdhKvhfDvny/l hyKJgXqrWcaPMiGAloENWDMuoS+WFApnaFCR3KxAJKTQahQu120ikHQxp+mKC1IPWb5+ gaoQ== X-Gm-Message-State: AOJu0YxzEFb4y9gGFuB6M2V7KLzotb2x/OTmYQHPJPgnfEZK812lDfFc RfYocsyK7T4D3ofPR6FcZv7flei5T4WK X-Received: from anyblade.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:1791]) (user=mmaurer job=sendgmr) by 2002:a81:440d:0:b0:59b:ebe0:9fd3 with SMTP id r13-20020a81440d000000b0059bebe09fd3mr29132ywa.7.1695930489339; Thu, 28 Sep 2023 12:48:09 -0700 (PDT) Date: Thu, 28 Sep 2023 19:48:01 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.582.g8ccd20d70d-goog Message-ID: <20230928194801.2278999-1-mmaurer@google.com> Subject: [PATCH v3] 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 groat.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 (groat.vger.email [0.0.0.0]); Thu, 28 Sep 2023 12:48:31 -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 --- rust/Makefile | 2 ++ scripts/Makefile.host | 2 ++ 2 files changed, 4 insertions(+) diff --git a/rust/Makefile b/rust/Makefile index 87958e864be0..da664d7aed51 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='$(subst ','\'',$(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.582.g8ccd20d70d-goog