From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1Zb7zU-0004OU-9z for mharc-grub-devel@gnu.org; Sun, 13 Sep 2015 10:10:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58839) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zb7zR-0004Lm-H6 for grub-devel@gnu.org; Sun, 13 Sep 2015 10:10:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zb7zM-0003gV-Hq for grub-devel@gnu.org; Sun, 13 Sep 2015 10:10:45 -0400 Received: from mail-la0-x231.google.com ([2a00:1450:4010:c03::231]:35970) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zb7zM-0003gN-4q for grub-devel@gnu.org; Sun, 13 Sep 2015 10:10:40 -0400 Received: by lanb10 with SMTP id b10so72554908lan.3 for ; Sun, 13 Sep 2015 07:10:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-type; bh=ach7BUyDqgFBgUXLl4q1PoFI92l68DO9mPBu2HCicJ8=; b=IrwtvAG5ibt3e5cB93wlIEv/Y2yzmajXgiNcuklyojbece7Si5jKuWUBgK+mAnqvnU CYxWqJGCm++tBm81lE4layJyaMDIRzsSBQ/UnVGD0QUUW0pDEehSvHgHRC79urOsGCpu WU0yXlwca4PEgEfUOIu5ckwSuZl3aXeoXOQ3wZBNhO5G3hDOO/KEwFy0oqMaPpwZj2zH 0ZP0xo4PKwXjoNAhQ+DrwDxJB1dNeVMtE2RU0MYxcZtG70xCGZziI2pk1p4SfIFoFLKJ mnkG1/wHThcQQB7UUSVMWE2pXSlx2I0RyHTuTmp2vUUSQmNXKn6LzDuuYx8cf7skARvY 32vA== X-Received: by 10.152.204.108 with SMTP id kx12mr8732156lac.20.1442153439073; Sun, 13 Sep 2015 07:10:39 -0700 (PDT) Received: from [192.168.1.43] (ppp91-76-134-130.pppoe.mtu-net.ru. [91.76.134.130]) by smtp.gmail.com with ESMTPSA id xu8sm1193900lab.27.2015.09.13.07.10.37 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 13 Sep 2015 07:10:38 -0700 (PDT) Subject: Re: [PATCH] Ensure that MIPS target code is compiled for the O32 ABI. To: Mark H Weaver References: <1440009323-8667-1-git-send-email-mhw@netris.org> <55D6A36D.205@gmail.com> <876147ryhy.fsf@netris.org> <55DAC58C.1030105@gmail.com> <87si79nmp3.fsf@netris.org> <55DAD1F9.7080302@gmail.com> <55DAE394.6030306@gmail.com> <87mvxfp6y8.fsf@netris.org> <55F2EDF4.4040207@gmail.com> <87a8srjb1h.fsf@netris.org> From: Andrei Borzenkov Message-ID: <55F583DD.2020805@gmail.com> Date: Sun, 13 Sep 2015 17:10:37 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <87a8srjb1h.fsf@netris.org> Content-Type: multipart/mixed; boundary="------------030704020200070700060604" X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c03::231 Cc: The development of GNU GRUB X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 13 Sep 2015 14:10:47 -0000 This is a multi-part message in MIME format. --------------030704020200070700060604 Content-Type: text/plain; charset=windows-1251; format=flowed Content-Transfer-Encoding: 8bit 13.09.2015 05:41, Mark H Weaver пишет: > Andrei Borzenkov writes: > >>> ld: /tmp/conftest-efc530.o: compiled for a big endian system and target is little endian >>> ld: /tmp/conftest-efc530.o: endianness incompatible with that of the selected emulation >> >> This is the same problem we had on powerpc. Your binutils are set to >> use little-endian output by default; we need to explicitly enable >> either big or little endian in this case as well. Could you try >> attached patch to verify? > > I'm glad to report that with your new patch, GRUB successfully builds on > GuixSD mips64el with TARGET_CC=clang. I haven't yet tried booting it > though. > Did you have chance to test whether compiled grub actually work? >>> Your patch works for me with gcc, although config.log shows this warning >>> when building the test program in your new code with the correct flags >>> for gcc (-mabi=32): >>> >>> ld: warning: cannot find entry symbol __start; defaulting to 00000000004000d0 >>> >> >> Well, I just reused existing checks in this case; we worry about it later. > > Okay. I guess the name of the start symbol depends on the platform and > linker. E.g. boot/mips/loongson/fwstart.S has this: > > --8<---------------cut here---------------start------------->8--- > .global start,_start,__start > start: > _start: > __start: > --8<---------------cut here---------------end--------------->8--- > > Other platforms have only '_start', or both 'start' and '_start'. > >>> I also worry that linking an O32 executable might be fragile on a pure >>> non-multilib N32 system such as GNU Guix, where we lack even the gcc >>> runtime library (libgcc_s) for O32. For now it seems to work, but I >>> wonder if it might be more robust to do the test compilation with -c and >>> -freestanding? >>> >> >> It is using -nostdlib; is it not enough? > > The warning above makes me doubt the portability and future-proofness of > the link step of this test. This problem could be avoided entirely by > omitting the link step. The link step serves no purpose in this test, > and is a potential source of portability problems. > This step helped us to catch endianness mismatch; we want to ensure in this case that full toolchain works to produce final binary. > Having said that, if you prefer to keep the link step, I guess it will > probably be okay in practice to define 'start', '_start', and '__start' > as above. Do as you think best. > Please test two attached patches. They separate o32 test from endianness test. I compile-tested them using cross-binutils for mips and powerpc64le to compile for mipsel and powerpc. The first patch also adds additional _start and __start symbols to endianness tests to avoid compiler warnings. I am interested in both native and cross compilation - i.e. please test for both --target=mipsel and --target=mips both with gcc and clang. config.log from all runs would be interesting even for successful cases. --------------030704020200070700060604 Content-Type: text/x-patch; name="0001-configure-try-to-find-options-to-force-endian-on-MIP.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-configure-try-to-find-options-to-force-endian-on-MIP.pa"; filename*1="tch" >From ca80d768a43685e3e67fe9092dc10d9c574ee596 Mon Sep 17 00:00:00 2001 From: Andrei Borzenkov Date: Sun, 13 Sep 2015 16:51:13 +0300 Subject: [PATCH 1/2] configure: try to find options to force endian on MIPS --- configure.ac | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index c864311..4760fe8 100644 --- a/configure.ac +++ b/configure.ac @@ -562,11 +562,11 @@ AC_COMPILE_IFELSE( ]])], [grub_cv_cc_target_clang=no], [grub_cv_cc_target_clang=yes])]) -if test x$target_cpu = xpowerpc; then +if test x$target_cpu = xpowerpc -o x$target_cpu = xmips; then AC_CACHE_CHECK([for options to get big-endian compilation], grub_cv_target_cc_big_endian, [ grub_cv_target_cc_big_endian=no - for cand in "-target powerpc -Wl,-EB" "-target powerpc" \ - "-target powerpc-linux-gnu -Wl,-EB" "-target powerpc-linux-gnu" \ + for cand in "-target $target_cpu -Wl,-EB" "-target $target_cpu" \ + "-target $target_cpu-linux-gnu -Wl,-EB" "-target $target_cpu-linux-gnu" \ "-mbig-endian"; do if test x"$grub_cv_target_cc_big_endian" != xno ; then break @@ -577,6 +577,8 @@ if test x$target_cpu = xpowerpc; then #error still little endian #endif asm (".globl start; start:"); +asm (".globl _start; _start:"); +asm (".globl __start; __start:"); void __main (void); void __main (void) {} int main (void); @@ -595,6 +597,41 @@ int main (void); TARGET_CPPFLAGS="$TARGET_CPPFLAGS $skip_linkflags" TARGET_CCASFLAGS="$TARGET_CCASFLAGS $skip_linkflags" TARGET_LDFLAGS="$TARGET_LDFLAGS $grub_cv_target_cc_big_endian" +elif test x$target_cpu = xmipsel; then + AC_CACHE_CHECK([for options to get little-endian compilation], grub_cv_target_cc_little_endian, [ + grub_cv_target_cc_little_endian=no + for cand in "-target $target_cpu -Wl,-EL" "-target $target_cpu" \ + "-target $target_cpu-linux-gnu -Wl,-EL" "-target $target_cpu-linux-gnu" \ + "-mlittle-endian"; do + if test x"$grub_cv_target_cc_little_endian" != xno ; then + break + fi + CFLAGS="$TARGET_CFLAGS $cand -Werror" + AC_LINK_IFELSE([AC_LANG_PROGRAM([[ +#if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__ORDER_BIG_ENDIAN__ == __BYTE_ORDER__) +#error still big endian +#endif +asm (".globl start; start:"); +asm (".globl _start; _start:"); +asm (".globl __start; __start:"); +void __main (void); +void __main (void) {} +int main (void); +]], [[]])], + [grub_cv_target_cc_little_endian="$cand"], []) + done + ]) + + if test x"$grub_cv_target_cc_little_endian" = xno ; then + AC_MSG_ERROR([could not force little-endian]) + fi + + skip_linkflags="$(echo "$grub_cv_target_cc_little_endian"|sed 's@-Wl,-EL@@')" + + TARGET_CFLAGS="$TARGET_CFLAGS $skip_linkflags" + TARGET_CPPFLAGS="$TARGET_CPPFLAGS $skip_linkflags" + TARGET_CCASFLAGS="$TARGET_CCASFLAGS $skip_linkflags" + TARGET_LDFLAGS="$TARGET_LDFLAGS $grub_cv_target_cc_little_endian" fi AC_CACHE_CHECK([for options to compile assembly], [grub_cv_cc_target_asm_compile], [ -- 1.9.1 --------------030704020200070700060604 Content-Type: text/x-patch; name="0002-configure-try-to-force-o32-ABI-on-MIPS.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0002-configure-try-to-force-o32-ABI-on-MIPS.patch" >From b69cb301dca85c60b25f0118e5532a2b12f7bae6 Mon Sep 17 00:00:00 2001 From: Andrei Borzenkov Date: Sun, 13 Sep 2015 16:51:13 +0300 Subject: [PATCH 2/2] configure: try to force o32 ABI on MIPS GRUB expects o32 ABI, in particular used assembly is valid only in this mode. Some systems (e.g. GNU Guix) default to using newer n64 or n32 ABI. Try to find suitable options to force o32. For GCC this is simply -mabi=32. While clang supports this option as well, o32 ABI is valid for MIPS target and n32/64 ABI are valid for MIPS64 target only, so use "-target mips/mipsel -mabi=32". Reported-By: Mark H Weaver Also-By: Mark H Weaver --- configure.ac | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/configure.ac b/configure.ac index 4760fe8..7b4e5bc 100644 --- a/configure.ac +++ b/configure.ac @@ -634,6 +634,37 @@ int main (void); TARGET_LDFLAGS="$TARGET_LDFLAGS $grub_cv_target_cc_little_endian" fi +if test "x$target_cpu" = xmips || test "x$target_cpu" = xmipsel ; then + AC_CACHE_CHECK([for options to force MIPS o32 ABI], grub_cv_target_cc_mips_o32_abi, [ + grub_cv_target_cc_mips_o32_abi=no + for arg in "" "-mabi=32" "-target $target_cpu -mabi=32" ; do + if test x"$grub_cv_target_cc_mips_o32_abi" != xno ; then + break + fi + CFLAGS="$TARGET_CFLAGS $arg -Werror" + AC_LINK_IFELSE([AC_LANG_PROGRAM([[ +#if !defined(_ABIO32) || !defined(_MIPS_SIM) || (_MIPS_SIM != _ABIO32) +#error not o32 ABI +#endif +asm (".globl start; start:"); +asm (".globl _start; _start:"); +asm (".globl __start; __start:"); +void __main (void); +void __main (void) {} +int main (void); +]], [[]])], + [grub_cv_target_cc_mips_o32_abi="$arg"], []) + done + ]) + + if test x"$grub_cv_target_cc_mips_o32_abi" = xno ; then + AC_MSG_ERROR([could not force MIPS o32 ABI]) + fi + + TARGET_CFLAGS="$TARGET_CFLAGS $grub_cv_target_cc_mips_o32_abi" + TARGET_CCASFLAGS="$TARGET_CCASFLAGS $grub_cv_target_cc_mips_o32_abi" +fi + AC_CACHE_CHECK([for options to compile assembly], [grub_cv_cc_target_asm_compile], [ test_program= case "x$target_cpu-$platform" in -- 1.9.1 --------------030704020200070700060604--