linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nathan Chancellor <natechancellor@gmail.com>
To: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Masahiro Yamada <masahiroy@kernel.org>,
	linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org,
	clang-built-linux@googlegroups.com, linux-kbuild@vger.kernel.org,
	Nick Desaulniers <ndesaulniers@google.com>,
	Sami Tolvanen <samitolvanen@google.com>,
	Dmitry Golovin <dima@golovin.in>,
	Sedat Dilek <sedat.dilek@gmail.com>
Subject: Re: [PATCH v3 3/4] MIPS: VDSO: Use $(LD) instead of $(CC) to link VDSO
Date: Mon, 27 Apr 2020 19:17:37 -0700	[thread overview]
Message-ID: <20200428021737.GA7351@ubuntu-s3-xlarge-x86> (raw)
In-Reply-To: <20200426162737.GA9322@alpha.franken.de>

On Sun, Apr 26, 2020 at 06:27:37PM +0200, Thomas Bogendoerfer wrote:
> On Thu, Apr 23, 2020 at 10:18:06AM -0700, Nathan Chancellor wrote:
> > Currently, the VDSO is being linked through $(CC). This does not match
> > how the rest of the kernel links objects, which is through the $(LD)
> > variable.
> 
> this causes build errors for me when (cross) compiling a big endian target:
> 
> target is little endian
> mips64-linux-gnu-ld: arch/mips/vdso/elf.o: endianness incompatible with that of the selected emulation
> mips64-linux-gnu-ld: failed to merge target specific data of file arch/mips/vdso/elf.o
> 
> Thomas.
> 

Thanks for reporting this, I figured it out. This is the solution that I
came up with, I'll send out a v4 tomorrow once I do some more testing.

Cheers,
Nathan

From 256e3b6c8fff7a66aa29961ebefc0fe653ec34b6 Mon Sep 17 00:00:00 2001
From: Nathan Chancellor <natechancellor@gmail.com>
Date: Mon, 27 Apr 2020 17:02:55 -0700
Subject: [PATCH] MIPS: Unconditionally specify '-EL' or '-EB'

This was all done to work around a GCC bug that has been fixed after
4.2. The kernel requires GCC 4.6 or newer so remove all of these hacks
and just use the traditional flags.

 $ mips64-linux-gcc --version | head -n1
 mips64-linux-gcc (GCC) 4.6.3

 $ mips64-linux-gcc -EB -dM -E -C -x c /dev/null | grep MIPSE
 #define MIPSEB 1
 #define __MIPSEB__ 1
 #define _MIPSEB 1
 #define __MIPSEB 1

 $ mips64-linux-gcc -EL -dM -E -C -x c /dev/null | grep MIPSE
 #define __MIPSEL__ 1
 #define MIPSEL 1
 #define _MIPSEL 1
 #define __MIPSEL 1

This is necessary when converting the MIPS VDSO to use $(LD) instead of
$(CC) to link because the OUTPUT_FORMAT is defaulted to little endian
and only flips to big endian when -EB is set on the command line, which
is inherited from KBUILD_CFLAGS. Without this, we will see the following
error when compiling for big endian (64r2_defconfig):

$ make -j$(nproc) ARCH=mips CROSS_COMPILE=mips64-linux- \
  64r2el_defconfig arch/mips/vdso/
...
mips64-linux-ld: arch/mips/vdso/elf.o: compiled for a big endian system
and target is little endian
mips64-linux-ld: arch/mips/vdso/elf.o: endianness incompatible with that
of the selected emulation
mips64-linux-ld: failed to merge target specific data of file
arch/mips/vdso/elf.o
...

Reported-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
---
 arch/mips/Makefile | 25 -------------------------
 1 file changed, 25 deletions(-)

diff --git a/arch/mips/Makefile b/arch/mips/Makefile
index e1c44aed81565..301efb90b51ed 100644
--- a/arch/mips/Makefile
+++ b/arch/mips/Makefile
@@ -116,33 +116,8 @@ endif
 
 cflags-y += -ffreestanding
 
-#
-# We explicitly add the endianness specifier if needed, this allows
-# to compile kernels with a toolchain for the other endianness. We
-# carefully avoid to add it redundantly because gcc 3.3/3.4 complains
-# when fed the toolchain default!
-#
-# Certain gcc versions up to gcc 4.1.1 (probably 4.2-subversion as of
-# 2006-10-10 don't properly change the predefined symbols if -EB / -EL
-# are used, so we kludge that here.  A bug has been filed at
-# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29413.
-#
-# clang doesn't suffer from these issues and our checks against -dumpmachine
-# don't work so well when cross compiling, since without providing --target
-# clang's output will be based upon the build machine. So for clang we simply
-# unconditionally specify -EB or -EL as appropriate.
-#
-ifdef CONFIG_CC_IS_CLANG
 cflags-$(CONFIG_CPU_BIG_ENDIAN)		+= -EB
 cflags-$(CONFIG_CPU_LITTLE_ENDIAN)	+= -EL
-else
-undef-all += -UMIPSEB -U_MIPSEB -U__MIPSEB -U__MIPSEB__
-undef-all += -UMIPSEL -U_MIPSEL -U__MIPSEL -U__MIPSEL__
-predef-be += -DMIPSEB -D_MIPSEB -D__MIPSEB -D__MIPSEB__
-predef-le += -DMIPSEL -D_MIPSEL -D__MIPSEL -D__MIPSEL__
-cflags-$(CONFIG_CPU_BIG_ENDIAN)		+= $(shell $(CC) -dumpmachine |grep -q 'mips.*el-.*' && echo -EB $(undef-all) $(predef-be))
-cflags-$(CONFIG_CPU_LITTLE_ENDIAN)	+= $(shell $(CC) -dumpmachine |grep -q 'mips.*el-.*' || echo -EL $(undef-all) $(predef-le))
-endif
 
 cflags-$(CONFIG_SB1XXX_CORELIS)	+= $(call cc-option,-mno-sched-prolog) \
 				   -fno-omit-frame-pointer
-- 
2.26.2


  parent reply	other threads:[~2020-04-28  2:17 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-19 18:04 [PATCH 1/2] kbuild: add CONFIG_LD_IS_LLD Nathan Chancellor
2020-04-19 18:04 ` [PATCH 2/2] MIPS: VDSO: Do not disable VDSO when linking with ld.lld Nathan Chancellor
2020-04-19 18:17   ` Nathan Chancellor
2020-04-19 19:32     ` Masahiro Yamada
2020-04-19 20:05       ` Nathan Chancellor
2020-04-19 20:21 ` [PATCH v2 1/3] kbuild: add CONFIG_LD_IS_LLD Nathan Chancellor
2020-04-19 20:21   ` [PATCH v2 2/3] MIPS: VDSO: Move disabling the VDSO logic to Kconfig Nathan Chancellor
2020-04-20  9:53     ` Sedat Dilek
2020-04-21  2:42       ` Nathan Chancellor
2020-04-23 14:41         ` Masahiro Yamada
2020-04-19 20:21   ` [PATCH v2 3/3] MIPS: VDSO: Allow ld.lld to link the VDSO Nathan Chancellor
2020-04-23 14:38   ` [PATCH v2 1/3] kbuild: add CONFIG_LD_IS_LLD Masahiro Yamada
2020-04-23 17:18   ` [PATCH v3 1/4] " Nathan Chancellor
2020-04-23 17:18     ` [PATCH v3 2/4] MIPS: VDSO: Move disabling the VDSO logic to Kconfig Nathan Chancellor
2020-04-23 17:18     ` [PATCH v3 3/4] MIPS: VDSO: Use $(LD) instead of $(CC) to link VDSO Nathan Chancellor
2020-04-26 16:27       ` Thomas Bogendoerfer
2020-04-27  2:08         ` Nathan Chancellor
2020-04-27 16:22           ` Maciej W. Rozycki
2020-04-27 23:24             ` Nathan Chancellor
2020-04-29 17:46               ` Maciej W. Rozycki
2020-04-30  3:14                 ` Nathan Chancellor
2020-04-28  2:17         ` Nathan Chancellor [this message]
2020-04-23 17:18     ` [PATCH v3 4/4] MIPS: VDSO: Allow ld.lld to link the VDSO Nathan Chancellor
2020-04-28 22:14     ` [PATCH v5 0/5] Allow ld.lld to link the MIPS VDSO Nathan Chancellor
2020-04-28 22:14       ` [PATCH v4 1/5] kbuild: add CONFIG_LD_IS_LLD Nathan Chancellor
2020-04-29  7:13         ` Sedat Dilek
2020-04-30  3:05           ` Nathan Chancellor
2020-04-28 22:14       ` [PATCH v4 2/5] MIPS: VDSO: Move disabling the VDSO logic to Kconfig Nathan Chancellor
2020-04-28 22:14       ` [PATCH v4 3/5] MIPS: Unconditionally specify '-EB' or '-EL' Nathan Chancellor
2020-04-28 22:14       ` [PATCH v4 4/5] MIPS: VDSO: Use $(LD) instead of $(CC) to link VDSO Nathan Chancellor
2020-04-28 22:54         ` Fangrui Song
2020-04-29  0:44           ` Nathan Chancellor
2020-05-02 13:34           ` Maciej W. Rozycki
2020-05-02 13:50         ` Maciej W. Rozycki
2020-05-02 15:49           ` Nathan Chancellor
2020-04-28 22:14       ` [PATCH v4 5/5] MIPS: VDSO: Allow ld.lld to link the VDSO Nathan Chancellor
2020-04-29  7:04       ` [PATCH v5 0/5] Allow ld.lld to link the MIPS VDSO Sedat Dilek
2020-04-30  3:06         ` Nathan Chancellor
2020-05-12  8:05       ` Thomas Bogendoerfer
2020-05-12  8:28         ` Nathan Chancellor
2020-05-13 11:18           ` Thomas Bogendoerfer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200428021737.GA7351@ubuntu-s3-xlarge-x86 \
    --to=natechancellor@gmail.com \
    --cc=clang-built-linux@googlegroups.com \
    --cc=dima@golovin.in \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=samitolvanen@google.com \
    --cc=sedat.dilek@gmail.com \
    --cc=tsbogend@alpha.franken.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).