diff mbox

[mips] Patch for new mips triplet - mips-mti-elf

Message ID 3324456b-606c-494e-93ac-2479868f750d@EXCHHUB01.MIPS.com
State New
Headers show

Commit Message

Steve Ellcey Sept. 13, 2012, 5:25 p.m. UTC
Here is a patch to add a new mips*-mti-elf target to GCC.  This is similar
to the mips*-mti-linux-gnu target but for bare metal instead of linux.
The main difference between this new target and the existing mips*-sde-elf
target is that this version does not get built for as many different mips
architectures making the overall GCC build and test process faster and the
resulting cross compiler smaller because there are fewer different runtime
libraries.

I have attached 4 seperate patches because I made changes at the top level,
the top level config directory, the gcc directory, and the gcc test directory.

The top-level change is to not build the gprof directory for mips-mti-elf,
copying what we already do for mips-sde-elf.  The config directory change
is to use -mcode-readable=pcrel instead of -mcode-xonly during compilation.
The flags do the same thing but -mcode-readable=pcrel is the prefered flag
to use and for my new target I have it set up to only understand the new
flag instead of both the old and new flags.  The existing mips-sde-elf target
recognizes both old and new flags so it should not be affected by this
change.  Most of the changes are two new files in the gcc directory for the
new target, and then there is one test that is skipped on mips-sde-elf and I
now skip it for mips-mti-elf too.

For this patch to work I also need a binutils patch which I will submit later
today, it adds the mips*-mti-elf target to binutils as a target that behaves
identically to mips*-sde-elf.

I tested each variation that the new target supports using newlib and the
gnu simulator.  OK to checkin?


Top-level:


2012-09-12  Steve Ellcey  <sellcey@mips.com>

	* configure.ac: Add mips*-mti-elf* target.
	* configure: Regenerate.

Comments

Richard Sandiford Sept. 16, 2012, 8:22 a.m. UTC | #1
"Steve Ellcey " <sellcey@mips.com> writes:
> +#undef SYSROOT_SUFFIX_SPEC
> +#define SYSROOT_SUFFIX_SPEC \
> +    "%{mips32:/mips32}%{mips64:/mips64}%{mips64r2:/mips64r2}%{mips16:/mips16}%{msoft-float:/sof}%{mel|EL:/el}%{mabi=64:/64}%{mabi=n32:/n32}"

This shouldn't be needed for *-elf targets.

> +/* This is idential to sde.h except for the ABI setting which defaults
> +   to 32 instead of n32 on 32 bit architectures and the addition of
> +   MIPS_ISA_SYNCI_SPEC.  */

SDE defaults to o32 (-mabi=32) for 32-bit targets and n32 for 64-bit targets.
I think that's what you'd want here too, otherwise the mips64 multilibs
are really no different from the mips32 ones.

> +  /* Remove a redundant -mfp64 for -mabi=n32; we want the !mfp64	\
> +     multilibs.  There's no need to check whether the architecture	\
> +     is 64-bit; cc1 will complain if it isn't.  */			\
> +  "%{mabi=n32: %<mfp64}",						\

This bit shouldn't be needed, since there are no mfp64 multilibs.

Richard
Steve Ellcey Sept. 17, 2012, 3:43 p.m. UTC | #2
On Sun, 2012-09-16 at 09:22 +0100, Richard Sandiford wrote:

> > +/* This is idential to sde.h except for the ABI setting which defaults
> > +   to 32 instead of n32 on 32 bit architectures and the addition of
> > +   MIPS_ISA_SYNCI_SPEC.  */
> 
> SDE defaults to o32 (-mabi=32) for 32-bit targets and n32 for 64-bit targets.
> I think that's what you'd want here too, otherwise the mips64 multilibs
> are really no different from the mips32 ones.

I am a bit confused about this.  It looks like the current
mips-*-linux-gnu targets default to o32 when compiled for 64-bit targets
but the mips-sde-elf target defaults to n32 when compiled for 64-bit
targets.  I am not sure which default makes more sense but it seems odd
that the two targets have different defaults for the same architecture.
Do you know how the current state of affairs came to be with respect to
this difference in defaults?

Steve Ellcey
sellcey@mips.com
Richard Sandiford Sept. 17, 2012, 8:36 p.m. UTC | #3
Steve Ellcey <sellcey@mips.com> writes:
> On Sun, 2012-09-16 at 09:22 +0100, Richard Sandiford wrote:
>
>> > +/* This is idential to sde.h except for the ABI setting which defaults
>> > +   to 32 instead of n32 on 32 bit architectures and the addition of
>> > +   MIPS_ISA_SYNCI_SPEC.  */
>> 
>> SDE defaults to o32 (-mabi=32) for 32-bit targets and n32 for 64-bit targets.
>> I think that's what you'd want here too, otherwise the mips64 multilibs
>> are really no different from the mips32 ones.
>
> I am a bit confused about this.  It looks like the current
> mips-*-linux-gnu targets default to o32 when compiled for 64-bit targets
> but the mips-sde-elf target defaults to n32 when compiled for 64-bit
> targets.  I am not sure which default makes more sense but it seems odd
> that the two targets have different defaults for the same architecture.
> Do you know how the current state of affairs came to be with respect to
> this difference in defaults?

It's a hosted vs. embedded thing.  Hosted targets like *-linux-gnu have
dynamic ABI requirements and so are keyed off an ABI rather than an
architecture.  The only effect of -march= and --with-arch= should be to
extend the choice of available instructions.

That was actually very useful in pre MIPS(isa)32 and MIPS(isa)64 days,
because MIPS IV had ISA extensions that could be used in 32-bit as well
as 64-bit code.  You could therefore use the MIPS IV extensions with an
existing 32-bit MIPS I or MIPS II sysroot.  The same sort of thing applied
to processor-specific extensions in 64-bit processors (of which there were
many :-)).  It's less useful with the stock MIPS32 and MIPS64 ISAs because
the 32-bit subset of MIPS64 is (by design) essentially MIPS32.

In a hosted environment, if you want a 64-bit toolchain, you need
to use a 64-bit target like mips64-linux-gnu or mipsisa64-linux-gnu.
(Or configure mips-*-linux-gnu with --enable-targets=all and be
prepared to use -mabi=n32.)

In contrast, embedded *-elf targets have only static ABI requirements,
and the runtime libraries are usually built as part of the toolchain.
It's therefore convenient for -march= to select the "best" ABI for
the architecture.

Richard
Steve Ellcey Sept. 17, 2012, 10:40 p.m. UTC | #4
On Mon, 2012-09-17 at 21:36 +0100, Richard Sandiford wrote:

> It's a hosted vs. embedded thing.  Hosted targets like *-linux-gnu have
> dynamic ABI requirements and so are keyed off an ABI rather than an
> architecture.  The only effect of -march= and --with-arch= should be to
> extend the choice of available instructions.
> 
> That was actually very useful in pre MIPS(isa)32 and MIPS(isa)64 days,
> because MIPS IV had ISA extensions that could be used in 32-bit as well
> as 64-bit code.  You could therefore use the MIPS IV extensions with an
> existing 32-bit MIPS I or MIPS II sysroot.  The same sort of thing applied
> to processor-specific extensions in 64-bit processors (of which there were
> many :-)).  It's less useful with the stock MIPS32 and MIPS64 ISAs because
> the 32-bit subset of MIPS64 is (by design) essentially MIPS32.

If this is less useful now and since the multilib mips-mti-linux-gnu
target I created earlier is only supporting the mips32(r2) and
mips64(r2) ISAs (and not MIPS IV, etc) what do you think about me
changing that target to default to n32 when specifying the mips64 or
mips64r2 architectures and not specifying an explicit ABI?  That way
both the mips-mti-linux-gnu and mips-mti-elf targets will behave in the
same way with regards to the default ABI.

Steve Ellcey
sellcey@mips.com
Richard Sandiford Sept. 18, 2012, 7:08 a.m. UTC | #5
Steve Ellcey <sellcey@mips.com> writes:
> On Mon, 2012-09-17 at 21:36 +0100, Richard Sandiford wrote:
>> It's a hosted vs. embedded thing.  Hosted targets like *-linux-gnu have
>> dynamic ABI requirements and so are keyed off an ABI rather than an
>> architecture.  The only effect of -march= and --with-arch= should be to
>> extend the choice of available instructions.
>> 
>> That was actually very useful in pre MIPS(isa)32 and MIPS(isa)64 days,
>> because MIPS IV had ISA extensions that could be used in 32-bit as well
>> as 64-bit code.  You could therefore use the MIPS IV extensions with an
>> existing 32-bit MIPS I or MIPS II sysroot.  The same sort of thing applied
>> to processor-specific extensions in 64-bit processors (of which there were
>> many :-)).  It's less useful with the stock MIPS32 and MIPS64 ISAs because
>> the 32-bit subset of MIPS64 is (by design) essentially MIPS32.
>
> If this is less useful now and since the multilib mips-mti-linux-gnu
> target I created earlier is only supporting the mips32(r2) and
> mips64(r2) ISAs (and not MIPS IV, etc) what do you think about me
> changing that target to default to n32 when specifying the mips64 or
> mips64r2 architectures and not specifying an explicit ABI?  That way
> both the mips-mti-linux-gnu and mips-mti-elf targets will behave in the
> same way with regards to the default ABI.

JFTR, it would be the case even if you did support MIPS IV.  n32 was
the best ABI there too.  My point was that if you only had access to a
32-bit sysroot and/or kernel, compiling for o32 with MIPS IV (i.e. a
64-bit arch) did have something to offer over o32 with the "highest"
32-bit arch (MIPS II).

But yeah, since mips-mti-linux-gnu provides separate multilibs and
sysroots for mips64 and mips64r2, you can define the ABI of those
multilibs and sysroots to be what you like.  And I agree n32 makes sense.
But I think it would be a bad idea simply to add a rule to
DRIVER_SELF_SPECS.  I think you'd also want to make the 64-bit sysroots
"mips64-linux-gnu-style" (i.e. IRIX-6-style) sysroots, with n32 stuff
in /lib32, /usr/lib32, etc., rather than in /lib and /usr/lib.  That way,
your sysroots are compatible with mipsisa64-linux-gnu and
mipsisa63r2-linux-gnu, in case anyone ever does need to build their own
toolchain.  You also won't need to patch glibc for your layout, and
won't confuse package build scripts that expect n32 stuff to be in the
standard locations.  Obviously that'll mean a bit of work in the t-*
makefile fragments though.

Another thing to watch out for is that mips-sde-elf redefines the
n32 ABI so that long double is only 64 bits (i.e. equivalent to double),
not the ABI-prescribed 128 bits.  I think it'd be better to avoid that
change for mips-sti-linux-gnu, for the same reasons as above.

Richard
diff mbox

Patch

diff --git a/configure.ac b/configure.ac
index a6f5828..3ddefdb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1032,7 +1032,7 @@  case "${target}" in
   microblaze*)
     noconfigdirs="$noconfigdirs gprof"
     ;;
-  mips*-sde-elf*)
+  mips*-sde-elf* | mips*-mti-elf*)
     if test x$with_newlib = xyes; then
       noconfigdirs="$noconfigdirs gprof"
     fi
@@ -2251,7 +2251,7 @@  case "${target}" in
   spu-*-*)
     target_makefile_frag="config/mt-spu"
     ;;
-  mips*-sde-elf*)
+  mips*-sde-elf* | mips*-mti-elf*)
     target_makefile_frag="config/mt-sde"
     ;;
   mipsisa*-*-elfoabi*)


===================================================================


2012-09-13  Steve Ellcey  <sellcey@mips.com>

	* mt-sde: Change -mcode-xonly to -mcode-readable=pcrel.


diff --git a/config/mt-sde b/config/mt-sde
index d6992e4..a3fc1e1 100644
--- a/config/mt-sde
+++ b/config/mt-sde
@@ -1,10 +1,10 @@ 
 # We default to building libraries optimised for size.  We use
 # -minterlink-mips16 so that the non-MIPS16 libraries can still be
-# linked against partly-MIPS16 code.  The -mcode-xonly option allows
+# linked against partly-MIPS16 code.  The -mcode-readable=pcrel option allows
 # MIPS16 libraries to run on Harvard-style split I/D memories, so long
 # as they have the D-to-I redirect for PC-relative loads.  -mno-gpopt
 # has two purposes: it allows libraries to be used in situations where
 # $gp != our _gp, and it allows them to be built with -G8 while
 # retaining link compatibility with -G0 and -G4.
-CFLAGS_FOR_TARGET += -Os -minterlink-mips16 -mcode-xonly -mno-gpopt
-CXXFLAGS_FOR_TARGET += -Os -minterlink-mips16 -mcode-xonly -mno-gpopt
+CFLAGS_FOR_TARGET += -Os -minterlink-mips16 -mcode-readable=pcrel -mno-gpopt
+CXXFLAGS_FOR_TARGET += -Os -minterlink-mips16 -mcode-readable=pcrel -mno-gpopt



===================================================================


2012-09-13  Steve Ellcey  <sellcey@mips.com>

	* config.gcc (mips*-mti-elf*): New target.
	* config/mips/mti-elf.h: New file.
	* config/mips/t-mti-elf: New file.


diff --git a/gcc/config.gcc b/gcc/config.gcc
index ba366b3..9f5e170 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -1741,6 +1741,11 @@  mips*-*-linux*)				# Linux MIPS, either endian.
         esac
 	test x$with_llsc != x || with_llsc=yes
 	;;
+mips*-mti-elf*)
+	tm_file="elfos.h newlib-stdint.h ${tm_file} mips/elf.h mips/sde.h mips/mti-elf.h"
+	tmake_file="mips/t-mti-elf"
+	tm_defines="${tm_defines} MIPS_ISA_DEFAULT=33 MIPS_ABI_DEFAULT=ABI_32"
+	;;
 mips*-sde-elf*)
 	tm_file="elfos.h newlib-stdint.h ${tm_file} mips/elf.h mips/sde.h"
 	tmake_file="mips/t-sde"
diff --git a/gcc/config/mips/mti-elf.h b/gcc/config/mips/mti-elf.h
new file mode 100644
index 0000000..229555e
--- /dev/null
+++ b/gcc/config/mips/mti-elf.h
@@ -0,0 +1,56 @@ 
+/* Target macros for mips*-mti-elf targets.
+   Copyright (C) 2012
+   Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+#undef SYSROOT_SUFFIX_SPEC
+#define SYSROOT_SUFFIX_SPEC \
+    "%{mips32:/mips32}%{mips64:/mips64}%{mips64r2:/mips64r2}%{mips16:/mips16}%{msoft-float:/sof}%{mel|EL:/el}%{mabi=64:/64}%{mabi=n32:/n32}"
+
+/* This is idential to sde.h except for the ABI setting which defaults
+   to 32 instead of n32 on 32 bit architectures and the addition of
+   MIPS_ISA_SYNCI_SPEC.  */
+
+#undef DRIVER_SELF_SPECS
+#define DRIVER_SELF_SPECS						\
+  /* Make sure a -mips option is present.  This helps us to pick	\
+     the right multilib, and also makes the later specs easier		\
+     to write.  */							\
+  MIPS_ISA_LEVEL_SPEC,							\
+									\
+  /* Infer the default float setting from -march.  */			\
+  MIPS_ARCH_FLOAT_SPEC,							\
+									\
+  /* Infer the -msynci setting from -march if not explicitly set.  */	\
+  MIPS_ISA_SYNCI_SPEC,							\
+									\
+  /* If no ABI option is specified, infer one from the ISA level	\
+     or -mgp setting.  */						\
+  "%{!mabi=*:-mabi=32}",						\
+									\
+  /* Remove a redundant -mfp64 for -mabi=n32; we want the !mfp64	\
+     multilibs.  There's no need to check whether the architecture	\
+     is 64-bit; cc1 will complain if it isn't.  */			\
+  "%{mabi=n32: %<mfp64}",						\
+									\
+  /* Make sure that an endian option is always present.  This makes	\
+     things like LINK_SPEC easier to write.  */				\
+  "%{!EB:%{!EL:%(endian_spec)}}",					\
+									\
+  /* Configuration-independent MIPS rules.  */				\
+  BASE_DRIVER_SELF_SPECS				
diff --git a/gcc/config/mips/t-mti-elf b/gcc/config/mips/t-mti-elf
new file mode 100644
index 0000000..5bc00a9
--- /dev/null
+++ b/gcc/config/mips/t-mti-elf
@@ -0,0 +1,21 @@ 
+# Copyright (C) 2007, 2008, 2011 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+MULTILIB_OPTIONS = EL msoft-float mips32/mips64/mips64r2
+MULTILIB_DIRNAMES = el sof mips32 mips64 mips64r2
+MULTILIB_MATCHES = EL=mel EB=meb


===================================================================


2012-09-13  Steve Ellcey  <sellcey@mips.com>

	* gcc.target/mips/pr37362.c: Add mips*-mti-elf exception.


diff --git a/gcc/testsuite/gcc.target/mips/pr37362.c b/gcc/testsuite/gcc.target/mips/pr37362.c
index a378366..da34b9d 100644
--- a/gcc/testsuite/gcc.target/mips/pr37362.c
+++ b/gcc/testsuite/gcc.target/mips/pr37362.c
@@ -1,5 +1,5 @@ 
 /* mips*-sde-elf doesn't have 128-bit long doubles.  */
-/* { dg-do compile { target { ! mips*-sde-elf } } } */
+/* { dg-do compile { target { ! mips*-sde-elf mips*-mti-elf } } } */
 /* { dg-options "-march=mips64r2 -mabi=n32" } */
 
 typedef float TFtype __attribute__((mode(TF)));