IRIX 4.0.5F crosscompilation adventures

LarBob

Administrator
Feb 8, 2019
51
27
18
Onre and I have been on a journey to crosscompile some cozy little ECOFF executables for our friend 4.0.5F. I have come back to report... success!

Code:
rose:~ larbob$ file /usr/iriscc/local/bin/mips-sgi-irix4-gcc
/usr/iriscc/local/bin/mips-sgi-irix4-gcc: Mach-O executable ppc
rose:~ larbob$ /usr/iriscc/local/bin/mips-sgi-irix4-gcc --version
3.0.4
Onre was able to get GCC 3.0.4 targetting mips-sgi-irix4 built!

We started on my Power Mac G5 for $REASONS, but that was generating a lot of heat in my room, so I found my old copy of Snow Leopard server and installed it on a 2009 MacBook Pro I had lying around. Now we're running a GCC that targets IRIX 4.0.5F and that was compiled for Mac OS X 10.5 PPC on Mac OS X 10.6 x86_64 thanks to the wonders of Rosetta (thanks, Transitive Corporation!).

So far, I've compiled older versions of zsh, gzip, and grep, and they all work fine on my R3k Indigo.

Code:
rose:~ larbob$ file /iris/usr/local/bin/zsh
/iris/usr/local/bin/zsh: MIPSEB ECOFF executable (paged) not stripped - version 2.40
Code:
dionysus% echo $0
./zsh
dionysus% printf "hi\nhello\nhey" > test
dionysus% ./grep -R "hey" .
./test:hey
dionysus% ./gunzip
gunzip: compressed data not read from a terminal. Use -f to force decompression.
For help, type: gunzip -h
And as for building the thing...

The 4.0.5F sysroot folder should contain /lib, /usr/include, and /usr/lib.

Configuring binutils:
Code:
../binutils-2.18/configure --prefix=$HOME/local --target=mips-sgi-irix4 --with-build-sysroot=$HOME/sysroots/irix-4.0.5/
Now, as for configuring the crosscompiler:
Code:
export CC="gcc-3.1 -std=c89"
../gcc-3.0.4/configure --enable-obsolete --prefix=$HOME/local --target=mips-sgi-irix4 --disable-nls --enable-languages=c --with-build-sysroot=$HOME/sysroots/irix-4.0.5 --enable-tls=no --with-stabs --with-gnu-as --with-gnu-ld --with-as=$HOME/local/bin/mips-sgi-irix4-as --with-ld=$HOME/local/bin/mips-sgi-irix4-ld
Onre used a native GCC 3.1 for OS X 10.5 to build GCC 3.0.4 targetting 4.0.5F.
 
Last edited:

Elf

Storybook / Retired, ex-staff
Feb 4, 2019
792
252
63
Mountain West (US)
That's awesome! I need to try IRIX 4.0.5 sometime, especially given the number of Indigo 1s I have sitting around. Very curious how it compares to 5.3. Cross-compiling almost seems necessary at this point given CPU speed and RAM restrictions and the size of "modern" software.
 

LarBob

Administrator
Feb 8, 2019
51
27
18
That's awesome! I need to try IRIX 4.0.5 sometime, especially given the number of Indigo 1s I have sitting around. Very curious how it compares to 5.3. Cross-compiling almost seems necessary at this point given CPU speed and RAM restrictions and the size of "modern" software.
Yeah, I'm building GCC 3.0.4 on the machine right now and it's taking quite a bit of time. :D

It'd be nice to have a multi CPU machine that can run 4.x as well.
 
  • Like
Reactions: Elf

massiverobot

irix detailer
Feb 8, 2019
121
108
43
Philly
twitter.com
What are the multi-cpu options for 4.x ? The crimson was single CPU only... what other big SGI was there at this time?

I'm def intererested in this for my Personal Iris running 4f. Nice work!
 

hbent

New member
Oct 29, 2020
15
7
3
Hi, I know this is an old thread, but I've successfully built gcc 10.2.0 as a cross-compiler to IRIX 4. The patches aren't too difficult, I can post them if someone is interested in them.

Code:
(aelfric:~hbent/dmesg) % mips-sgi-irix4-gcc -v
Using built-in specs.
COLLECT_GCC=mips-sgi-irix4-gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/mips-sgi-irix4/10.2.0/lto-wrapper
Target: mips-sgi-irix4
Configured with: ../configure --target=mips-sgi-irix4 --enable-languages=c --with-gnu-as --with-gnu-ld --disable-libssp --disable-nls --with-stabs
Thread model: single
Supported LTO compression algorithms: zlib zstd
gcc version 10.2.0 (GCC)
This is with binutils 2.23.2. It works pretty well. LTO stuff doesn't actually work (no surprise there) and you don't get any of the fancy stack-smashing protection, but who cares?

I'm running 4.0.5H (with some patches) on an Indigo, you can in theory load 4.0.5H on just about anything if you modify the .idb files.
 
  • Like
Reactions: Elf and foetz

LarBob

Administrator
Feb 8, 2019
51
27
18
Hi, I know this is an old thread, but I've successfully built gcc 10.2.0 as a cross-compiler to IRIX 4. The patches aren't too difficult, I can post them if someone is interested in them.

Code:
(aelfric:~hbent/dmesg) % mips-sgi-irix4-gcc -v
Using built-in specs.
COLLECT_GCC=mips-sgi-irix4-gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/mips-sgi-irix4/10.2.0/lto-wrapper
Target: mips-sgi-irix4
Configured with: ../configure --target=mips-sgi-irix4 --enable-languages=c --with-gnu-as --with-gnu-ld --disable-libssp --disable-nls --with-stabs
Thread model: single
Supported LTO compression algorithms: zlib zstd
gcc version 10.2.0 (GCC)
This is with binutils 2.23.2. It works pretty well. LTO stuff doesn't actually work (no surprise there) and you don't get any of the fancy stack-smashing protection, but who cares?

I'm running 4.0.5H (with some patches) on an Indigo, you can in theory load 4.0.5H on just about anything if you modify the .idb files.
Amazing! I'd appreciate the patches and I'm sure others would too. :D
 
  • Like
Reactions: Elf

hbent

New member
Oct 29, 2020
15
7
3
I am a little hesitant to blindly post patches - if you are doing this, please make an effort to understand what the patches do.

First, copy all of the support files for IRIX 4 from the last GCC distribution that supported it (3.2.3). That would be gcc/config/mips/*iris* if I recall correctly. Then the patches are:

Code:
--- gcc/config.gcc.orig 2020-07-23 02:35:17.316384243 -0400
+++ gcc/config.gcc      2020-11-18 22:24:38.327372656 -0500
@@ -2472,6 +2496,68 @@
        # automatically detect that GAS supports it, yet we require it.
        gcc_cv_initfini_array=yes
        ;;
+mips-sgi-irix4*)                # Mostly like a MIPS.
+        tm_file="mips/iris3.h ${tm_file} mips/iris4.h"
+        if test x$stabs = xyes; then
+                tm_file="${tm_file} dbx.h"
+        fi
+        tmake_file=mips/t-iris
+        xm_defines=POSIX
+        if test x$gas = xyes
+        then    :
+        else
+                extra_passes="mips-tfile mips-tdump"
+        fi
+        if test x$gnu_ld != xyes
+        then
+                use_collect2=yes
+        fi
+#       if test x$enable_threads = xyes; then
+#               thread_file='irix'
+#       fi
+        ;;

bsd*)                       # NetBSD/mips, either endian.
        target_cpu_default="MASK_ABICALLS"

--- gcc/config/mips/mips.c.orig 2020-07-23 02:35:17.424385434 -0400
+++ gcc/config/mips/mips.c      2020-10-12 19:46:48.625369654 -0400
@@ -65,6 +65,8 @@
#include "context.h"
#include "builtins.h"
#include "rtl-iter.h"
+#include "defaults.h"
+#include "dbxout.h"

/* This file should be included last.  */
#include "target-def.h"
@@ -909,7 +911,7 @@
                     6            /* memory_latency */
   },
   { /* R4000 */
-     COSTS_N_INSNS (6),           /* fp_add */
+     COSTS_N_INSNS (4),           /* fp_add */
      COSTS_N_INSNS (7),           /* fp_mult_sf */
      COSTS_N_INSNS (8),           /* fp_mult_df */
      COSTS_N_INSNS (23),          /* fp_div_sf */
@@ -7067,7 +7069,10 @@
       fputs ("\n", asm_out_file);
     }

+/* XXX HRB */
+#ifdef ASM_OUTPUT_TYPE_DIRECTIVE
   ASM_OUTPUT_TYPE_DIRECTIVE (asm_out_file, name, "function");
+#endif

   /* Start the definition proper.  */
   assemble_name (asm_out_file, name);
@@ -9761,7 +9766,7 @@
     }
   else
     mips_declare_common_object (stream, name, "\n\t.comm\t",
-                               size, align, true);
+                               size, align, false);
}

#ifdef ASM_OUTPUT_SIZE_DIRECTIVE
@@ -9891,16 +9896,16 @@
      information in order to correctly debug binaries produced by
      older binutils.  See the function mips_gdbarch_init in
      gdb/mips-tdep.c.  */
-  fprintf (asm_out_file, "\t.section .mdebug.%s\n\t.previous\n",
-          mips_mdebug_abi_name ());
+  /* fprintf (asm_out_file, "\t.section .mdebug.%s\n\t.previous\n",
+          mips_mdebug_abi_name ()); */

   /* There is no ELF header flag to distinguish long32 forms of the
      EABI from long64 forms.  Emit a special section to help tools
      such as GDB.  Do the same for o64, which is sometimes used with
      -mlong64.  */
-  if (mips_abi == ABI_EABI || mips_abi == ABI_O64)
+/*  if (mips_abi == ABI_EABI || mips_abi == ABI_O64)
     fprintf (asm_out_file, "\t.section .gcc_compiled_long%d\n"
-            "\t.previous\n", TARGET_LONG64 ? 64 : 32);
+            "\t.previous\n", TARGET_LONG64 ? 64 : 32); */

   /* Record the NaN encoding.  */

--- gcc/config/mips/mips.h.orig 2020-07-23 02:35:17.424385434 -0400
+++ gcc/config/mips/mips.h      2020-10-12 17:04:59.915528338 -0400
@@ -1417,7 +1417,6 @@
%{mfix-24k} \
%{noasmopt:-O0; O0|fno-delayed-branch:-O1; O*:-O2; :-O1} \
%(subtarget_asm_debugging_spec) \
-%{mabi=*} %{!mabi=*: %(asm_abi_default_spec)} \
%{mgp32} %{mgp64} %{march=*} %{mxgot:-xgot} \
%{mfp32} %{mfpxx} %{mfp64} %{mnan=*} \
%{modd-spreg} %{mno-odd-spreg} \

--- gcc/opts.c  2020-10-12 18:03:19.515222301 -0400
+++ gcc/opts.c.orig     2020-07-23 02:35:17.708388562 -0400
@@ -494,7 +494,7 @@
     { OPT_LEVELS_2_PLUS, OPT_foptimize_sibling_calls, NULL, 1 },
     { OPT_LEVELS_2_PLUS, OPT_fpartial_inlining, NULL, 1 },
     { OPT_LEVELS_2_PLUS, OPT_fpeephole2, NULL, 1 },
-/*    { OPT_LEVELS_2_PLUS, OPT_freorder_functions, NULL, 1 }, */
+    { OPT_LEVELS_2_PLUS, OPT_freorder_functions, NULL, 1 },
     { OPT_LEVELS_2_PLUS, OPT_frerun_cse_after_loop, NULL, 1 },
#ifdef INSN_SCHEDULING
     { OPT_LEVELS_2_PLUS, OPT_fschedule_insns2, NULL, 1 },

--- gcc/varasm.c.orig   2020-07-23 02:35:18.668399139 -0400
+++ gcc/varasm.c        2020-10-12 17:01:34.475555946 -0400
@@ -2844,7 +2844,7 @@
       gcc_assert (!i);
     }

-  gcc_assert (!force);
+  /* gcc_assert (!force); */

   return false;
}
@@ -6530,7 +6530,7 @@
{
   /* Some object formats don't support named sections at all.  The
      front-end should already have flagged this as an error.  */
-  gcc_unreachable ();
+  /* gcc_unreachable (); */
}

#ifndef TLS_SECTION_ASM_FLAG

--- gcc/dbxout.c.orig   2020-07-23 02:35:17.552386844 -0400
+++ gcc/dbxout.c        2020-10-12 17:53:02.412195297 -0400
@@ -1288,12 +1288,12 @@
#else
   if (DBX_LINES_FUNCTION_RELATIVE)
     {
-      char begin_label[20];
-      dbxout_begin_stabn_sline (lineno);
+      /* char begin_label[20];
+      dbxout_begin_stabn_sline (lineno); */
       /* Reference current function start using LFBB.  */
-      ASM_GENERATE_INTERNAL_LABEL (begin_label, "LFBB", scope_labelno);
+      /* ASM_GENERATE_INTERNAL_LABEL (begin_label, "LFBB", scope_labelno);
       dbxout_stab_value_internal_label_diff ("LM", &dbxout_source_line_counter,
-                                            begin_label);
+                                            begin_label); */
     }
   else
     dbxout_stabd (N_SLINE, lineno);

--- libgcc/config.host.orig     2020-07-23 02:35:18.752400064 -0400
+++ libgcc/config.host  2020-11-19 23:43:10.845281518 -0500
@@ -344,7 +344,7 @@

case ${host} in
*-*-darwin* | *-*-dragonfly* | *-*-freebsd* | *-*-netbsd* | *-*-openbsd* | \
-  *-*-solaris2*)
+  *-*-solaris2* | alpha*-dec-osf5.1*)
   enable_execute_stack=enable-execute-stack-mprotect.c
   ;;
i[34567]86-*-mingw* | x86_64-*-mingw*)
@@ -413,6 +413,16 @@
alpha*-*-openbsd*)
        tmake_file="${tmake_file} alpha/t-alpha alpha/t-ieee"
        ;;
+alpha*-dec-osf5.1*)
+        tmake_file="${tmake_file} alpha/t-alpha alpha/t-ieee t-crtfm t-slibgcc alpha/t-slibgcc-osf"
+        case ${target_thread_file} in
+          posix)
+            tmake_file="${tmake_file} alpha/t-osf-pthread"
+            ;;
+        esac
+        extra_parts="${extra_parts} crtfastmath.o"
+        md_unwind_header=alpha/osf5-unwind.h
+        ;;
alpha64-dec-*vms*)
        tmake_file="$tmake_file alpha/t-alpha alpha/t-ieee alpha/t-vms t-slibgcc-vms"
        extra_parts="$extra_parts vms-dwarf2.o vms-dwarf2eh.o"
@@ -1011,6 +1021,9 @@
        esac
        extra_parts="$extra_parts crti.o crtn.o"
        ;;
+mips-sgi-irix[456]*)
+        tmake_file=mips/t-iris
+        ;;
mipsisa32-*-elf* | mipsisa32el-*-elf* | \
mipsisa32r2-*-elf* | mipsisa32r2el-*-elf* | \
mipsisa32r6-*-elf* | mipsisa32r6el-*-elf* | \
 
  • Like
Reactions: Elf

hbent

New member
Oct 29, 2020
15
7
3
I'm cross-compiling on Gentoo, but there shouldn't be any problem with any modern Unix that can compile GCC 10 if you have the contents of /usr/lib and /usr/include in /usr/local/mips-sgi-irix4/[include,lib] and have an appropriate bintuils. Compile binutils with "--target=mips-sgi-irix4"
 

hbent

New member
Oct 29, 2020
15
7
3
Also haha oops, I got a little bit of OSF/1 patching caught up in there... don't mind the man behind the curtain...
 

hbent

New member
Oct 29, 2020
15
7
3
Ah, and binutils probably won't work past 2.23.2. At least, I didn't try to patch it after they dropped support for IRIX 4. YMMV, please do not attempt without the supervision of a physician, etc.
 

hbent

New member
Oct 29, 2020
15
7
3
What are the multi-cpu options for 4.x ? The crimson was single CPU only... what other big SGI was there at this time?
As mentioned earlier, the big R3000 machines like the 4D/2x0, 3x0 etc. will run IRIX 4 (and probably be happiest that way) but whether they will be any faster than a single processor Crimson, or even an R4000 Indigo, is up for debate. The outright fastest machine that will run IRIX 4 is a 200MHz R4000 Indigo2, but only the version with 1MB L2 cache. IRIX 4.0.5H will install without any modifications. I have one of these machines and I've done it, but it's not really worthwhile because there is no support for most of the associated peripherals. There will be no ability to run a 100Mbit ethernet board, or a video capture board of any variety.
 

hbent

New member
Oct 29, 2020
15
7
3
If you want a native GCC, I've managed to get up to 3.2.3. The main obstacle is that you have to reverse this patch:

Code:
--- trunk/gcc/hwint.h   2001/05/03 11:03:11     41784
+++ trunk/gcc/hwint.h   2001/05/03 11:58:43     41785
@@ -27,6 +27,29 @@

 /* Find the largest host integer type and set its size and type.  */

+/* Use long long on the host if the target has a wider long type than
+   the host.  */
+
+#if ! defined HOST_BITS_PER_WIDE_INT \
+    && defined HOST_BITS_PER_LONGLONG \
+    && (HOST_BITS_PER_LONGLONG > HOST_BITS_PER_LONG) \
+    && (defined (LONG_LONG_MAX) || defined (LONGLONG_MAX) \
+        || defined (LLONG_MAX) || defined (__GNUC__))
+
+# ifdef MAX_LONG_TYPE_SIZE
+#  if MAX_LONG_TYPE_SIZE > HOST_BITS_PER_LONG
+#   define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_LONGLONG
+#   define HOST_WIDE_INT long long
+#  endif
+# else
+#  if LONG_TYPE_SIZE > HOST_BITS_PER_LONG
+#   define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_LONGLONG
+#   define HOST_WIDE_INT long long
+#  endif
+# endif
+
+#endif
+
 #ifndef HOST_BITS_PER_WIDE_INT

 # if HOST_BITS_PER_LONG > HOST_BITS_PER_INT
I've made some progress on a native GCC 3.3.6 (it works but it segfaults fairly often) but as of now anything more recent than that has eluded me.
 
  • Like
Reactions: LarBob and Elf

About us

  • Silicon Graphics User Group (SGUG) is a community for users, developers, and admirers of Silicon Graphics (SGI) products. We aim to be a friendly hobbyist community for discussing all aspects of SGIs, including use, software development, the IRIX Operating System, and troubleshooting, as well as facilitating hardware exchange.

User Menu