Message ID | 20230409145358.2538266-1-masahiroy@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1413870vqo; Sun, 9 Apr 2023 08:05:08 -0700 (PDT) X-Google-Smtp-Source: AKy350aaT70bSmy1SEqghJXAw/Fc4zJNk7/IIlcPiHpfsL+OrGEeIiunGj4qNjKPqjAs30qOaIBb X-Received: by 2002:a17:90b:3e85:b0:23b:4005:26e6 with SMTP id rj5-20020a17090b3e8500b0023b400526e6mr10291807pjb.34.1681052708486; Sun, 09 Apr 2023 08:05:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681052708; cv=none; d=google.com; s=arc-20160816; b=wv5Ntiaf/vCB5AVPLveJmEIJbykE+ApITjmWrl/4pa8EeTZiNPFruofnST7Co6T5W2 DEtWFwm9Ww+yXq9pSe3TgIUiHPLqPKLD6dDMlBa9e7Whv8Teb4CitZfLCqpmmjNmgCNs WpjSwS/GJCOqy3kUXoCSTp5Va5rJcSu9sYYUUFTQj4vku4+st+A7QX9pLwbnBMYAUtBz g/4aBC9yARk/p8bSLBIdMoQoQiQueOD5nXXT4F5TCmFM9vws7SepYasLgFB/WH400xeg H4MIhDYF+S7rpxoZBouB/mR+Hg1LeX9ZiEcvs3sqm6xfmOLNIS2WOuwE1GGkD8TaFk36 q2zA== 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=UT+KZY/0NdCZUrolZImODuWcHv5Zp8rAn6+BjpqCZog=; b=iJfILq2Fso5Vn0+PhPHUpbFeHUp4O55f897uB6O3FAVAlEKpGIH5tJufQabrLoNEN5 S8VIhY8i/rnG6/y/7HJ5g7iG1g3klq1iMEtXzFvxAeT0YTDnfbZHLFCe3Dzf8Mr8jwTi uPC+VJUbj/l1igIYSBNYOHT/MFNRIci5x86IlqZoQQk7isKGtr/Hm9bU4KZEswseVmvs j8nHt1VtLij5go2SntloRv+Iy63t4dizLam3RpXkBCPj4QD/Tx8/xxjBZh9QXRARIHea ceG4NPyUuXb0iOvcbRFM50/3PSjjgtXx9B9AMAsUs6nMsot3RZyjTh9nm3EUaUQoQVhe aP+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=c7+bCLim; 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 j186-20020a638bc3000000b005195b49d9d6si1373241pge.511.2023.04.09.08.04.51; Sun, 09 Apr 2023 08:05:08 -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=@kernel.org header.s=k20201202 header.b=c7+bCLim; 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 S229598AbjDIOyI (ORCPT <rfc822;yuanzuo1009@gmail.com> + 99 others); Sun, 9 Apr 2023 10:54:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229462AbjDIOyG (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 9 Apr 2023 10:54:06 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 136973A87; Sun, 9 Apr 2023 07:54:06 -0700 (PDT) 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 A0F9E60B9F; Sun, 9 Apr 2023 14:54:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 601D6C433EF; Sun, 9 Apr 2023 14:54:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681052045; bh=sR52KGMqxK6Vt6XY9CUVOsj3Fqld4NSi7ibY6IQOrls=; h=From:To:Cc:Subject:Date:From; b=c7+bCLim2D3xhHj9JAL0ZLjWdWnrvkOKClHaZBXuRTJFRMzoD8+7yJCMn65AyhspJ r/A8d6GIy75OYca0Ddu2CRsJQzfb6/ttOugEx92E3i+u0hQF7CJlv+1l3c9fZPqdEt 7kehPv01N4jrHKBwDghBZA5gWap3UGFm7P19NLQqAQ8yPSo9/PdcSqmei6+punbR02 CoFynNaG9cf9QaRFNCKr+yGod6Ajoewn/kCBzpR0egG9Qggebl5e+fCbE/rXiCX3Fj ZnH3QCzmboEVdeLxLQf1TQ0lx3TKAr4NuZVb4F7OwoSB27ubtdDp1gvW2MJytgEgAm vH/w1ohaBirdw== From: Masahiro Yamada <masahiroy@kernel.org> To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada <masahiroy@kernel.org>, Tom Rini <trini@konsulko.com>, Nathan Chancellor <nathan@kernel.org>, Nick Desaulniers <ndesaulniers@google.com>, Nicolas Schier <nicolas@fjasle.eu>, Tom Rix <trix@redhat.com>, llvm@lists.linux.dev Subject: [PATCH] kbuild: add $(CLANG_CFLAGS) to KBUILD_CPPFLAGS Date: Sun, 9 Apr 2023 23:53:57 +0900 Message-Id: <20230409145358.2538266-1-masahiroy@kernel.org> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762711524883304362?= X-GMAIL-MSGID: =?utf-8?q?1762711524883304362?= |
Series |
kbuild: add $(CLANG_CFLAGS) to KBUILD_CPPFLAGS
|
|
Commit Message
Masahiro Yamada
April 9, 2023, 2:53 p.m. UTC
When preprocessing arch/*/kernel/vmlinux.lds.S, the target triple is
not passed to $(CPP) because we add it only to KBUILD_{C,A}FLAGS.
As a result, the linker script is preprocessed with predefined macros
for the build host instead of the target.
Assuming you use an x86 build machine, compare the following:
$ clang -dM -E -x c /dev/null
$ clang -dM -E -x c /dev/null -target aarch64-linux-gnu
There is no actual problem presumably because our linker scripts do not
rely on such predefined macros, but it is better to define correct ones.
Move $(CFLAGS_CFLAGS) to KBUILD_CPPFLAGS, so that all *.c, *.S, *.lds.S
will be processed with the proper target triple.
Reported-by: Tom Rini <trini@konsulko.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
scripts/Makefile.clang | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
Comments
Hi Masahiro, kernel test robot noticed the following build warnings: [auto build test WARNING on masahiroy-kbuild/for-next] [also build test WARNING on masahiroy-kbuild/fixes linus/master v6.3-rc6 next-20230406] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Masahiro-Yamada/kbuild-add-CLANG_CFLAGS-to-KBUILD_CPPFLAGS/20230409-225441 base: https://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git for-next patch link: https://lore.kernel.org/r/20230409145358.2538266-1-masahiroy%40kernel.org patch subject: [PATCH] kbuild: add $(CLANG_CFLAGS) to KBUILD_CPPFLAGS config: mips-ip22_defconfig (https://download.01.org/0day-ci/archive/20230410/202304100319.Wfcfuyqz-lkp@intel.com/config) compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project 2c57868e2e877f73c339796c3374ae660bb77f0d) reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # install mips cross compiling tool for clang build # apt-get install binutils-mips-linux-gnu # https://github.com/intel-lab-lkp/linux/commit/4a97e93c7f8c2aaf7bcca67a061264a1126d0e25 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Masahiro-Yamada/kbuild-add-CLANG_CFLAGS-to-KBUILD_CPPFLAGS/20230409-225441 git checkout 4a97e93c7f8c2aaf7bcca67a061264a1126d0e25 # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=mips olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=mips prepare If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> | Link: https://lore.kernel.org/oe-kbuild-all/202304100319.Wfcfuyqz-lkp@intel.com/ All warnings (new ones prefixed by >>): >> clang: warning: argument unused during compilation: '-mno-check-zero-division' [-Wunused-command-line-argument] clang: warning: argument unused during compilation: '-mabi=32' [-Wunused-command-line-argument] >> clang: warning: argument unused during compilation: '-G 0' [-Wunused-command-line-argument] >> clang: warning: argument unused during compilation: '-mno-abicalls' [-Wunused-command-line-argument] error: unknown target CPU 'r5000' note: valid target CPU values are: nocona, core2, penryn, bonnell, atom, silvermont, slm, goldmont, goldmont-plus, tremont, nehalem, corei7, westmere, sandybridge, corei7-avx, ivybridge, core-avx-i, haswell, core-avx2, broadwell, skylake, skylake-avx512, skx, cascadelake, cooperlake, cannonlake, icelake-client, rocketlake, icelake-server, tigerlake, sapphirerapids, alderlake, raptorlake, meteorlake, sierraforest, grandridge, graniterapids, emeraldrapids, knl, knm, k8, athlon64, athlon-fx, opteron, k8-sse3, athlon64-sse3, opteron-sse3, amdfam10, barcelona, btver1, btver2, bdver1, bdver2, bdver3, bdver4, znver1, znver2, znver3, znver4, x86-64, x86-64-v2, x86-64-v3, x86-64-v4 scripts/genksyms/parse.y: warning: 9 shift/reduce conflicts [-Wconflicts-sr] scripts/genksyms/parse.y: warning: 5 reduce/reduce conflicts [-Wconflicts-rr] scripts/genksyms/parse.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples error: unknown target CPU 'r5000' note: valid target CPU values are: mips1, mips2, mips3, mips4, mips5, mips32, mips32r2, mips32r3, mips32r5, mips32r6, mips64, mips64r2, mips64r3, mips64r5, mips64r6, octeon, octeon+, p5600 make[2]: *** [scripts/Makefile.build:252: scripts/mod/empty.o] Error 1 error: unknown target CPU 'r5000' note: valid target CPU values are: mips1, mips2, mips3, mips4, mips5, mips32, mips32r2, mips32r3, mips32r5, mips32r6, mips64, mips64r2, mips64r3, mips64r5, mips64r6, octeon, octeon+, p5600 make[2]: *** [scripts/Makefile.build:114: scripts/mod/devicetable-offsets.s] Error 1 make[2]: Target 'scripts/mod/' not remade because of errors. make[1]: *** [Makefile:1285: prepare0] Error 2 make[1]: Target 'prepare' not remade because of errors. make: *** [Makefile:226: __sub-make] Error 2 make: Target 'prepare' not remade because of errors.
On Mon, Apr 10, 2023 at 04:09:37AM +0800, kernel test robot wrote: > Hi Masahiro, > > kernel test robot noticed the following build warnings: > > [auto build test WARNING on masahiroy-kbuild/for-next] > [also build test WARNING on masahiroy-kbuild/fixes linus/master v6.3-rc6 next-20230406] > [If your patch is applied to the wrong git tree, kindly drop us a note. > And when submitting patch, we suggest to use '--base' as documented in > https://git-scm.com/docs/git-format-patch#_base_tree_information] > > url: https://github.com/intel-lab-lkp/linux/commits/Masahiro-Yamada/kbuild-add-CLANG_CFLAGS-to-KBUILD_CPPFLAGS/20230409-225441 > base: https://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git for-next > patch link: https://lore.kernel.org/r/20230409145358.2538266-1-masahiroy%40kernel.org > patch subject: [PATCH] kbuild: add $(CLANG_CFLAGS) to KBUILD_CPPFLAGS > config: mips-ip22_defconfig (https://download.01.org/0day-ci/archive/20230410/202304100319.Wfcfuyqz-lkp@intel.com/config) > compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project 2c57868e2e877f73c339796c3374ae660bb77f0d) > reproduce (this is a W=1 build): > wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross > chmod +x ~/bin/make.cross > # install mips cross compiling tool for clang build > # apt-get install binutils-mips-linux-gnu > # https://github.com/intel-lab-lkp/linux/commit/4a97e93c7f8c2aaf7bcca67a061264a1126d0e25 > git remote add linux-review https://github.com/intel-lab-lkp/linux > git fetch --no-tags linux-review Masahiro-Yamada/kbuild-add-CLANG_CFLAGS-to-KBUILD_CPPFLAGS/20230409-225441 > git checkout 4a97e93c7f8c2aaf7bcca67a061264a1126d0e25 > # save the config file > mkdir build_dir && cp config build_dir/.config > COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=mips olddefconfig > COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=mips prepare > > If you fix the issue, kindly add following tag where applicable > | Reported-by: kernel test robot <lkp@intel.com> > | Link: https://lore.kernel.org/oe-kbuild-all/202304100319.Wfcfuyqz-lkp@intel.com/ > > All warnings (new ones prefixed by >>): > > >> clang: warning: argument unused during compilation: '-mno-check-zero-division' [-Wunused-command-line-argument] > clang: warning: argument unused during compilation: '-mabi=32' [-Wunused-command-line-argument] > >> clang: warning: argument unused during compilation: '-G 0' [-Wunused-command-line-argument] > >> clang: warning: argument unused during compilation: '-mno-abicalls' [-Wunused-command-line-argument] > error: unknown target CPU 'r5000' > note: valid target CPU values are: nocona, core2, penryn, bonnell, atom, silvermont, slm, goldmont, goldmont-plus, tremont, nehalem, corei7, westmere, sandybridge, corei7-avx, ivybridge, core-avx-i, haswell, core-avx2, broadwell, skylake, skylake-avx512, skx, cascadelake, cooperlake, cannonlake, icelake-client, rocketlake, icelake-server, tigerlake, sapphirerapids, alderlake, raptorlake, meteorlake, sierraforest, grandridge, graniterapids, emeraldrapids, knl, knm, k8, athlon64, athlon-fx, opteron, k8-sse3, athlon64-sse3, opteron-sse3, amdfam10, barcelona, btver1, btver2, bdver1, bdver2, bdver3, bdver4, znver1, znver2, znver3, znver4, x86-64, x86-64-v2, x86-64-v3, x86-64-v4 While r5000 is not a valid MIPS CPU for LLVM (as you can see from the values below), the note here seems to imply that there is a place where KBUILD_{A,C}FLAGS is used without KBUILD_CPPFLAGS because we are dropping '--target'. V=1 does not make it obvious where that is happening though, as I see the error right after syncing the configuration (is it coming from Kconfig internally?). I can see the same issue with 32r2_defconfig, which uses an LLVM supported CPU value. > scripts/genksyms/parse.y: warning: 9 shift/reduce conflicts [-Wconflicts-sr] > scripts/genksyms/parse.y: warning: 5 reduce/reduce conflicts [-Wconflicts-rr] > scripts/genksyms/parse.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples > error: unknown target CPU 'r5000' > note: valid target CPU values are: mips1, mips2, mips3, mips4, mips5, mips32, mips32r2, mips32r3, mips32r5, mips32r6, mips64, mips64r2, mips64r3, mips64r5, mips64r6, octeon, octeon+, p5600 > make[2]: *** [scripts/Makefile.build:252: scripts/mod/empty.o] Error 1 > error: unknown target CPU 'r5000' > note: valid target CPU values are: mips1, mips2, mips3, mips4, mips5, mips32, mips32r2, mips32r3, mips32r5, mips32r6, mips64, mips64r2, mips64r3, mips64r5, mips64r6, octeon, octeon+, p5600 > make[2]: *** [scripts/Makefile.build:114: scripts/mod/devicetable-offsets.s] Error 1 > make[2]: Target 'scripts/mod/' not remade because of errors. > make[1]: *** [Makefile:1285: prepare0] Error 2 > make[1]: Target 'prepare' not remade because of errors. > make: *** [Makefile:226: __sub-make] Error 2 > make: Target 'prepare' not remade because of errors. > > -- > 0-DAY CI Kernel Test Service > https://github.com/intel/lkp-tests
Hi Masahiro, Nit: s/CLANG_CFLAGS/CLANG_FLAGS/ in the title and a small typo below. On Sun, Apr 09, 2023 at 11:53:57PM +0900, Masahiro Yamada wrote: > When preprocessing arch/*/kernel/vmlinux.lds.S, the target triple is > not passed to $(CPP) because we add it only to KBUILD_{C,A}FLAGS. > > As a result, the linker script is preprocessed with predefined macros > for the build host instead of the target. > > Assuming you use an x86 build machine, compare the following: > > $ clang -dM -E -x c /dev/null > $ clang -dM -E -x c /dev/null -target aarch64-linux-gnu > > There is no actual problem presumably because our linker scripts do not > rely on such predefined macros, but it is better to define correct ones. > > Move $(CFLAGS_CFLAGS) to KBUILD_CPPFLAGS, so that all *.c, *.S, *.lds.S ^ CLANG_FLAGS > will be processed with the proper target triple. > > Reported-by: Tom Rini <trini@konsulko.com> > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> We will need to sort out the report from the kbuild test robot before we can do this. Otherwise, I think this should be fine, although I am curious if -Wunused-command-line-argument might fire more because there may be flags are unused while preprocessing. I will run this through my test matrix once the other report has been addressed to make sure there is nothing else obviously wrong with this change. Cheers, Nathan > --- > > scripts/Makefile.clang | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/scripts/Makefile.clang b/scripts/Makefile.clang > index 70b354fa1cb4..93ca059cc3b8 100644 > --- a/scripts/Makefile.clang > +++ b/scripts/Makefile.clang > @@ -38,6 +38,5 @@ CLANG_FLAGS += -Werror=unknown-warning-option > CLANG_FLAGS += -Werror=ignored-optimization-argument > CLANG_FLAGS += -Werror=option-ignored > CLANG_FLAGS += -Werror=unused-command-line-argument > -KBUILD_CFLAGS += $(CLANG_FLAGS) > -KBUILD_AFLAGS += $(CLANG_FLAGS) > +KBUILD_CPPFLAGS += $(CLANG_FLAGS) > export CLANG_FLAGS > -- > 2.37.2 >
Hi Masahiro, On Sun, Apr 09, 2023 at 11:53:57PM +0900, Masahiro Yamada wrote: > When preprocessing arch/*/kernel/vmlinux.lds.S, the target triple is > not passed to $(CPP) because we add it only to KBUILD_{C,A}FLAGS. > > As a result, the linker script is preprocessed with predefined macros > for the build host instead of the target. > > Assuming you use an x86 build machine, compare the following: > > $ clang -dM -E -x c /dev/null > $ clang -dM -E -x c /dev/null -target aarch64-linux-gnu > > There is no actual problem presumably because our linker scripts do not > rely on such predefined macros, but it is better to define correct ones. > > Move $(CFLAGS_CFLAGS) to KBUILD_CPPFLAGS, so that all *.c, *.S, *.lds.S > will be processed with the proper target triple. > > Reported-by: Tom Rini <trini@konsulko.com> > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> > --- > > scripts/Makefile.clang | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/scripts/Makefile.clang b/scripts/Makefile.clang > index 70b354fa1cb4..93ca059cc3b8 100644 > --- a/scripts/Makefile.clang > +++ b/scripts/Makefile.clang > @@ -38,6 +38,5 @@ CLANG_FLAGS += -Werror=unknown-warning-option > CLANG_FLAGS += -Werror=ignored-optimization-argument > CLANG_FLAGS += -Werror=option-ignored > CLANG_FLAGS += -Werror=unused-command-line-argument > -KBUILD_CFLAGS += $(CLANG_FLAGS) > -KBUILD_AFLAGS += $(CLANG_FLAGS) > +KBUILD_CPPFLAGS += $(CLANG_FLAGS) > export CLANG_FLAGS > -- > 2.37.2 > I am doubling back to this change, as the lack of '--target' in KBUILD_CPPFLAGS is now an active bug with clang-17 due to a new change that rejects '-mbig-endian' and '-mlittle-endian' when not supported by the target, which breaks the arm64 vDSO build when preprocessing its linker script: # Turn on CONFIG_CPU_BIG_ENDIAN in menuconfig $ make -skj"$(nproc)" ARCH=arm64 LLVM=1 O=build mrproper virtconfig menuconfig arch/arm64/kernel/vdso/ ... clang: error: unsupported option '-mbig-endian' for target 'x86_64-pc-linux-gnu' make[3]: *** [.../scripts/Makefile.build:387: arch/arm64/kernel/vdso/vdso.lds] Error 1 ... https://github.com/llvm/llvm-project/commit/d81ce04587c006b6731198956c522c93d0df1050 https://github.com/ClangBuiltLinux/linux/issues/1859 This change resolves that issue. I was able to figure out why those new warnings appeared for ARCH=mips, it is the shell invocation for CHECKFLAGS. The following diff resolves it for me: diff --git a/arch/mips/Makefile b/arch/mips/Makefile index a7a4ee66a9d3..ef7b05ae92ce 100644 --- a/arch/mips/Makefile +++ b/arch/mips/Makefile @@ -346,7 +346,7 @@ KBUILD_CFLAGS += -fno-asynchronous-unwind-tables KBUILD_LDFLAGS += -m $(ld-emul) ifdef CONFIG_MIPS -CHECKFLAGS += $(shell $(CC) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \ +CHECKFLAGS += $(shell $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \ grep -E -vw '__GNUC_(MINOR_|PATCHLEVEL_)?_' | \ sed -e "s/^\#define /-D'/" -e "s/ /'='/" -e "s/$$/'/" -e 's/\$$/&&/g') endif I will run this change plus that diff through my build matrix to see if any other issues pop up. If not, I will respond with some tags and perhaps this could be taken as a fix for 6.4 so that it could potentially be backported? Cheers, Nathan
On Wed, May 31, 2023 at 02:33:23PM -0700, Nathan Chancellor wrote: > Hi Masahiro, > > On Sun, Apr 09, 2023 at 11:53:57PM +0900, Masahiro Yamada wrote: > > When preprocessing arch/*/kernel/vmlinux.lds.S, the target triple is > > not passed to $(CPP) because we add it only to KBUILD_{C,A}FLAGS. > > > > As a result, the linker script is preprocessed with predefined macros > > for the build host instead of the target. > > > > Assuming you use an x86 build machine, compare the following: > > > > $ clang -dM -E -x c /dev/null > > $ clang -dM -E -x c /dev/null -target aarch64-linux-gnu > > > > There is no actual problem presumably because our linker scripts do not > > rely on such predefined macros, but it is better to define correct ones. > > > > Move $(CFLAGS_CFLAGS) to KBUILD_CPPFLAGS, so that all *.c, *.S, *.lds.S > > will be processed with the proper target triple. > > > > Reported-by: Tom Rini <trini@konsulko.com> > > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> > > --- > > > > scripts/Makefile.clang | 3 +-- > > 1 file changed, 1 insertion(+), 2 deletions(-) > > > > diff --git a/scripts/Makefile.clang b/scripts/Makefile.clang > > index 70b354fa1cb4..93ca059cc3b8 100644 > > --- a/scripts/Makefile.clang > > +++ b/scripts/Makefile.clang > > @@ -38,6 +38,5 @@ CLANG_FLAGS += -Werror=unknown-warning-option > > CLANG_FLAGS += -Werror=ignored-optimization-argument > > CLANG_FLAGS += -Werror=option-ignored > > CLANG_FLAGS += -Werror=unused-command-line-argument > > -KBUILD_CFLAGS += $(CLANG_FLAGS) > > -KBUILD_AFLAGS += $(CLANG_FLAGS) > > +KBUILD_CPPFLAGS += $(CLANG_FLAGS) > > export CLANG_FLAGS > > -- > > 2.37.2 > > > > I am doubling back to this change, as the lack of '--target' in > KBUILD_CPPFLAGS is now an active bug with clang-17 due to a new change > that rejects '-mbig-endian' and '-mlittle-endian' when not supported by > the target, which breaks the arm64 vDSO build when preprocessing its > linker script: > > # Turn on CONFIG_CPU_BIG_ENDIAN in menuconfig > $ make -skj"$(nproc)" ARCH=arm64 LLVM=1 O=build mrproper virtconfig menuconfig arch/arm64/kernel/vdso/ > ... > clang: error: unsupported option '-mbig-endian' for target 'x86_64-pc-linux-gnu' > make[3]: *** [.../scripts/Makefile.build:387: arch/arm64/kernel/vdso/vdso.lds] Error 1 > ... > > https://github.com/llvm/llvm-project/commit/d81ce04587c006b6731198956c522c93d0df1050 > https://github.com/ClangBuiltLinux/linux/issues/1859 > > This change resolves that issue. I was able to figure out why those new > warnings appeared for ARCH=mips, it is the shell invocation for > CHECKFLAGS. The following diff resolves it for me: > > diff --git a/arch/mips/Makefile b/arch/mips/Makefile > index a7a4ee66a9d3..ef7b05ae92ce 100644 > --- a/arch/mips/Makefile > +++ b/arch/mips/Makefile > @@ -346,7 +346,7 @@ KBUILD_CFLAGS += -fno-asynchronous-unwind-tables > KBUILD_LDFLAGS += -m $(ld-emul) > > ifdef CONFIG_MIPS > -CHECKFLAGS += $(shell $(CC) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \ > +CHECKFLAGS += $(shell $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \ > grep -E -vw '__GNUC_(MINOR_|PATCHLEVEL_)?_' | \ > sed -e "s/^\#define /-D'/" -e "s/ /'='/" -e "s/$$/'/" -e 's/\$$/&&/g') > endif > > I will run this change plus that diff through my build matrix to see if > any other issues pop up. If not, I will respond with some tags and > perhaps this could be taken as a fix for 6.4 so that it could > potentially be backported? I found two more issues lurking in PowerPC. I have attached suggested patches for all the issues I have uncovered to this email, please feel free to use them or do something different if you feel there is a better fix. With those issues resolved in one way or another, consider the original change: Reviewed-by: Nathan Chancellor <nathan@kernel.org> Tested-by: Nathan Chancellor <nathan@kernel.org> If it would work better for you, I am more than happy to take over this series as well. Cheers, Nathan
On Thu, Jun 1, 2023 at 6:33 AM Nathan Chancellor <nathan@kernel.org> wrote: > > Hi Masahiro, > > On Sun, Apr 09, 2023 at 11:53:57PM +0900, Masahiro Yamada wrote: > > When preprocessing arch/*/kernel/vmlinux.lds.S, the target triple is > > not passed to $(CPP) because we add it only to KBUILD_{C,A}FLAGS. > > > > As a result, the linker script is preprocessed with predefined macros > > for the build host instead of the target. > > > > Assuming you use an x86 build machine, compare the following: > > > > $ clang -dM -E -x c /dev/null > > $ clang -dM -E -x c /dev/null -target aarch64-linux-gnu > > > > There is no actual problem presumably because our linker scripts do not > > rely on such predefined macros, but it is better to define correct ones. > > > > Move $(CFLAGS_CFLAGS) to KBUILD_CPPFLAGS, so that all *.c, *.S, *.lds.S > > will be processed with the proper target triple. > > > > Reported-by: Tom Rini <trini@konsulko.com> > > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> > > --- > > > > scripts/Makefile.clang | 3 +-- > > 1 file changed, 1 insertion(+), 2 deletions(-) > > > > diff --git a/scripts/Makefile.clang b/scripts/Makefile.clang > > index 70b354fa1cb4..93ca059cc3b8 100644 > > --- a/scripts/Makefile.clang > > +++ b/scripts/Makefile.clang > > @@ -38,6 +38,5 @@ CLANG_FLAGS += -Werror=unknown-warning-option > > CLANG_FLAGS += -Werror=ignored-optimization-argument > > CLANG_FLAGS += -Werror=option-ignored > > CLANG_FLAGS += -Werror=unused-command-line-argument > > -KBUILD_CFLAGS += $(CLANG_FLAGS) > > -KBUILD_AFLAGS += $(CLANG_FLAGS) > > +KBUILD_CPPFLAGS += $(CLANG_FLAGS) > > export CLANG_FLAGS > > -- > > 2.37.2 > > > > I am doubling back to this change, as the lack of '--target' in > KBUILD_CPPFLAGS is now an active bug with clang-17 due to a new change > that rejects '-mbig-endian' and '-mlittle-endian' when not supported by > the target, which breaks the arm64 vDSO build when preprocessing its > linker script: > > # Turn on CONFIG_CPU_BIG_ENDIAN in menuconfig > $ make -skj"$(nproc)" ARCH=arm64 LLVM=1 O=build mrproper virtconfig menuconfig arch/arm64/kernel/vdso/ > ... > clang: error: unsupported option '-mbig-endian' for target 'x86_64-pc-linux-gnu' > make[3]: *** [.../scripts/Makefile.build:387: arch/arm64/kernel/vdso/vdso.lds] Error 1 > ... > > https://github.com/llvm/llvm-project/commit/d81ce04587c006b6731198956c522c93d0df1050 > https://github.com/ClangBuiltLinux/linux/issues/1859 > > This change resolves that issue. Ah. Now we have a good reason to apply this patch. > I was able to figure out why those new > warnings appeared for ARCH=mips, it is the shell invocation for > CHECKFLAGS. The following diff resolves it for me: > > diff --git a/arch/mips/Makefile b/arch/mips/Makefile > index a7a4ee66a9d3..ef7b05ae92ce 100644 > --- a/arch/mips/Makefile > +++ b/arch/mips/Makefile > @@ -346,7 +346,7 @@ KBUILD_CFLAGS += -fno-asynchronous-unwind-tables > KBUILD_LDFLAGS += -m $(ld-emul) > > ifdef CONFIG_MIPS > -CHECKFLAGS += $(shell $(CC) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \ > +CHECKFLAGS += $(shell $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \ > grep -E -vw '__GNUC_(MINOR_|PATCHLEVEL_)?_' | \ > sed -e "s/^\#define /-D'/" -e "s/ /'='/" -e "s/$$/'/" -e 's/\$$/&&/g') > endif Agree. This is the right fix because this $(shell ...) retrieves the predefined macros of the compiler. So, KBUILD_CPPFLAGS is correct. > I will run this change plus that diff through my build matrix to see if > any other issues pop up. If not, I will respond with some tags and > perhaps this could be taken as a fix for 6.4 so that it could > potentially be backported? > > Cheers, > Nathan
On Sat, Jun 3, 2023 at 12:25 AM Nathan Chancellor <nathan@kernel.org> wrote: > > On Wed, May 31, 2023 at 02:33:23PM -0700, Nathan Chancellor wrote: > > Hi Masahiro, > > > > On Sun, Apr 09, 2023 at 11:53:57PM +0900, Masahiro Yamada wrote: > > > When preprocessing arch/*/kernel/vmlinux.lds.S, the target triple is > > > not passed to $(CPP) because we add it only to KBUILD_{C,A}FLAGS. > > > > > > As a result, the linker script is preprocessed with predefined macros > > > for the build host instead of the target. > > > > > > Assuming you use an x86 build machine, compare the following: > > > > > > $ clang -dM -E -x c /dev/null > > > $ clang -dM -E -x c /dev/null -target aarch64-linux-gnu > > > > > > There is no actual problem presumably because our linker scripts do not > > > rely on such predefined macros, but it is better to define correct ones. > > > > > > Move $(CFLAGS_CFLAGS) to KBUILD_CPPFLAGS, so that all *.c, *.S, *.lds.S > > > will be processed with the proper target triple. > > > > > > Reported-by: Tom Rini <trini@konsulko.com> > > > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> > > > --- > > > > > > scripts/Makefile.clang | 3 +-- > > > 1 file changed, 1 insertion(+), 2 deletions(-) > > > > > > diff --git a/scripts/Makefile.clang b/scripts/Makefile.clang > > > index 70b354fa1cb4..93ca059cc3b8 100644 > > > --- a/scripts/Makefile.clang > > > +++ b/scripts/Makefile.clang > > > @@ -38,6 +38,5 @@ CLANG_FLAGS += -Werror=unknown-warning-option > > > CLANG_FLAGS += -Werror=ignored-optimization-argument > > > CLANG_FLAGS += -Werror=option-ignored > > > CLANG_FLAGS += -Werror=unused-command-line-argument > > > -KBUILD_CFLAGS += $(CLANG_FLAGS) > > > -KBUILD_AFLAGS += $(CLANG_FLAGS) > > > +KBUILD_CPPFLAGS += $(CLANG_FLAGS) > > > export CLANG_FLAGS > > > -- > > > 2.37.2 > > > > > > > I am doubling back to this change, as the lack of '--target' in > > KBUILD_CPPFLAGS is now an active bug with clang-17 due to a new change > > that rejects '-mbig-endian' and '-mlittle-endian' when not supported by > > the target, which breaks the arm64 vDSO build when preprocessing its > > linker script: > > > > # Turn on CONFIG_CPU_BIG_ENDIAN in menuconfig > > $ make -skj"$(nproc)" ARCH=arm64 LLVM=1 O=build mrproper virtconfig menuconfig arch/arm64/kernel/vdso/ > > ... > > clang: error: unsupported option '-mbig-endian' for target 'x86_64-pc-linux-gnu' > > make[3]: *** [.../scripts/Makefile.build:387: arch/arm64/kernel/vdso/vdso.lds] Error 1 > > ... > > > > https://github.com/llvm/llvm-project/commit/d81ce04587c006b6731198956c522c93d0df1050 > > https://github.com/ClangBuiltLinux/linux/issues/1859 > > > > This change resolves that issue. I was able to figure out why those new > > warnings appeared for ARCH=mips, it is the shell invocation for > > CHECKFLAGS. The following diff resolves it for me: > > > > diff --git a/arch/mips/Makefile b/arch/mips/Makefile > > index a7a4ee66a9d3..ef7b05ae92ce 100644 > > --- a/arch/mips/Makefile > > +++ b/arch/mips/Makefile > > @@ -346,7 +346,7 @@ KBUILD_CFLAGS += -fno-asynchronous-unwind-tables > > KBUILD_LDFLAGS += -m $(ld-emul) > > > > ifdef CONFIG_MIPS > > -CHECKFLAGS += $(shell $(CC) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \ > > +CHECKFLAGS += $(shell $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \ > > grep -E -vw '__GNUC_(MINOR_|PATCHLEVEL_)?_' | \ > > sed -e "s/^\#define /-D'/" -e "s/ /'='/" -e "s/$$/'/" -e 's/\$$/&&/g') > > endif > > > > I will run this change plus that diff through my build matrix to see if > > any other issues pop up. If not, I will respond with some tags and > > perhaps this could be taken as a fix for 6.4 so that it could > > potentially be backported? > > I found two more issues lurking in PowerPC. I have attached suggested > patches for all the issues I have uncovered to this email, please feel > free to use them or do something different if you feel there is a better > fix. With those issues resolved in one way or another, consider the > original change: > > Reviewed-by: Nathan Chancellor <nathan@kernel.org> > Tested-by: Nathan Chancellor <nathan@kernel.org> > > If it would work better for you, I am more than happy to take over this > series as well. > > Cheers, > Nathan Thanks. All the three patches look good to me. I will apply them, then mine on top. A nit: The first patch for mips will introduce the warning as $(KBUILD_CPPFLAGS) does not contain $(CLANG_FLAGS) at this point. Then, it will be fixed again when my patch is applied. The two must be squashed together to avoid the regression, but I think it is OK as-is. The second patch for powerpc reminded me of converting $(CC) to $(LD) for linking vDSO. I do not remember why powerpc vDSO still uses $(CC). -- Best Regards Masahiro Yamada
On Sun, Jun 04, 2023 at 01:32:21AM +0900, Masahiro Yamada wrote: > On Sat, Jun 3, 2023 at 12:25 AM Nathan Chancellor <nathan@kernel.org> wrote: > > > > On Wed, May 31, 2023 at 02:33:23PM -0700, Nathan Chancellor wrote: > > > Hi Masahiro, > > > > > > On Sun, Apr 09, 2023 at 11:53:57PM +0900, Masahiro Yamada wrote: > > > > When preprocessing arch/*/kernel/vmlinux.lds.S, the target triple is > > > > not passed to $(CPP) because we add it only to KBUILD_{C,A}FLAGS. > > > > > > > > As a result, the linker script is preprocessed with predefined macros > > > > for the build host instead of the target. > > > > > > > > Assuming you use an x86 build machine, compare the following: > > > > > > > > $ clang -dM -E -x c /dev/null > > > > $ clang -dM -E -x c /dev/null -target aarch64-linux-gnu > > > > > > > > There is no actual problem presumably because our linker scripts do not > > > > rely on such predefined macros, but it is better to define correct ones. > > > > > > > > Move $(CFLAGS_CFLAGS) to KBUILD_CPPFLAGS, so that all *.c, *.S, *.lds.S > > > > will be processed with the proper target triple. > > > > > > > > Reported-by: Tom Rini <trini@konsulko.com> > > > > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> > > > > --- > > > > > > > > scripts/Makefile.clang | 3 +-- > > > > 1 file changed, 1 insertion(+), 2 deletions(-) > > > > > > > > diff --git a/scripts/Makefile.clang b/scripts/Makefile.clang > > > > index 70b354fa1cb4..93ca059cc3b8 100644 > > > > --- a/scripts/Makefile.clang > > > > +++ b/scripts/Makefile.clang > > > > @@ -38,6 +38,5 @@ CLANG_FLAGS += -Werror=unknown-warning-option > > > > CLANG_FLAGS += -Werror=ignored-optimization-argument > > > > CLANG_FLAGS += -Werror=option-ignored > > > > CLANG_FLAGS += -Werror=unused-command-line-argument > > > > -KBUILD_CFLAGS += $(CLANG_FLAGS) > > > > -KBUILD_AFLAGS += $(CLANG_FLAGS) > > > > +KBUILD_CPPFLAGS += $(CLANG_FLAGS) > > > > export CLANG_FLAGS > > > > -- > > > > 2.37.2 > > > > > > > > > > I am doubling back to this change, as the lack of '--target' in > > > KBUILD_CPPFLAGS is now an active bug with clang-17 due to a new change > > > that rejects '-mbig-endian' and '-mlittle-endian' when not supported by > > > the target, which breaks the arm64 vDSO build when preprocessing its > > > linker script: > > > > > > # Turn on CONFIG_CPU_BIG_ENDIAN in menuconfig > > > $ make -skj"$(nproc)" ARCH=arm64 LLVM=1 O=build mrproper virtconfig menuconfig arch/arm64/kernel/vdso/ > > > ... > > > clang: error: unsupported option '-mbig-endian' for target 'x86_64-pc-linux-gnu' > > > make[3]: *** [.../scripts/Makefile.build:387: arch/arm64/kernel/vdso/vdso.lds] Error 1 > > > ... > > > > > > https://github.com/llvm/llvm-project/commit/d81ce04587c006b6731198956c522c93d0df1050 > > > https://github.com/ClangBuiltLinux/linux/issues/1859 > > > > > > This change resolves that issue. I was able to figure out why those new > > > warnings appeared for ARCH=mips, it is the shell invocation for > > > CHECKFLAGS. The following diff resolves it for me: > > > > > > diff --git a/arch/mips/Makefile b/arch/mips/Makefile > > > index a7a4ee66a9d3..ef7b05ae92ce 100644 > > > --- a/arch/mips/Makefile > > > +++ b/arch/mips/Makefile > > > @@ -346,7 +346,7 @@ KBUILD_CFLAGS += -fno-asynchronous-unwind-tables > > > KBUILD_LDFLAGS += -m $(ld-emul) > > > > > > ifdef CONFIG_MIPS > > > -CHECKFLAGS += $(shell $(CC) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \ > > > +CHECKFLAGS += $(shell $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \ > > > grep -E -vw '__GNUC_(MINOR_|PATCHLEVEL_)?_' | \ > > > sed -e "s/^\#define /-D'/" -e "s/ /'='/" -e "s/$$/'/" -e 's/\$$/&&/g') > > > endif > > > > > > I will run this change plus that diff through my build matrix to see if > > > any other issues pop up. If not, I will respond with some tags and > > > perhaps this could be taken as a fix for 6.4 so that it could > > > potentially be backported? > > > > I found two more issues lurking in PowerPC. I have attached suggested > > patches for all the issues I have uncovered to this email, please feel > > free to use them or do something different if you feel there is a better > > fix. With those issues resolved in one way or another, consider the > > original change: > > > > Reviewed-by: Nathan Chancellor <nathan@kernel.org> > > Tested-by: Nathan Chancellor <nathan@kernel.org> > > > > If it would work better for you, I am more than happy to take over this > > series as well. > > > > Cheers, > > Nathan > > Thanks. All the three patches look good to me. > > I will apply them, then mine on top. Thanks, sounds like a good plan! > A nit: > > The first patch for mips will introduce the warning > as $(KBUILD_CPPFLAGS) does not contain $(CLANG_FLAGS) > at this point. > Then, it will be fixed again when my patch is applied. > > The two must be squashed together to avoid the regression, > but I think it is OK as-is. Hmmm, what warning would be introduced? KBUILD_CPPFLAGS is being added to the CHECKFLAGS invocation, rather than replacing KBUILD_CFLAGS, so '--target' should always be present (first via KBUILD_CFLAGS then via KBUILD_CPPFLAGS), right? > The second patch for powerpc reminded me of > converting $(CC) to $(LD) for linking vDSO. > I do not remember why powerpc vDSO still uses $(CC). Nick tried to make the conversion some time ago but ran into issues with GNU ld crashing: https://lore.kernel.org/lkml/20200901222523.1941988-1-ndesaulniers@google.com/ https://lore.kernel.org/lkml/b2066ccd-2b81-6032-08e3-41105b400f75@csgroup.eu/ It might be easier to do this now that the PowerPC vDSO has been combined into one directory, but we have not had time to sit down and actually work on it. Cheers, Nathan
On Tue, Jun 6, 2023 at 12:21 AM Nathan Chancellor <nathan@kernel.org> wrote: > > On Sun, Jun 04, 2023 at 01:32:21AM +0900, Masahiro Yamada wrote: > > On Sat, Jun 3, 2023 at 12:25 AM Nathan Chancellor <nathan@kernel.org> wrote: > > > > > > On Wed, May 31, 2023 at 02:33:23PM -0700, Nathan Chancellor wrote: > > > > Hi Masahiro, > > > > > > > > On Sun, Apr 09, 2023 at 11:53:57PM +0900, Masahiro Yamada wrote: > > > > > When preprocessing arch/*/kernel/vmlinux.lds.S, the target triple is > > > > > not passed to $(CPP) because we add it only to KBUILD_{C,A}FLAGS. > > > > > > > > > > As a result, the linker script is preprocessed with predefined macros > > > > > for the build host instead of the target. > > > > > > > > > > Assuming you use an x86 build machine, compare the following: > > > > > > > > > > $ clang -dM -E -x c /dev/null > > > > > $ clang -dM -E -x c /dev/null -target aarch64-linux-gnu > > > > > > > > > > There is no actual problem presumably because our linker scripts do not > > > > > rely on such predefined macros, but it is better to define correct ones. > > > > > > > > > > Move $(CFLAGS_CFLAGS) to KBUILD_CPPFLAGS, so that all *.c, *.S, *.lds.S > > > > > will be processed with the proper target triple. > > > > > > > > > > Reported-by: Tom Rini <trini@konsulko.com> > > > > > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> > > > > > --- > > > > > > > > > > scripts/Makefile.clang | 3 +-- > > > > > 1 file changed, 1 insertion(+), 2 deletions(-) > > > > > > > > > > diff --git a/scripts/Makefile.clang b/scripts/Makefile.clang > > > > > index 70b354fa1cb4..93ca059cc3b8 100644 > > > > > --- a/scripts/Makefile.clang > > > > > +++ b/scripts/Makefile.clang > > > > > @@ -38,6 +38,5 @@ CLANG_FLAGS += -Werror=unknown-warning-option > > > > > CLANG_FLAGS += -Werror=ignored-optimization-argument > > > > > CLANG_FLAGS += -Werror=option-ignored > > > > > CLANG_FLAGS += -Werror=unused-command-line-argument > > > > > -KBUILD_CFLAGS += $(CLANG_FLAGS) > > > > > -KBUILD_AFLAGS += $(CLANG_FLAGS) > > > > > +KBUILD_CPPFLAGS += $(CLANG_FLAGS) > > > > > export CLANG_FLAGS > > > > > -- > > > > > 2.37.2 > > > > > > > > > > > > > I am doubling back to this change, as the lack of '--target' in > > > > KBUILD_CPPFLAGS is now an active bug with clang-17 due to a new change > > > > that rejects '-mbig-endian' and '-mlittle-endian' when not supported by > > > > the target, which breaks the arm64 vDSO build when preprocessing its > > > > linker script: > > > > > > > > # Turn on CONFIG_CPU_BIG_ENDIAN in menuconfig > > > > $ make -skj"$(nproc)" ARCH=arm64 LLVM=1 O=build mrproper virtconfig menuconfig arch/arm64/kernel/vdso/ > > > > ... > > > > clang: error: unsupported option '-mbig-endian' for target 'x86_64-pc-linux-gnu' > > > > make[3]: *** [.../scripts/Makefile.build:387: arch/arm64/kernel/vdso/vdso.lds] Error 1 > > > > ... > > > > > > > > https://github.com/llvm/llvm-project/commit/d81ce04587c006b6731198956c522c93d0df1050 > > > > https://github.com/ClangBuiltLinux/linux/issues/1859 > > > > > > > > This change resolves that issue. I was able to figure out why those new > > > > warnings appeared for ARCH=mips, it is the shell invocation for > > > > CHECKFLAGS. The following diff resolves it for me: > > > > > > > > diff --git a/arch/mips/Makefile b/arch/mips/Makefile > > > > index a7a4ee66a9d3..ef7b05ae92ce 100644 > > > > --- a/arch/mips/Makefile > > > > +++ b/arch/mips/Makefile > > > > @@ -346,7 +346,7 @@ KBUILD_CFLAGS += -fno-asynchronous-unwind-tables > > > > KBUILD_LDFLAGS += -m $(ld-emul) > > > > > > > > ifdef CONFIG_MIPS > > > > -CHECKFLAGS += $(shell $(CC) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \ > > > > +CHECKFLAGS += $(shell $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \ > > > > grep -E -vw '__GNUC_(MINOR_|PATCHLEVEL_)?_' | \ > > > > sed -e "s/^\#define /-D'/" -e "s/ /'='/" -e "s/$$/'/" -e 's/\$$/&&/g') > > > > endif > > > > > > > > I will run this change plus that diff through my build matrix to see if > > > > any other issues pop up. If not, I will respond with some tags and > > > > perhaps this could be taken as a fix for 6.4 so that it could > > > > potentially be backported? > > > > > > I found two more issues lurking in PowerPC. I have attached suggested > > > patches for all the issues I have uncovered to this email, please feel > > > free to use them or do something different if you feel there is a better > > > fix. With those issues resolved in one way or another, consider the > > > original change: > > > > > > Reviewed-by: Nathan Chancellor <nathan@kernel.org> > > > Tested-by: Nathan Chancellor <nathan@kernel.org> > > > > > > If it would work better for you, I am more than happy to take over this > > > series as well. > > > > > > Cheers, > > > Nathan > > > > Thanks. All the three patches look good to me. > > > > I will apply them, then mine on top. > > Thanks, sounds like a good plan! > > > A nit: > > > > The first patch for mips will introduce the warning > > as $(KBUILD_CPPFLAGS) does not contain $(CLANG_FLAGS) > > at this point. > > Then, it will be fixed again when my patch is applied. > > > > The two must be squashed together to avoid the regression, > > but I think it is OK as-is. > > Hmmm, what warning would be introduced? KBUILD_CPPFLAGS is being added > to the CHECKFLAGS invocation, rather than replacing KBUILD_CFLAGS, so > '--target' should always be present (first via KBUILD_CFLAGS then via > KBUILD_CPPFLAGS), right? Sorry, I wrongly read your code. You are right, you added $(KBUILD_CPPFLAGS) in addition to $(KBUILD_CFLAGS). Maybe, we can drop $(KBUILD_CFLAGS) (as a follow-up) because this $(shell ) invocation is only interested in preprocessor macros. diff --git a/arch/mips/Makefile b/arch/mips/Makefile index ef7b05ae92ce..e563cca6b663 100644 --- a/arch/mips/Makefile +++ b/arch/mips/Makefile @@ -346,7 +346,7 @@ KBUILD_CFLAGS += -fno-asynchronous-unwind-tables KBUILD_LDFLAGS += -m $(ld-emul) ifdef CONFIG_MIPS -CHECKFLAGS += $(shell $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \ +CHECKFLAGS += $(shell $(CC) $(KBUILD_CPPFLAGS) -dM -E -x c /dev/null | \ grep -E -vw '__GNUC_(MINOR_|PATCHLEVEL_)?_' | \ sed -e "s/^\#define /-D'/" -e "s/ /'='/" -e "s/$$/'/" -e 's/\$$/&&/g') endif > > > The second patch for powerpc reminded me of > > converting $(CC) to $(LD) for linking vDSO. > > I do not remember why powerpc vDSO still uses $(CC). > > Nick tried to make the conversion some time ago but ran into issues with > GNU ld crashing: > > https://lore.kernel.org/lkml/20200901222523.1941988-1-ndesaulniers@google.com/ > https://lore.kernel.org/lkml/b2066ccd-2b81-6032-08e3-41105b400f75@csgroup.eu/ > > It might be easier to do this now that the PowerPC vDSO has been > combined into one directory, but we have not had time to sit down and > actually work on it. > > Cheers, > Nathan
On Sat, Jun 3, 2023 at 9:33 AM Masahiro Yamada <masahiroy@kernel.org> wrote: > > On Sat, Jun 3, 2023 at 12:25 AM Nathan Chancellor <nathan@kernel.org> wrote: > > > > On Wed, May 31, 2023 at 02:33:23PM -0700, Nathan Chancellor wrote: > > > Hi Masahiro, > > > > > > On Sun, Apr 09, 2023 at 11:53:57PM +0900, Masahiro Yamada wrote: > > > > When preprocessing arch/*/kernel/vmlinux.lds.S, the target triple is > > > > not passed to $(CPP) because we add it only to KBUILD_{C,A}FLAGS. > > > > > > > > As a result, the linker script is preprocessed with predefined macros > > > > for the build host instead of the target. > > > > > > > > Assuming you use an x86 build machine, compare the following: > > > > > > > > $ clang -dM -E -x c /dev/null > > > > $ clang -dM -E -x c /dev/null -target aarch64-linux-gnu > > > > > > > > There is no actual problem presumably because our linker scripts do not > > > > rely on such predefined macros, but it is better to define correct ones. > > > > > > > > Move $(CFLAGS_CFLAGS) to KBUILD_CPPFLAGS, so that all *.c, *.S, *.lds.S > > > > will be processed with the proper target triple. > > > > > > > > Reported-by: Tom Rini <trini@konsulko.com> > > > > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> > > > > --- > > > > > > > > scripts/Makefile.clang | 3 +-- > > > > 1 file changed, 1 insertion(+), 2 deletions(-) > > > > > > > > diff --git a/scripts/Makefile.clang b/scripts/Makefile.clang > > > > index 70b354fa1cb4..93ca059cc3b8 100644 > > > > --- a/scripts/Makefile.clang > > > > +++ b/scripts/Makefile.clang > > > > @@ -38,6 +38,5 @@ CLANG_FLAGS += -Werror=unknown-warning-option > > > > CLANG_FLAGS += -Werror=ignored-optimization-argument > > > > CLANG_FLAGS += -Werror=option-ignored > > > > CLANG_FLAGS += -Werror=unused-command-line-argument > > > > -KBUILD_CFLAGS += $(CLANG_FLAGS) > > > > -KBUILD_AFLAGS += $(CLANG_FLAGS) > > > > +KBUILD_CPPFLAGS += $(CLANG_FLAGS) > > > > export CLANG_FLAGS > > > > -- > > > > 2.37.2 > > > > > > > > > > I am doubling back to this change, as the lack of '--target' in > > > KBUILD_CPPFLAGS is now an active bug with clang-17 due to a new change > > > that rejects '-mbig-endian' and '-mlittle-endian' when not supported by > > > the target, which breaks the arm64 vDSO build when preprocessing its > > > linker script: > > > > > > # Turn on CONFIG_CPU_BIG_ENDIAN in menuconfig > > > $ make -skj"$(nproc)" ARCH=arm64 LLVM=1 O=build mrproper virtconfig menuconfig arch/arm64/kernel/vdso/ > > > ... > > > clang: error: unsupported option '-mbig-endian' for target 'x86_64-pc-linux-gnu' > > > make[3]: *** [.../scripts/Makefile.build:387: arch/arm64/kernel/vdso/vdso.lds] Error 1 > > > ... > > > > > > https://github.com/llvm/llvm-project/commit/d81ce04587c006b6731198956c522c93d0df1050 > > > https://github.com/ClangBuiltLinux/linux/issues/1859 > > > > > > This change resolves that issue. I was able to figure out why those new > > > warnings appeared for ARCH=mips, it is the shell invocation for > > > CHECKFLAGS. The following diff resolves it for me: > > > > > > diff --git a/arch/mips/Makefile b/arch/mips/Makefile > > > index a7a4ee66a9d3..ef7b05ae92ce 100644 > > > --- a/arch/mips/Makefile > > > +++ b/arch/mips/Makefile > > > @@ -346,7 +346,7 @@ KBUILD_CFLAGS += -fno-asynchronous-unwind-tables > > > KBUILD_LDFLAGS += -m $(ld-emul) > > > > > > ifdef CONFIG_MIPS > > > -CHECKFLAGS += $(shell $(CC) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \ > > > +CHECKFLAGS += $(shell $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \ > > > grep -E -vw '__GNUC_(MINOR_|PATCHLEVEL_)?_' | \ > > > sed -e "s/^\#define /-D'/" -e "s/ /'='/" -e "s/$$/'/" -e 's/\$$/&&/g') > > > endif > > > > > > I will run this change plus that diff through my build matrix to see if > > > any other issues pop up. If not, I will respond with some tags and > > > perhaps this could be taken as a fix for 6.4 so that it could > > > potentially be backported? > > > > I found two more issues lurking in PowerPC. I have attached suggested > > patches for all the issues I have uncovered to this email, please feel > > free to use them or do something different if you feel there is a better > > fix. With those issues resolved in one way or another, consider the > > original change: > > > > Reviewed-by: Nathan Chancellor <nathan@kernel.org> > > Tested-by: Nathan Chancellor <nathan@kernel.org> > > > > If it would work better for you, I am more than happy to take over this > > series as well. > > > > Cheers, > > Nathan > > Thanks. All the three patches look good to me. > > I will apply them, then mine on top. Drive-by reply from https://github.com/ClangBuiltLinux/continuous-integration2/pull/585 Hi Masahiro, one nit:) If the patch still has time to adjust the commit message, perhaps consider replacing -target aarch64-linux-gnu with --target=aarch64-linux-gnu as the former is a deprecated driver option since Clang 3.x (long time ago). > Assuming you use an x86 build machine, compare the following: You may drop "Assuming you use an x86 build machine" and add --target=x86_64-linux-gnu to the `clang -dM -E -x c /dev/null` command :)
On Fri, Jun 23, 2023 at 2:07 AM Fangrui Song <maskray@google.com> wrote: > > On Sat, Jun 3, 2023 at 9:33 AM Masahiro Yamada <masahiroy@kernel.org> wrote: > > > > On Sat, Jun 3, 2023 at 12:25 AM Nathan Chancellor <nathan@kernel.org> wrote: > > > > > > On Wed, May 31, 2023 at 02:33:23PM -0700, Nathan Chancellor wrote: > > > > Hi Masahiro, > > > > > > > > On Sun, Apr 09, 2023 at 11:53:57PM +0900, Masahiro Yamada wrote: > > > > > When preprocessing arch/*/kernel/vmlinux.lds.S, the target triple is > > > > > not passed to $(CPP) because we add it only to KBUILD_{C,A}FLAGS. > > > > > > > > > > As a result, the linker script is preprocessed with predefined macros > > > > > for the build host instead of the target. > > > > > > > > > > Assuming you use an x86 build machine, compare the following: > > > > > > > > > > $ clang -dM -E -x c /dev/null > > > > > $ clang -dM -E -x c /dev/null -target aarch64-linux-gnu > > > > > > > > > > There is no actual problem presumably because our linker scripts do not > > > > > rely on such predefined macros, but it is better to define correct ones. > > > > > > > > > > Move $(CFLAGS_CFLAGS) to KBUILD_CPPFLAGS, so that all *.c, *.S, *.lds.S > > > > > will be processed with the proper target triple. > > > > > > > > > > Reported-by: Tom Rini <trini@konsulko.com> > > > > > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> > > > > > --- > > > > > > > > > > scripts/Makefile.clang | 3 +-- > > > > > 1 file changed, 1 insertion(+), 2 deletions(-) > > > > > > > > > > diff --git a/scripts/Makefile.clang b/scripts/Makefile.clang > > > > > index 70b354fa1cb4..93ca059cc3b8 100644 > > > > > --- a/scripts/Makefile.clang > > > > > +++ b/scripts/Makefile.clang > > > > > @@ -38,6 +38,5 @@ CLANG_FLAGS += -Werror=unknown-warning-option > > > > > CLANG_FLAGS += -Werror=ignored-optimization-argument > > > > > CLANG_FLAGS += -Werror=option-ignored > > > > > CLANG_FLAGS += -Werror=unused-command-line-argument > > > > > -KBUILD_CFLAGS += $(CLANG_FLAGS) > > > > > -KBUILD_AFLAGS += $(CLANG_FLAGS) > > > > > +KBUILD_CPPFLAGS += $(CLANG_FLAGS) > > > > > export CLANG_FLAGS > > > > > -- > > > > > 2.37.2 > > > > > > > > > > > > > I am doubling back to this change, as the lack of '--target' in > > > > KBUILD_CPPFLAGS is now an active bug with clang-17 due to a new change > > > > that rejects '-mbig-endian' and '-mlittle-endian' when not supported by > > > > the target, which breaks the arm64 vDSO build when preprocessing its > > > > linker script: > > > > > > > > # Turn on CONFIG_CPU_BIG_ENDIAN in menuconfig > > > > $ make -skj"$(nproc)" ARCH=arm64 LLVM=1 O=build mrproper virtconfig menuconfig arch/arm64/kernel/vdso/ > > > > ... > > > > clang: error: unsupported option '-mbig-endian' for target 'x86_64-pc-linux-gnu' > > > > make[3]: *** [.../scripts/Makefile.build:387: arch/arm64/kernel/vdso/vdso.lds] Error 1 > > > > ... > > > > > > > > https://github.com/llvm/llvm-project/commit/d81ce04587c006b6731198956c522c93d0df1050 > > > > https://github.com/ClangBuiltLinux/linux/issues/1859 > > > > > > > > This change resolves that issue. I was able to figure out why those new > > > > warnings appeared for ARCH=mips, it is the shell invocation for > > > > CHECKFLAGS. The following diff resolves it for me: > > > > > > > > diff --git a/arch/mips/Makefile b/arch/mips/Makefile > > > > index a7a4ee66a9d3..ef7b05ae92ce 100644 > > > > --- a/arch/mips/Makefile > > > > +++ b/arch/mips/Makefile > > > > @@ -346,7 +346,7 @@ KBUILD_CFLAGS += -fno-asynchronous-unwind-tables > > > > KBUILD_LDFLAGS += -m $(ld-emul) > > > > > > > > ifdef CONFIG_MIPS > > > > -CHECKFLAGS += $(shell $(CC) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \ > > > > +CHECKFLAGS += $(shell $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \ > > > > grep -E -vw '__GNUC_(MINOR_|PATCHLEVEL_)?_' | \ > > > > sed -e "s/^\#define /-D'/" -e "s/ /'='/" -e "s/$$/'/" -e 's/\$$/&&/g') > > > > endif > > > > > > > > I will run this change plus that diff through my build matrix to see if > > > > any other issues pop up. If not, I will respond with some tags and > > > > perhaps this could be taken as a fix for 6.4 so that it could > > > > potentially be backported? > > > > > > I found two more issues lurking in PowerPC. I have attached suggested > > > patches for all the issues I have uncovered to this email, please feel > > > free to use them or do something different if you feel there is a better > > > fix. With those issues resolved in one way or another, consider the > > > original change: > > > > > > Reviewed-by: Nathan Chancellor <nathan@kernel.org> > > > Tested-by: Nathan Chancellor <nathan@kernel.org> > > > > > > If it would work better for you, I am more than happy to take over this > > > series as well. > > > > > > Cheers, > > > Nathan > > > > Thanks. All the three patches look good to me. > > > > I will apply them, then mine on top. > > Drive-by reply from > https://github.com/ClangBuiltLinux/continuous-integration2/pull/585 > > Hi Masahiro, one nit:) If the patch still has time to adjust the > commit message, perhaps consider replacing > > -target aarch64-linux-gnu with --target=aarch64-linux-gnu > > as the former is a deprecated driver option since Clang 3.x (long time ago). > > > Assuming you use an x86 build machine, compare the following: > > You may drop "Assuming you use an x86 build machine" and add > --target=x86_64-linux-gnu to the `clang -dM -E -x c /dev/null` command > :) Thanks for the suggestion, but I do not want to change the commit ID unless there is something terribly wrong. Nathan recorded the commit ID in the CBL bug tracker.
diff --git a/scripts/Makefile.clang b/scripts/Makefile.clang index 70b354fa1cb4..93ca059cc3b8 100644 --- a/scripts/Makefile.clang +++ b/scripts/Makefile.clang @@ -38,6 +38,5 @@ CLANG_FLAGS += -Werror=unknown-warning-option CLANG_FLAGS += -Werror=ignored-optimization-argument CLANG_FLAGS += -Werror=option-ignored CLANG_FLAGS += -Werror=unused-command-line-argument -KBUILD_CFLAGS += $(CLANG_FLAGS) -KBUILD_AFLAGS += $(CLANG_FLAGS) +KBUILD_CPPFLAGS += $(CLANG_FLAGS) export CLANG_FLAGS