lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAK7LNAT+zj7fpE_-QewdCVFzz3smZq7V6XART+yOqKcAZCiTFA@mail.gmail.com>
Date:   Fri, 23 Jun 2023 14:40:34 +0900
From:   Masahiro Yamada <masahiroy@...nel.org>
To:     Fangrui Song <maskray@...gle.com>
Cc:     Nathan Chancellor <nathan@...nel.org>,
        linux-kbuild@...r.kernel.org, linux-kernel@...r.kernel.org,
        Tom Rini <trini@...sulko.com>,
        Nick Desaulniers <ndesaulniers@...gle.com>,
        Nicolas Schier <nicolas@...sle.eu>, Tom Rix <trix@...hat.com>,
        llvm@...ts.linux.dev
Subject: Re: [PATCH] kbuild: add $(CLANG_CFLAGS) to KBUILD_CPPFLAGS

On Fri, Jun 23, 2023 at 2:07 AM Fangrui Song <maskray@...gle.com> wrote:
>
> On Sat, Jun 3, 2023 at 9:33 AM Masahiro Yamada <masahiroy@...nel.org> wrote:
> >
> > On Sat, Jun 3, 2023 at 12:25 AM Nathan Chancellor <nathan@...nel.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@...sulko.com>
> > > > > Signed-off-by: Masahiro Yamada <masahiroy@...nel.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@...nel.org>
> > > Tested-by: Nathan Chancellor <nathan@...nel.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.



-- 
Best Regards
Masahiro Yamada

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ