From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1ZaPuS-0003u8-FJ for mharc-grub-devel@gnu.org; Fri, 11 Sep 2015 11:06:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37540) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZaPuP-0003tu-IU for grub-devel@gnu.org; Fri, 11 Sep 2015 11:06:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZaPuK-0003dh-Jx for grub-devel@gnu.org; Fri, 11 Sep 2015 11:06:37 -0400 Received: from mail-la0-x233.google.com ([2a00:1450:4010:c03::233]:33536) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZaPuK-0003b9-3r for grub-devel@gnu.org; Fri, 11 Sep 2015 11:06:32 -0400 Received: by lamp12 with SMTP id p12so49036253lam.0 for ; Fri, 11 Sep 2015 08:06:30 -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=BZwMvxJwaBvcsyfID3vhaI38VP7HU0o6Rt63Q2NBA20=; b=VvKW4id2fgF65ErasbrWYJH+T/gM/i7gu+8FTrfi9H6NZE/az15TuUjTRWSD6Mj+xd VD04EFC2y3AvL/ptBzvbUMNsAJfgUzF4/UsTkjJtf65rWVeH1Voe1Z1zFQ4RlvkvUWNG 4gbPewDZ6FJZu/Re6LGVVHghKOnFZ3+AXwEJVX/RuS3UwVTcZ7O5Enf0JVymtmYnxDa7 xNy3pkqFJTtEPYj1rbe+FzYtKVV2AYh/MtEoaQ8x4Ll23rB3MIN7Ki5u9EPFCQJ4ZyCC gEVc5S19s6ObiJHu7O9nggPcbJc+OY805D3BuHe3PoeoQw6dAoOOkPFRoWHv23R7Dnv/ ohaQ== X-Received: by 10.152.22.164 with SMTP id e4mr7936333laf.40.1441983990783; Fri, 11 Sep 2015 08:06:30 -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 n9sm109533lbs.28.2015.09.11.08.06.29 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Sep 2015 08:06:29 -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> From: Andrei Borzenkov Message-ID: <55F2EDF4.4040207@gmail.com> Date: Fri, 11 Sep 2015 18:06:28 +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: <87mvxfp6y8.fsf@netris.org> Content-Type: multipart/mixed; boundary="------------080805020605000403070106" X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c03::233 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: Fri, 11 Sep 2015 15:06:39 -0000 This is a multi-part message in MIME format. --------------080805020605000403070106 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 25.08.2015 21:18, Mark H Weaver пишет: > Andrei Borzenkov writes: > >> 24.08.2015 11:12, Andrei Borzenkov пишет: >>> Could you test attached patch for both gcc and clang? Use >>> >>> configure TARGET_CC=clang >> >> Sorry, was broken, fixed version attached. > > 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. > Here's the relevant excerpt: > > --8<---------------cut here---------------start------------->8--- > configure:24700: gcc -o conftest -Os -Wall -W -Wshadow -Wpointer-arith -Wundef -Wchar-subscripts -Wcomment -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wfloat-equal -Wformat-extra-args -Wformat-security -Wformat-y2k -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Wmain -Wmissing-braces -Wmissing-format-attribute -Wmultichar -Wparentheses -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wswitch -Wtrigraphs -Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value -Wunused-variable -Wwrite-strings -Wnested-externs -Wstrict-prototypes -g -Wredundant-decls -Wmissing-prototypes -Wmissing-declarations -Wcast-align -Wextra -Wattributes -Wendif-labels -Winit-self -Wint-to-pointer-cast -Winvalid-pch -Wmissing-field-initializers -Wnonnull -Woverflow -Wvla -Wpointer-to-int-cast -Wstrict-aliasing -Wvariadic-macros -Wvolatile-register-var -Wpointer-sign -Wmissing-include-dirs -Wmissing-prototypes -Wmissing-declarations -Wformat=2 -mabi=32 -Werror -Wall -W -DGRUB_CPU_MIPSEL=1 -DGRUB_MACHINE_MIPS_LOONGSON=1 -DGRUB_MACHINE=MIPS_LOONGSON -nostdlib -static conftest.c >&5 > ld: warning: cannot find entry symbol __start; defaulting to 00000000004000d0 > configure:24700: $? = 0 > configure:24708: result: -mabi=32 > --8<---------------cut here---------------end--------------->8--- > > 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? > clang: with TARGET_CC=clang, it fails for me. Here are the > relevant excerpts from config.log: > > --8<---------------cut here---------------start------------->8--- > configure:24700: /gnu/store/yjmchvkz0kmz4s1sxc0p89imfik68qzg-clang-3.6.0/bin/clang -o conftest -Os -Wall -W -Wshadow -Wpointer-arith -Wundef -Wchar-subscripts -Wcomment -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wfloat-equal -Wformat-extra-args -Wformat-security -Wformat-y2k -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Wmain -Wmissing-braces -Wmissing-format-attribute -Wmultichar -Wparentheses -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wswitch -Wtrigraphs -Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value -Wunused-variable -Wwrite-strings -Wnested-externs -Wstrict-prototypes -g -Wredundant-decls -Wmissing-prototypes -Wmissing-declarations -Wcast-align -Wextra -Wattributes -Wendif-labels -Winit-self -Wint-to-pointer-cast -Winvalid-pch -Wmissing-field-initializers -Wnonnull -Woverflow -Wvla -Wpointer-to-int-cast -Wstrict-aliasing -Wvariadic-macros -Wvolatile-register-var -Wpointer-sign -Wmis sing-include-dirs -Wmissing-prototypes -Wmissing-declarations -Wformat=2 -mabi=32 -Werror -Wall -W -DGRUB_CPU_MIPSEL=1 -DGRUB_MACHINE_MIPS_LOONGSON=1 -DGRUB_MACHINE=MIPS_LOONGSON -nostdlib -static conftest.c >&5 > error: unknown target CPU 'mips32r2' > configure:24700: $? = 1 > configure: failed program was: > [...] > configure:24700: /gnu/store/yjmchvkz0kmz4s1sxc0p89imfik68qzg-clang-3.6.0/bin/clang -o conftest -Os -Wall -W -Wshadow -Wpointer-arith -Wundef -Wchar-subscripts -Wcomment -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wfloat-equal -Wformat-extra-args -Wformat-security -Wformat-y2k -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Wmain -Wmissing-braces -Wmissing-format-attribute -Wmultichar -Wparentheses -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wswitch -Wtrigraphs -Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value -Wunused-variable -Wwrite-strings -Wnested-externs -Wstrict-prototypes -g -Wredundant-decls -Wmissing-prototypes -Wmissing-declarations -Wcast-align -Wextra -Wattributes -Wendif-labels -Winit-self -Wint-to-pointer-cast -Winvalid-pch -Wmissing-field-initializers -Wnonnull -Woverflow -Wvla -Wpointer-to-int-cast -Wstrict-aliasing -Wvariadic-macros -Wvolatile-register-var -Wpointer-sign -Wmis sing-include-dirs -Wmissing-prototypes -Wmissing-declarations -Wformat=2 -target mips -mabi=32 -Werror -Wall -W -DGRUB_CPU_MIPSEL=1 -DGRUB_MACHINE_MIPS_LOONGSON=1 -DGRUB_MACHINE=MIPS_LOONGSON -nostdlib -static conftest.c >&5 > 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? Although I guess we need to unify endianness checks for all supported platforms. > ld: failed to merge target specific data of file /tmp/conftest-efc530.o > ld: warning: cannot find entry symbol __start; defaulting to 00000000004000f0 > collect2: error: ld returned 1 exit status > clang-3.6: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation) > configure:24700: $? = 1 > configure: failed program was: > [...] > --8<---------------cut here---------------end--------------->8--- > > I guess that "-target mips" is interpreted as requesting big endian. > > I suspect that simply passing -mabi=32 is the right thing to do for > clang as well, but that the clang we have built in GNU Guix doesn't > include support for targetting the O32 ABI. As far as I can tell, clang can enable full platform (i.e. MIPS) but not platform variant. So if clang can compile for MIPS at all it should be able to produce both versions. The problem is, endianness in clang is property of target; and what makes it even worse, options that are passed to backend toolchains are also target dependent. > It's possible that the only > way to target O32 from a non-multilib N32 system using clang is to do > cross-compilation. Or perhaps we need to explicitly request support for > 'mips32r2' when building clang. > > Mark > --------------080805020605000403070106 Content-Type: text/x-patch; name="mips-32.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="mips-32.patch" From: Andrei Borzenkov Subject: [PATCH] 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 | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/configure.ac b/configure.ac index c864311..f3c9b90 100644 --- a/configure.ac +++ b/configure.ac @@ -597,6 +597,35 @@ int main (void); TARGET_LDFLAGS="$TARGET_LDFLAGS $grub_cv_target_cc_big_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:"); +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 -- tg: (8e3d2c8..) u/mips-o32 (depends on: master) --------------080805020605000403070106--