[IRIX 6] Fixes to ABI and ISA handling
Rainer Orth
ro@TechFak.Uni-Bielefeld.DE
Wed Dec 30 15:13:00 GMT 1998
egcs 1.1.1 on IRIX 6.2 generates N64 ABI object files and executables for
the mips3 instruction set architecture (ISA), instead of mips4 as the
MIPSpro 7.2 compilers do and SGI documents in it's abi(5) man page:
N64 Information
The N64 ABI supports the mips4 (by default) and mips3 ISA's. The
resulting program binary is in ELF64 format whose symbol table is in
DWARF format.
As one can see from the following compilation of a simple program, the
compiler defaults to mips3 (-D_MIPS_ISA=_MIPS_ISA_MIPS3 -D__mips=3):
gcc -save-temps -v -mabi=64 -o hello hello.c
Reading specs from /vol/egcs/lib/gcc-lib/mips-sgi-irix6.2/egcs-2.91.60/specs
gcc version egcs-2.91.60 19981201 (egcs-1.1.1 release)
/vol/egcs/lib/gcc-lib/mips-sgi-irix6.2/egcs-2.91.60/cpp -lang-c -v -undef -D__GNUC__=2 -D__GNUC_MINOR__=91 -Dunix -Dmips -Dsgi -Dhost_mips -DMIPSEB -D_MIPSEB -DSYSTYPE_SVR4 -D_LONGLONG -D_SVR4_SOURCE -D_MODERN_C -D__DSO__ -D__unix__ -D__mips__ -D__sgi__ -D__host_mips__ -D__MIPSEB__ -D_MIPSEB -D__SYSTYPE_SVR4__ -D_LONGLONG -D_SVR4_SOURCE -D_MODERN_C -D__DSO__ -D__unix -D__mips -D__sgi -D__host_mips -D__MIPSEB -D__SYSTYPE_SVR4 -Asystem(unix) -Asystem(svr4) -Acpu(mips) -Amachine(sgi) -D__CHAR_UNSIGNED__ -D__LANGUAGE_C -D_LANGUAGE_C -DLANGUAGE_C -D__SIZE_TYPE__=long unsigned int -D__PTRDIFF_TYPE__=long int -D__LONG_MAX__=9223372036854775807L -D__EXTENSIONS__ -D_SGI_SOURCE -D_MIPS_FPSET=32 -D_MIPS_ISA=_MIPS_ISA_MIPS3 -D_ABI64=3 -D_MIPS_SIM=_ABI64 -D_MIPS_SZINT=32 -D_MIPS_SZLONG=64 -D_MIPS_SZPTR=64 -D_COMPILER_VERSION=601 -U__mips -D__mips=3 -D__mips64 hello.c hello.i
GNU CPP version egcs-2.91.60 19981201 (egcs-1.1.1 release) [AL 1.1, MM 40] SGI running IRIX 6.x
#include "..." search starts here:
#include <...> search starts here:
/vol/egcs/include
/vol/egcs/share/mips-sgi-irix6.2/include
/vol/egcs/lib/gcc-lib/mips-sgi-irix6.2/egcs-2.91.60/include
/usr/include
End of search list.
/vol/egcs/lib/gcc-lib/mips-sgi-irix6.2/egcs-2.91.60/cc1 hello.i -quiet -dumpbase hello.c -mabi=64 -version -o hello.s
GNU C version egcs-2.91.60 19981201 (egcs-1.1.1 release) (mips-sgi-irix6.2) compiled by GNU C version egcs-2.91.60 19981201 (egcs-1.1.1 release).
/usr/bin/as -g0 -64 -nocpp -show -G 0 -w -o hello.o hello.s
/usr/bin/../lib32/cmplrs/as -g0 -64 -nocpp -show -G 0 -w -o hello.o hello.s
/usr/lib32/cmplrs/asm -EB -pic2 -elf -g0 -G0 -w -mips4 -64 -O0 -t5_ll_sc_bug hello.s -o hello.o
/vol/egcs/lib/gcc-lib/mips-sgi-irix6.2/egcs-2.91.60/collect2 -call_shared -no_unresolved -init __do_global_ctors -fini __do_global_dtors -_SYSTYPE_SVR4 -woff 131 -64 -o hello /usr/lib64/mips3/crt1.o /vol/egcs/lib/gcc-lib/mips-sgi-irix6.2/egcs-2.91.60/mabi=64/crtbegin.o -L/vol/egcs/lib/gcc-lib/mips-sgi-irix6.2/egcs-2.91.60/mabi=64 -L/vol/egcs/lib/gcc-lib/mips-sgi-irix6.2/egcs-2.91.60 -L/vol/egcs/share/mips-sgi-irix6.2/lib/mabi=64 -L/vol/egcs/share/mips-sgi-irix6.2/lib -L/usr/bin -L/vol/egcs/lib/mabi=64 -L/vol/egcs/lib hello.o -dont_warn_unused -lgcc -warn_unused -L/usr/lib64/mips3 -L/usr/lib64 -dont_warn_unused -lc -warn_unused -dont_warn_unused -lgcc -warn_unused /vol/egcs/lib/gcc-lib/mips-sgi-irix6.2/egcs-2.91.60/mabi=64/crtend.o /usr/lib64/mips3/crtn.o
The resulting object file and executable are marked as mips4 nontheless,
since the assembler is invoked simply with `as -64' and defaults to mips4,
while the compiler driver links mips3 versions of several libraries and
runtime files:
file hello.o hello
hello.o: ELF 64-bit MSB mips-4 relocatable MIPS - version 1
hello: ELF 64-bit MSB mips-4 dynamic executable (not stripped) MIPS - version 1
The following patch (relative to to the current CVS version) fixes this
inconsistency and in addition handles possible combinations of -mipsX
without -mabi=X and vice versa, as mentioned in several ??? comments in
config/mips/iris6.h.
Beyond that, it already includes the necessary spec support to handle
-mabi=32, too. I include this because the various changes are so
intertwined that it would be quite difficult to separate them for now.
They are unlikely to hurt since -mabi=32 is currently rejected by mips.c
(override_options).
I had an almost working version of O32 ABI support on IRIX 6 for gcc 2.8.1,
which I plan to update for egcs and finish in the foreseeable future. The
necessary changes will follow once they are tested.
While checking all possible combinations of -mabi=X and -mipsX, I noticed
some differences between gcc and MIPSpro 7.2 cc. The following table shows
what my patch implements. In entries with slashes in the gcc column,
before the slash is the behaviour implemented by the spec, after is what
mips.c does. The entries with exclamation marks show behaviour differing
from cc, as discussed below.
options gcc cc
ISA ABI
none mips3 n32
-mabi=32 mips2/1 o32 !mips2 (1)
-mabi=n32 mips3 n32
-mabi=64 mips4 n64
-mips1 mips1 o32
-mips2 mips2 o32
-mips3 mips3 n32/n64 !n64 (2)
-mips4 mips4 n32/n64 !n64 (2)
-mabi=32 -mips1 mips1 o32
-mabi=32 -mips2 mips2 o32
-mabi=32 -mips3 *error* !*warning* (3)
-mabi=32 -mips4 *error*
-mabi=n32 -mips1 *error* !mips3 (4)
-mabi=n32 -mips2 *error* !mips3 (4)
-mabi=n32 -mips3 mips3 n32
-mabi=n32 -mips4 mips4 n32
-mabi=64 -mips1 *error* !mips4 (5)
-mabi=64 -mips2 *error* !mips4 (5)
-mabi=64 -mips3 mips3 n64
-mabi=64 -mips4 mips4 n64
* -mabi=32 only (1):
override_options() defaults to mips1 here (as the IRIX 5 support did),
contrary to cc, which uses mips2. Which default is correct?
* -mips3/-mips4 only (2):
override_options() defaults to n64 here, whereas cc uses n32. This is
probably a leftover from the original IRIX 6.0 port (IRIX 6.0 only
supported o32 and n64) which should probably be fixed by now. Otherwise
the spec could explicitly pass in -mabi=n32 here.
* -mabi=32 -mips3 (3):
cc: Warning: -mips3 should not be used for ucode 32-bit compiles
cc1: -mabi=32 does not support -mips3
I don't know if the mips backend really doesn't support o32 with mips3.
Maybe the check in mips.c (override_options) should be changed into a
warning instead of an error?
* -mabi=n32 -mips1/2 (4):
cc WARNING: ABI specification -n32 conflicts with ISA specification -mips1: defaulting ISA to mips3
cc1: -mabi=n32 does not support -mips1
* -mabi=64 -mips1/2 (5):
cc WARNING: ABI specification -64 conflicts with ISA specification -mips1: defaulting ISA to mips4
cc1: -mabi=64 does not support -mips1
cc1: Only MIPS-III or MIPS-IV CPUs can support 64 bit longs
While cc in all four cases simply emits a warning and defaults to the
default ISA corresponding to the specified ABI, gcc gives an error and
stops. That behaviour is probably preferable to guard against user error.
Wed Dec 30 21:56:22 1998 Rainer Orth <ro@TechFak.Uni-Bielefeld.DE>
* config/mips/iris6.h (SUBTARGET_CPP_SPEC, STARTFILE_SPEC,
LIB_SPEC, ENDFILE_SPEC, LINK_SPEC): Default to mips4 ISA for N64
ABI. Properly handle combinations of -mipsX without -mabi=X and
vice versa. Initial spec support to bring -mabi=32 back.
Index: iris6.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/config/mips/iris6.h,v
retrieving revision 1.14
diff -u -p -r1.14 iris6.h
--- iris6.h 1998/12/16 21:09:10 1.14
+++ iris6.h 1998/12/30 22:08:41
@@ -58,13 +58,6 @@ Boston, MA 02111-1307, USA. */
%{!mabi*: -D__SIZE_TYPE__=unsigned\\ int -D__PTRDIFF_TYPE__=int}"
/* We must make -mips3 do what -mlong64 used to do. */
-/* ??? If no mipsX option given, but a mabi=X option is, then should set
- _MIPS_ISA based on the mabi=X option. */
-/* ??? If no mabi=X option give, but a mipsX option is, then should set
- _MIPS_SIM based on the mipsX option. */
-/* ??? Same for _MIPS_SZINT. */
-/* ??? Same for _MIPS_SZPTR. */
-/* ??? Same for __SIZE_TYPE and __PTRDIFF_TYPE. */
#undef SUBTARGET_CPP_SPEC
#define SUBTARGET_CPP_SPEC "\
%{!ansi:-D__EXTENSIONS__ -D_SGI_SOURCE} \
@@ -73,11 +66,19 @@ Boston, MA 02111-1307, USA. */
%{mips2: -D_MIPS_ISA=_MIPS_ISA_MIPS2} \
%{mips3: -D_MIPS_ISA=_MIPS_ISA_MIPS3} \
%{mips4: -D_MIPS_ISA=_MIPS_ISA_MIPS4} \
-%{!mips*: -D_MIPS_ISA=_MIPS_ISA_MIPS3} \
+%{!mips*: \
+ %{mabi=32: -D_MIPS_ISA=_MIPS_ISA_MIPS2} \
+ %{!mabi=32: \
+ %{mabi=64: -D_MIPS_ISA=_MIPS_ISA_MIPS4} \
+ %{!mabi=64: -D_MIPS_ISA=_MIPS_ISA_MIPS3}}} \
%{mabi=32: -D_MIPS_SIM=_MIPS_SIM_ABI32} \
%{mabi=n32: -D_ABIN32=2 -D_MIPS_SIM=_ABIN32} \
%{mabi=64: -D_ABI64=3 -D_MIPS_SIM=_ABI64} \
-%{!mabi*: -D_ABIN32=2 -D_MIPS_SIM=_ABIN32} \
+%{!mabi*: \
+ %{mips1: -D_MIPS_SIM=_MIPS_SIM_ABI32} \
+ %{!mips1: \
+ %{mips2: -D_MIPS_SIM=_MIPS_SIM_ABI32} \
+ %{!mips2: -D_ABIN32=2 -D_MIPS_SIM=_ABIN32}}} \
%{!mint64: -D_MIPS_SZINT=32}%{mint64: -D_MIPS_SZINT=64} \
%{mabi=32: -D_MIPS_SZLONG=32} \
%{mabi=n32: -D_MIPS_SZLONG=32} \
@@ -88,11 +89,19 @@ Boston, MA 02111-1307, USA. */
%{mabi=64: -D_MIPS_SZPTR=64} \
%{!mabi*: -D_MIPS_SZPTR=32} \
%{!mips1:%{!mips2: -D_COMPILER_VERSION=601}} \
-%{!mips*: -U__mips -D__mips=3} \
+%{!mips*: -U__mips \
+ %{mabi=32: -D__mips=2} \
+ %{!mabi=32: \
+ %{mabi=64: -D__mips=4} \
+ %{!mabi=64: -D__mips=3}}} \
%{mabi=32: -U__mips64} \
%{mabi=n32: -D__mips64} \
%{mabi=64: -D__mips64} \
-%{!mabi*: -D__mips64}"
+%{!mabi*: \
+ %{mips1: -U__mips64} \
+ %{!mips1: \
+ %{mips2: -U__mips64} \
+ %{!mips2: -D__mips64}}}"
/* Irix 6 uses DWARF-2. */
#define DWARF2_DEBUGGING_INFO
@@ -459,8 +468,6 @@ do { \
? "$" : ".")
/* Profiling is supported via libprof1.a not -lc_p as in Irix 3. */
-/* ??? If no mabi=X option give, but a mipsX option is, then should depend
- on the mipsX option. */
#undef STARTFILE_SPEC
#define STARTFILE_SPEC \
"%{!static:%{!shared: \
@@ -474,19 +481,25 @@ do { \
%{!pg:%{p:/usr/lib32/mips3/mcrt1.o%s /usr/lib32/mips3/libprof1.a%s} \
%{!p:/usr/lib32/mips3/crt1.o%s}}}} \
%{mabi=64: \
- %{mips4:%{pg:/usr/lib64/mips4/gcrt1.o} \
- %{!pg:%{p:/usr/lib64/mips4/mcrt1.o /usr/lib64/mips4/libprof1.a} \
- %{!p:/usr/lib64/mips4/crt1.o}}} \
- %{!mips4:%{pg:/usr/lib64/mips3/gcrt1.o} \
+ %{mips3:%{pg:/usr/lib64/mips3/gcrt1.o} \
%{!pg:%{p:/usr/lib64/mips3/mcrt1.o /usr/lib64/mips3/libprof1.a} \
- %{!p:/usr/lib64/mips3/crt1.o}}}} \
+ %{!p:/usr/lib64/mips3/crt1.o}}} \
+ %{!mips3:%{pg:/usr/lib64/mips4/gcrt1.o} \
+ %{!pg:%{p:/usr/lib64/mips4/mcrt1.o /usr/lib64/mips4/libprof1.a} \
+ %{!p:/usr/lib64/mips4/crt1.o}}}} \
%{!mabi*: \
- %{mips4:%{pg:/usr/lib32/mips4/gcrt1.o%s} \
- %{!pg:%{p:/usr/lib32/mips4/mcrt1.o%s /usr/lib32/mips4/libprof1.a%s} \
- %{!p:/usr/lib32/mips4/crt1.o%s}}} \
- %{!mips4:%{pg:/usr/lib32/mips3/gcrt1.o%s} \
- %{!pg:%{p:/usr/lib32/mips3/mcrt1.o%s /usr/lib32/mips3/libprof1.a%s} \
- %{!p:/usr/lib32/mips3/crt1.o%s}}}}}} \
+ %{mips1: %{pg:gcrt1.o%s} \
+ %{!pg:%{p:mcrt1.o%s libprof1.a%s}%{!p:crt1.o%s}}} \
+ %{!mips1: \
+ %{mips2: %{pg:gcrt1.o%s} \
+ %{!pg:%{p:mcrt1.o%s libprof1.a%s}%{!p:crt1.o%s}}} \
+ %{!mips2: \
+ %{mips4:%{pg:/usr/lib32/mips4/gcrt1.o%s} \
+ %{!pg:%{p:/usr/lib32/mips4/mcrt1.o%s /usr/lib32/mips4/libprof1.a%s} \
+ %{!p:/usr/lib32/mips4/crt1.o%s}}} \
+ %{!mips4:%{pg:/usr/lib32/mips3/gcrt1.o%s} \
+ %{!pg:%{p:/usr/lib32/mips3/mcrt1.o%s /usr/lib32/mips3/libprof1.a%s} \
+ %{!p:/usr/lib32/mips3/crt1.o%s}}}}}} \
%{static: \
%{mabi=32:%{pg:/usr/lib/nonshared/gcrt1.o%s} \
%{!pg:%{p:/usr/lib/nonshared/mcrt1.o%s /usr/lib/nonshared/libprof1.a%s} \
@@ -501,35 +514,48 @@ do { \
/usr/lib32/mips3/nonshared/libprof1.a%s} \
%{!p:/usr/lib32/mips3/nonshared/crt1.o%s}}}} \
%{mabi=64: \
- %{mips4:%{pg:/usr/lib64/mips4/nonshared/gcrt1.o} \
- %{!pg:%{p:/usr/lib64/mips4/nonshared/mcrt1.o \
- /usr/lib64/mips4/nonshared/libprof1.a} \
- %{!p:/usr/lib64/mips4/nonshared/crt1.o}}} \
- %{!mips4:%{pg:/usr/lib64/mips3/nonshared/gcrt1.o} \
+ %{mips3:%{pg:/usr/lib64/mips3/nonshared/gcrt1.o} \
%{!pg:%{p:/usr/lib64/mips3/nonshared/mcrt1.o \
/usr/lib64/mips3/nonshared/libprof1.a} \
- %{!p:/usr/lib64/mips3/nonshared/crt1.o}}}} \
+ %{!p:/usr/lib64/mips3/nonshared/crt1.o}}} \
+ %{!mips3:%{pg:/usr/lib64/mips4/nonshared/gcrt1.o} \
+ %{!pg:%{p:/usr/lib64/mips4/nonshared/mcrt1.o \
+ /usr/lib64/mips4/nonshared/libprof1.a} \
+ %{!p:/usr/lib64/mips4/nonshared/crt1.o}}}} \
%{!mabi*: \
- %{mips4:%{pg:/usr/lib32/mips4/nonshared/gcrt1.o%s} \
- %{!pg:%{p:/usr/lib32/mips4/nonshared/mcrt1.o%s \
- /usr/lib32/mips4/nonshared/libprof1.a%s} \
- %{!p:/usr/lib32/mips4/nonshared/crt1.o%s}}} \
- %{!mips4:%{pg:/usr/lib32/mips3/nonshared/gcrt1.o%s} \
- %{!pg:%{p:/usr/lib32/mips3/nonshared/mcrt1.o%s \
- /usr/lib32/mips3/nonshared/libprof1.a%s} \
- %{!pg:%{p:/usr/lib32/mips3/nonshared/mcrt1.o%s \
- /usr/lib32/mips3/nonshared/libprof1.a%s} \
- %{!p:/usr/lib32/mips3/nonshared/crt1.o%s}}}}}} \
+ %{mips1: %{pg:/usr/lib/nonshared/gcrt1.o%s} \
+ %{!pg:%{p:/usr/lib/nonshared/mcrt1.o%s /usr/lib/nonshared/libprof1.a%s} \
+ %{!p:/usr/lib/nonshared/crt1.o%s}}} \
+ %{!mips1: \
+ %{mips2: %{pg:/usr/lib/nonshared/gcrt1.o%s} \
+ %{!pg:%{p:/usr/lib/nonshared/mcrt1.o%s /usr/lib/nonshared/libprof1.a%s} \
+ %{!p:/usr/lib/nonshared/crt1.o%s}}} \
+ %{!mips2: \
+ %{mips4:%{pg:/usr/lib32/mips4/nonshared/gcrt1.o%s} \
+ %{!pg:%{p:/usr/lib32/mips4/nonshared/mcrt1.o%s \
+ /usr/lib32/mips4/nonshared/libprof1.a%s} \
+ %{!p:/usr/lib32/mips4/nonshared/crt1.o%s}}} \
+ %{!mips4:%{pg:/usr/lib32/mips3/nonshared/gcrt1.o%s} \
+ %{!pg:%{p:/usr/lib32/mips3/nonshared/mcrt1.o%s \
+ /usr/lib32/mips3/nonshared/libprof1.a%s} \
+ %{!pg:%{p:/usr/lib32/mips3/nonshared/mcrt1.o%s \
+ /usr/lib32/mips3/nonshared/libprof1.a%s} \
+ %{!p:/usr/lib32/mips3/nonshared/crt1.o%s}}}}}}}}}} \
crtbegin.o%s"
#undef LIB_SPEC
#define LIB_SPEC \
"%{mabi=n32: %{mips4:-L/usr/lib32/mips4} %{!mips4:-L/usr/lib32/mips3} \
-L/usr/lib32} \
- %{mabi=64: %{mips4:-L/usr/lib64/mips4} %{!mips4:-L/usr/lib64/mips3} \
+ %{mabi=64: %{mips3:-L/usr/lib64/mips3} %{!mips3:-L/usr/lib64/mips4} \
-L/usr/lib64} \
- %{!mabi*: %{mips4:-L/usr/lib32/mips4} %{!mips4:-L/usr/lib32/mips3} \
- -L/usr/lib32} \
+ %{!mabi*: \
+ %{mips1: } \
+ %{!mips1: \
+ %{mips2: } \
+ %{!mips2: \
+ %{mips4:-L/usr/lib32/mips4} %{!mips4:-L/usr/lib32/mips3} \
+ -L/usr/lib32}}} \
%{!shared: \
-dont_warn_unused %{p:libprof1.a%s}%{pg:libprof1.a%s} -lc -warn_unused}"
@@ -537,8 +563,6 @@ do { \
#undef LIBGCC_SPEC
#define LIBGCC_SPEC "-dont_warn_unused -lgcc -warn_unused"
-/* ??? If no mabi=X option give, but a mipsX option is, then should depend
- on the mipsX option. */
#undef ENDFILE_SPEC
#define ENDFILE_SPEC \
"crtend.o%s \
@@ -546,13 +570,16 @@ do { \
%{mabi=32:crtn.o%s}\
%{mabi=n32:%{mips4:/usr/lib32/mips4/crtn.o%s}\
%{!mips4:/usr/lib32/mips3/crtn.o%s}}\
- %{mabi=64:%{mips4:/usr/lib64/mips4/crtn.o%s}\
- %{!mips4:/usr/lib64/mips3/crtn.o%s}}\
- %{!mabi*:%{mips4:/usr/lib32/mips4/crtn.o%s}\
- %{!mips4:/usr/lib32/mips3/crtn.o%s}}}"
+ %{mabi=64:%{mips3:/usr/lib64/mips3/crtn.o%s}\
+ %{!mips3:/usr/lib64/mips4/crtn.o%s}}\
+ %{!mabi*:\
+ %{mips1:crtn.o%s}\
+ %{!mips1:\
+ %{mips2:crtn.o%s}\
+ %{!mips2:\
+ %{mips4:/usr/lib32/mips4/crtn.o%s}\
+ %{!mips4:/usr/lib32/mips3/crtn.o%s}}}}}"
-/* ??? If no mabi=X option give, but a mipsX option is, then should depend
- on the mipsX option. */
#undef LINK_SPEC
#define LINK_SPEC "\
%{G*} %{EB} %{EL} %{mips1} %{mips2} %{mips3} %{mips4} \
@@ -563,5 +590,12 @@ do { \
%{!shared: %{!non_shared: %{!call_shared: -call_shared -no_unresolved}}}} \
%{rpath} -init __do_global_ctors -fini __do_global_dtors \
%{shared:-hidden_symbol __do_global_ctors,__do_global_dtors,__EH_FRAME_BEGIN__,__frame_dummy} \
--_SYSTYPE_SVR4 -woff 131 \
-%{mabi=32: -32}%{mabi=n32: -n32}%{mabi=64: -64}%{!mabi*: -n32}"
+-_SYSTYPE_SVR4 \
+%{mabi=32: -32}\
+%{mabi=n32: -n32}\
+%{mabi=64: -64}\
+%{!mabi*: \
+ %{mips1: -32}\
+ %{!mips1: \
+ %{mips2: -32}\
+ %{!mips2: -n32}}}"
-----------------------------------------------------------------------------
Rainer Orth, Technical Faculty, University of Bielefeld
Internet: ro@TechFak.Uni-Bielefeld.DE
More information about the Gcc-patches
mailing list