Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp892773iog; Fri, 17 Jun 2022 16:42:19 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s2mVTl2ztB6Y0mhodFhBstP2bjijR4P9iEOFWutBggdzHaCx1OBMmMEmHmq41ABL74JmO/ X-Received: by 2002:a17:906:b795:b0:70d:8e9:f4d2 with SMTP id dt21-20020a170906b79500b0070d08e9f4d2mr11783494ejb.188.1655509339562; Fri, 17 Jun 2022 16:42:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655509339; cv=none; d=google.com; s=arc-20160816; b=wMiFqfXqqyfAaVu+13J6gHU5MLuIfkdmNUa/vzj9CZufbLI30jhAyrYDmVAcRVbiHb IP77UnY1eV9ZdKWjyQgzvhIeqo/a5TNVVgCaIAA1mY3aI4Ev0XIN7iGkfyp0KzmEBJA8 wUk8IiXt5ynAgv5kRnDlVgGe621A8gmRdPBH6cOo02BtZCEIHcgYONTz5DGe3Ugtsnhd F20ZDw29VLmdaC3WhXQty2ExzD9XZswayPXiyl50JEcRpyoSb3DQAvYfxfdSZufGNqu+ gnCI9G5DnERs263n32K/8SSBVy2kOA2PTgMmNHYg84fZOvGEmQ2qgtiQExQwlwQmCnbY Ft6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=EXgpKpIVzT6qnZVCgCn3/+ZdUQI+LHK0/bEVe7Lb4mY=; b=tketDE7whBZ5uHKj4QHOYbc63oZPzLtIcA6tXWlQvTCyQkWjIUJjTawsYCK3XOb9dM NOianxBWfiCOSVOPwwZIkch0txAQiVqz1XBe+yZ0NW13DQyloxxcW9QZspN+rpuvC5+t yR4TjVhI/CsXeusIC6AWMkF8ivTOVE3N+yS3/0SzhD3Rxm9WlsOP2zVtI4eaY4OPQ5oj zrBNdq0RxwIFvYCakcRKYITtk3dwHYZhKTaWiyWC9IsGS7goH6It060suz/j8zR7du1w UtjQqxXh6SibapdnZx9TNr0Mf5UQZmt2CeVaIFjZ0StdoqsmA8kg/2+4rl1lBUL89pb2 WVUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=hldD5704; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hd33-20020a17090796a100b006fe8c58b721si7040051ejc.881.2022.06.17.16.41.55; Fri, 17 Jun 2022 16:42:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=hldD5704; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383685AbiFQX0T (ORCPT + 99 others); Fri, 17 Jun 2022 19:26:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383500AbiFQX0R (ORCPT ); Fri, 17 Jun 2022 19:26:17 -0400 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3427C663F4 for ; Fri, 17 Jun 2022 16:26:16 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id i29so9011514lfp.3 for ; Fri, 17 Jun 2022 16:26:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=EXgpKpIVzT6qnZVCgCn3/+ZdUQI+LHK0/bEVe7Lb4mY=; b=hldD5704PosVIx7pUYS/I5Fkd39xNzHxffHQ4mZN1Dqeeuu2C4pwCxAQJNgtGLYwk9 w7FJIcrUIRSS7x7h7nxefPG9ErzMKZMCYjFXnwB6jDP9vW9l7w3v44r21dvY+UO/roaH DuoO8nTSDMIPRijv/rUkB+5O/ifpxQW5EsEk/kcxRq9igUh8BEY3NEIxapGHRXPEivrV mEubtXEvlefXACss71A3Yow9/ml9N4sTH4bxhcrDrh4VpAU+l17QlhYYZuNW98vzP9tg nWdM5nclxBc/2bwkBpTMkpG+KU30Q0CgYJD/wbMLZRWwW2OIMr9AzbNDc9dxSlEJaxPO Zx/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=EXgpKpIVzT6qnZVCgCn3/+ZdUQI+LHK0/bEVe7Lb4mY=; b=UaDvSB5kCCV49FSs6LZLz8cDlG4cpYTKFFr8G1zVRlMRjTb4Il5Bcl/HDpWXlE7miu +MV6Eca/9lG3pTmA6lDqrLuhPvlzhtVZWQGNJOql3We0b/DRztAOhWSBR88kPt87w6Rm tR3ZFGXOw5F6pXEnFFjz983m8bsIR1zXQydMYJCCYZvvWgyHq+S6hT4jdbBmjUoJp9nE Xgn/0I8h+LYNocZxtY4/czT4WQHfkYC2c0xZSfoGwFNh9Cgn0Q+dBqeldoboVRJmBtve M6zR2YMOdSGhHKm4ozQXIaBZV50Vj6xM0G4z9njRDuQxCnxpFOaAvaFmQ3OiJbgz8lR5 kiog== X-Gm-Message-State: AJIora8hnM/k562TKiGtdYwkuX1rygsc5Vp9UmVHSM+E1+GEGUebTgGd gu1EnKPhuwvWMK91TLNdOCGAxDrGVjHkfHrgB/H5vA== X-Received: by 2002:a05:6512:3f9f:b0:47d:c87e:f8f3 with SMTP id x31-20020a0565123f9f00b0047dc87ef8f3mr7012832lfa.401.1655508374233; Fri, 17 Jun 2022 16:26:14 -0700 (PDT) MIME-Version: 1.0 References: <20220617203948.3714905-1-ndesaulniers@google.com> In-Reply-To: From: Nick Desaulniers Date: Fri, 17 Jun 2022 16:26:02 -0700 Message-ID: Subject: Re: [PATCH] scripts/Makefile.clang: set --target for host based on make -v To: Nathan Chancellor Cc: Masahiro Yamada , Michal Marek , Tom Rix , Linux Kbuild mailing list , LKML , clang-built-linux Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 On Fri, Jun 17, 2022 at 4:21 PM Nathan Chancellor wrote: > > On Fri, Jun 17, 2022 at 01:39:48PM -0700, Nick Desaulniers wrote: > > We're working on providing statically linked images of clang to host on > > kernel.org. We're building them in Alpine Linux based Docker containers, > > which are MUSL based systems. > > > > In order to keep bootstrapping simpler, I'd like for them to have an > > implicit default --target of x86_64-alpine-linux-musl (set via LLVM's > > cmake variable LLVM_DEFAULT_TARGET_TRIPLE). > > > > Similarly, if one were to use a different build of clang meant for a > > glibc or bionic based system on a MUSL based host, we'd prefer to use > > the correct MUSL based triple for target hosts. > > > > Borrowed from the Zen of Python: Explicit is better than implicit. Let's > > be explicit about the target triple for HOSTCC when building with > > HOSTCC=clang or LLVM=1. > > > > Signed-off-by: Nick Desaulniers > > I have tested this with a few different distributions on both aarch64 > and x86_64: > > Reviewed-by: Nathan Chancellor > Tested-by: Nathan Chancellor > > One small comment below. > > > --- > > Makefile | 3 +-- > > scripts/Makefile.clang | 10 ++++++++++ > > 2 files changed, 11 insertions(+), 2 deletions(-) > > > > diff --git a/Makefile b/Makefile > > index 1a6678d817bd..87712d9b043c 100644 > > --- a/Makefile > > +++ b/Makefile > > @@ -600,10 +600,9 @@ endif > > # CC_VERSION_TEXT is referenced from Kconfig (so it needs export), > > # and from include/config/auto.conf.cmd to detect the compiler upgrade. > > CC_VERSION_TEXT = $(subst $(pound),,$(shell LC_ALL=C $(CC) --version 2>/dev/null | head -n 1)) > > +HOSTCC_VERSION_TEXT = $(subst $(pound),,$(shell LC_ALL=C $(HOSTCC) --version 2>/dev/null | head -n 1)) > > > > -ifneq ($(findstring clang,$(CC_VERSION_TEXT)),) > > include $(srctree)/scripts/Makefile.clang > > -endif > > > > # Include this also for config targets because some architectures need > > # cc-cross-prefix to determine CROSS_COMPILE. > > diff --git a/scripts/Makefile.clang b/scripts/Makefile.clang > > index 87285b76adb2..a4505cd62d7b 100644 > > --- a/scripts/Makefile.clang > > +++ b/scripts/Makefile.clang > > @@ -1,3 +1,4 @@ > > +ifneq ($(findstring clang,$(CC_VERSION_TEXT)),) > > # Individual arch/{arch}/Makefiles should use -EL/-EB to set intended > > # endianness and -m32/-m64 to set word size based on Kconfigs instead of > > # relying on the target triple. > > @@ -39,3 +40,12 @@ CLANG_FLAGS += -Werror=ignored-optimization-argument > > KBUILD_CFLAGS += $(CLANG_FLAGS) > > KBUILD_AFLAGS += $(CLANG_FLAGS) > > export CLANG_FLAGS > > +endif > > + > > +# If HOSTCC is clang, set the host target triple explicitly; do not rely on > > +# implicit defaults. > > +ifneq ($(findstring clang,$(HOSTCC_VERSION_TEXT)),) > > +HOST_TRIPLE := --target=$(shell make --version | head -n2 | tail -n1 | cut -d ' ' -f 3) > > Should we use $(MAKE) instead of make here? I guess the only case where oh! yeah, good call. I think so. Will wait until next Tuesday (Juneteenth holiday in the US on Monday) to send a v2. Thanks for taking a look! > it would matter is if someone was calling make via an explicit path and > did not have it available in their PATH so maybe it is not worth > worrying about. > > > +KBUILD_HOSTCFLAGS += $(HOST_TRIPLE) > > +KBUILD_HOSTLDFLAGS += $(HOST_TRIPLE) > > +endif > > > > base-commit: 79fe0f863f920c5fcf9dea61676742f813f0b7a6 > > -- > > 2.36.1.476.g0c4daa206d-goog > > > > -- Thanks, ~Nick Desaulniers