Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1136606pxm; Thu, 3 Mar 2022 11:01:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJx9KG9yjf7KpuflDJCrTT4Nff+cIuGmjmsaYgqVpQmJSS3lpYbL0CfDcS5rHU/7p0wVx6Xt X-Received: by 2002:a17:906:407:b0:6cd:472b:2d5f with SMTP id d7-20020a170906040700b006cd472b2d5fmr27331030eja.573.1646334104571; Thu, 03 Mar 2022 11:01:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646334104; cv=none; d=google.com; s=arc-20160816; b=Wfc/sysw+EiFaj5U+lDxwfNpgSSkoXnAmLn0X41NZ8YL28hNQS1SQJbZIVu++wfKXD 5DlXNbaPWs9HgePVkHuHqLMVaQM9aPyinJrGTCErcImyKlud7gNLH6LbiyHUaE5Q7x42 qB0Y4D9qMp/rZqHeG5MpakR0gi4vFg2mzf8sZru3rJGfHbOX0J9ot91oKgwIq85j42CV kVXauSYW6y8bMH+RtN8TpT1kEJkLEyWmWYVnafg+f1dHJ34LOvb5lvqXQ0mGVYrPk7w7 b9vXcLDv7t+zt5IcSdWC8HbIpthGw/1dHp7lPMoFIR9rgfuaTNu2I+sdC6gsk45TZWhG 5yZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ohbn/bPviM+Tn+8s9bW5yJzK3RtPWtRGdwqb7XZ19L4=; b=0FPBQkajSjrW9EkHOVe0QLA1dJ1WyC3Pf+ToyvesG4g5t2OqVvlnEgofjKDZaXchSz lSE5GoIsKYdK4j+aaUIcIlhL9ktVUg2LTCNfnKkD69EA6O/ZDX6xHVzTtNr0vKx7/Lhl xFQRbxLGNuJ7z3hJMIdM92/98oktoCP2dgnPLfSbqHFhU5Vl3bmQOp/kwSahlvlSYBbd U0+oysAXDej3P/C6iOtK/J61xvmZBDWLRrdNxanK015kw9eM+A3/Zxyg58fCt2SCzULr HbDRzESt7Gv7pA9rySq1zjmn3CAHWLoOGylZOtZDP6H7OeUiYj+PjRjmW5jyseasBvZ7 /P9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=fYI3KNOp; 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=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nb32-20020a1709071ca000b006d8795e1fffsi2114088ejc.548.2022.03.03.11.00.56; Thu, 03 Mar 2022 11:01:44 -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=@chromium.org header.s=google header.b=fYI3KNOp; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231256AbiCCSFV (ORCPT + 99 others); Thu, 3 Mar 2022 13:05:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230342AbiCCSFR (ORCPT ); Thu, 3 Mar 2022 13:05:17 -0500 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70D2415A23D for ; Thu, 3 Mar 2022 10:04:30 -0800 (PST) Received: by mail-pl1-x634.google.com with SMTP id s1so5261178plg.12 for ; Thu, 03 Mar 2022 10:04:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=ohbn/bPviM+Tn+8s9bW5yJzK3RtPWtRGdwqb7XZ19L4=; b=fYI3KNOpEKTXvpyCy3jCS2z+jaUVpXtgvjgEgAdk8FMI22Cg6u/XNKbhtN0HvFfYFm x9P6oFBQLx3A9RVSKEJVMFyI0zWPw7TUDUqVQiTBk1hwqx089hMWSRVZhqCDlZeH4/8R ist44ayWIh7Yb4m/Z1f26HDstQYgLpqBnwFPw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=ohbn/bPviM+Tn+8s9bW5yJzK3RtPWtRGdwqb7XZ19L4=; b=AJuhcERNsEsbBkc1ZIb/fapN8rypa3pp1HcWNlc8SUcXsK3sLDFIjRwbJNCua+nudW //rl8ngYVgnjKyJ4F4B0cgLIKQpo2+PtM6R44mXyjy4pzCNl9JuX6uTEItUnq65sNJkB GkRGEll0doZDwvrjZeAxL1x//WIjkoSTS9oJBpd6SLQGr9MB8I7FniqbfoUP7NitRuyT zuIM8q9EObhE3z1dIscf1y3/r92eVni/LS+tXbMRAWLvdX6V+LYzKywAIhkbDjalwrOX 4Gg5R5HKRMoWCb3DusJXm1nHkRTeo1+ayVHZiNjbjyWy82gies01/iTnuDOvFsWlvjhO YrAA== X-Gm-Message-State: AOAM5302vmBgTAX7nkRGfN0t2wf+ZEympiOJ2duwc4rZnav+FlADYi27 S20U+obK6mgPQQsF9WNq0ez3Xw== X-Received: by 2002:a17:902:e812:b0:14f:40ad:befa with SMTP id u18-20020a170902e81200b0014f40adbefamr36437378plg.172.1646330669843; Thu, 03 Mar 2022 10:04:29 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id 16-20020a056a00073000b004dfe2217090sm3226384pfm.200.2022.03.03.10.04.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Mar 2022 10:04:29 -0800 (PST) Date: Thu, 3 Mar 2022 10:04:28 -0800 From: Kees Cook To: Nathan Chancellor Cc: David Gow , Jeff Dike , Richard Weinberger , Anton Ivanov , Masahiro Yamada , Nick Desaulniers , linux-um@lists.infradead.org, linux-kbuild@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, llvm@lists.linux.dev, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] um: clang: Strip out -mno-global-merge from USER_CFLAGS Message-ID: <202203030947.E2FA3D9@keescook> References: <20220303090643.241747-1-davidgow@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Thu, Mar 03, 2022 at 10:30:47AM -0700, Nathan Chancellor wrote: > Hi David, > > On Thu, Mar 03, 2022 at 05:06:42PM +0800, David Gow wrote: > > The things built with USER_CFLAGS don't seem to recognise it as a > > compiler option, and print a warning: > > clang: warning: argument unused during compilation: '-mno-global-merge' [-Wunused-command-line-argument] > > > > Fixes: 744814d2fa ("um: Allow builds with Clang") > > Signed-off-by: David Gow > > --- > > > > This warning shows up after merging: > > https://lore.kernel.org/lkml/20220227184517.504931-6-keescook@chromium.org/ > > > > I'm not 100% sure why this is necessary, but it does seem to work. All > > the attempts to get rid of -mno-global-merge entirely have been met with > > skepticism, but I'm guessing that it's not a problem for just the UML > > "user" files, as they shouldn't(?) interact too much with modules. > > Thank you for the patch! I think it is correct, as this flag only works > for AArch64 and ARM, as it is only used in Clang::AddAArch64TargetArgs() > and Clang::AddARMTargetArgs() in clang/lib/Driver/ToolChains/Clang.cpp, > which are obviously never called with UML. I am not sure why we do not > see warning during regular kernel builds, maybe something about how UML > objects are compiled exposes this? Yeah, I got really turned around when I tried to find this last week. > > Regardless, I would definitely like to clean up this instance of the > warning because I would like to make this warning a hard error so that > we do not get cryptic cc-option failures: > > https://github.com/ClangBuiltLinux/linux/issues/1587 > > Reviewed-by: Nathan Chancellor > > One small comment below. > > > arch/um/Makefile | 4 ++++ > > 1 file changed, 4 insertions(+) > > > > diff --git a/arch/um/Makefile b/arch/um/Makefile > > index f2fe63bfd819..320b09cd513c 100644 > > --- a/arch/um/Makefile > > +++ b/arch/um/Makefile > > @@ -75,6 +75,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -I%,,$(KBUILD_CFLAGS))) \ > > -D_FILE_OFFSET_BITS=64 -idirafter $(srctree)/include \ > > -idirafter $(objtree)/include -D__KERNEL__ -D__UM_HOST__ > > > > +ifdef CONFIG_CC_IS_CLANG > > Is this ifdef needed? > > > +USER_CFLAGS := $(patsubst -mno-global-merge,,$(USER_CFLAGS)) > > +endif How does -mno-global-merge get KBUILD_CFLAGS in the first place? If it's arm/arm64 only, shouldn't that get relocated to those architectures? *time travel* found it: 61163efae020 ("kbuild: LLVMLinux: Add Kbuild support for building kernel with Clang") So I think this may have been universally true long ago, and now only arm/arm64 need it? diff --git a/Makefile b/Makefile index 2f6fbba88a0e..fbc42c3c389e 100644 --- a/Makefile +++ b/Makefile @@ -852,10 +852,6 @@ ifdef CONFIG_CC_IS_CLANG KBUILD_CPPFLAGS += -Qunused-arguments # The kernel builds with '-std=gnu89' so use of GNU extensions is acceptable. KBUILD_CFLAGS += -Wno-gnu -# CLANG uses a _MergedGlobals as optimization, but this breaks modpost, as the -# source of a reference will be _MergedGlobals and not on of the whitelisted names. -# See modpost pattern 2 -KBUILD_CFLAGS += -mno-global-merge else # gcc inanely warns about local variables called 'main' diff --git a/arch/arm/Makefile b/arch/arm/Makefile index a2391b8de5a5..dcab28c44c26 100644 --- a/arch/arm/Makefile +++ b/arch/arm/Makefile @@ -48,6 +48,13 @@ CHECKFLAGS += -D__ARMEL__ KBUILD_LDFLAGS += -EL endif +ifdef CONFIG_CC_IS_CLANG +# CLANG uses a _MergedGlobals as optimization, but this breaks modpost, as the +# source of a reference will be _MergedGlobals and not on of the whitelisted names. +# See modpost pattern 2 +KBUILD_CFLAGS += -mno-global-merge +endif + # # The Scalar Replacement of Aggregates (SRA) optimization pass in GCC 4.9 and # later may result in code being generated that handles signed short and signed diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index 2f1de88651e6..2d20fb2ea664 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -36,6 +36,13 @@ ifeq ($(CONFIG_BROKEN_GAS_INST),y) $(warning Detected assembler with broken .inst; disassembly will be unreliable) endif +ifdef CONFIG_CC_IS_CLANG +# CLANG uses a _MergedGlobals as optimization, but this breaks modpost, as the +# source of a reference will be _MergedGlobals and not on of the whitelisted names. +# See modpost pattern 2 +KBUILD_CFLAGS += -mno-global-merge +endif + KBUILD_CFLAGS += -mgeneral-regs-only \ $(compat_vdso) $(cc_has_k_constraint) KBUILD_CFLAGS += $(call cc-disable-warning, psabi) > > + > > #This will adjust *FLAGS accordingly to the platform. > > include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS) > > > > -- > > 2.35.1.616.g0bdcbb4464-goog > > -- Kees Cook