Skip to content

Commit

Permalink
Ensure all compilers are mipsel not mipseb (#13)
Browse files Browse the repository at this point in the history
* Ensure 2.6.x are mipsel not mipseb

* Ensure all compilers target mipsel by default

* whoops
  • Loading branch information
mkst committed Oct 5, 2023
1 parent 98230bc commit 0c233b8
Show file tree
Hide file tree
Showing 19 changed files with 131 additions and 32 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build-*/
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
ifndef VERSION
$(error You must specify a VERSION e.g. VERSION=2.8.1)
endif

all:
docker compose up -d --build
mkdir -p build-gcc-$(VERSION)
docker compose up --build && docker compose down

clean:
rm -rf build/
rm -rf build-gcc-*/

.PHONY: all
6 changes: 5 additions & 1 deletion gcc-2.6.0.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ RUN patch -u -p1 collect2.c -i ../patches/collect2-2.6.0.c.patch
RUN patch -u -p1 cccp.c -i ../patches/cccp-2.6.0.c.patch
RUN patch -u -p1 gcc.c -i ../patches/gcc-2.6.0.c.patch
RUN patch -u -p1 cp/g++.c -i ../patches/g++-2.6.0.c.patch
RUN patch -u -p1 config/mips/mips.h -i ../patches/mipsel-2.6.patch

RUN ./configure \
--target=mips-linux-gnu \
Expand All @@ -26,7 +27,10 @@ RUN ./configure \
--host=i386-pc-linux \
--build=i386-pc-linux

RUN make cpp cc1 xgcc cc1plus g++ CFLAGS="-std=gnu89 -m32 -static -Dbsd4_4 -Dmips -DHAVE_STRERROR" || true
RUN make cpp cc1 xgcc cc1plus g++ CFLAGS="-std=gnu89 -m32 -static -Dbsd4_4 -Dmips -DHAVE_STRERROR"

COPY tests /work/tests
RUN ./cc1 -quiet -O2 /work/tests/little_endian.c && grep -E 'lbu\s\$2,0\(\$4\)' /work/tests/little_endian.s

COPY entrypoint.sh /work/
RUN chmod +x /work/entrypoint.sh
Expand Down
5 changes: 5 additions & 0 deletions gcc-2.6.3-psx.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ RUN tar xzf gcc-2.6.3.tar.gz
WORKDIR /work/gcc-2.6.3
COPY patches /work/patches
RUN sed -i -- 's/include <varargs.h>/include <stdarg.h>/g' *.c

RUN patch -u -p1 obstack.h -i ../patches/obstack-2.7.2.h.patch
RUN patch -u -p1 sdbout.c -i ../patches/sdbout-2.6.3.c.patch
RUN patch -su -p1 < ../patches/psx.patch

RUN ./configure \
--target=mips-sony-psx \
--prefix=/opt/cross \
Expand All @@ -23,6 +25,9 @@ RUN ./configure \

RUN make -j cpp cc1 xgcc cc1plus g++ CFLAGS="-std=gnu89 -m32 -static -Dbsd4_4 -Dmips -march=i686" || true

COPY tests /work/tests
RUN ./cc1 -quiet -O2 /work/tests/little_endian.c && grep -E 'lbu\s\$2,0\(\$4\)' /work/tests/little_endian.s

COPY entrypoint.sh /work/
RUN chmod +x /work/entrypoint.sh
CMD [ "/work/entrypoint.sh" ]
8 changes: 7 additions & 1 deletion gcc-2.6.3.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ RUN tar xzf gcc-2.6.3.tar.gz
WORKDIR /work/gcc-2.6.3
COPY patches /work/patches
RUN sed -i -- 's/include <varargs.h>/include <stdarg.h>/g' *.c

RUN patch -u -p1 obstack.h -i ../patches/obstack-2.7.2.h.patch
RUN patch -u -p1 sdbout.c -i ../patches/sdbout-2.6.3.c.patch
RUN patch -u -p1 config/mips/mips.h -i ../patches/mipsel-2.6.patch

RUN ./configure \
--target=mips-linux-gnu \
--prefix=/opt/cross \
Expand All @@ -20,7 +23,10 @@ RUN ./configure \
--host=i386-pc-linux \
--build=i386-pc-linux

RUN make -j cpp cc1 xgcc cc1plus g++ CFLAGS="-std=gnu89 -m32 -static -Dbsd4_4 -Dmips" || true
RUN make cpp cc1 xgcc cc1plus g++ CFLAGS="-std=gnu89 -m32 -static -Dbsd4_4 -Dmips" || true

COPY tests /work/tests
RUN ./cc1 -quiet -O2 /work/tests/little_endian.c && grep -E 'lbu\s\$2,0\(\$4\)' /work/tests/little_endian.s

COPY entrypoint.sh /work/
RUN chmod +x /work/entrypoint.sh
Expand Down
7 changes: 6 additions & 1 deletion gcc-2.7.0.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ RUN tar xzf gcc-2.7.0.tar.gz
WORKDIR /work/gcc-2.7.0
COPY patches /work/patches
RUN sed -i -- 's/include <varargs.h>/include <stdarg.h>/g' *.c

RUN patch -u -p1 obstack.h -i ../patches/obstack-2.7.2.h.patch
RUN patch -u -p1 configure -i ../patches/configure.patch
RUN patch -u -p1 config.sub -i ../patches/config.sub.patch
RUN patch -u -p1 config/mips/mips.h -i ../patches/mipsel-2.7.patch

RUN ./configure \
--target=mips-linux-gnu \
--prefix=/opt/cross \
Expand All @@ -25,7 +28,9 @@ RUN ./configure \
--build=i386-pc-linux

RUN make -j cpp cc1 xgcc cc1plus g++ CFLAGS="-std=gnu89 -m32 -static"
RUN test -f cc1

COPY tests /work/tests
RUN ./cc1 -quiet -O2 /work/tests/little_endian.c && grep -E 'lbu\s\$2,0\(\$4\)' /work/tests/little_endian.s

COPY entrypoint.sh /work/
RUN chmod +x /work/entrypoint.sh
Expand Down
9 changes: 7 additions & 2 deletions gcc-2.7.1.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ RUN tar xzf gcc-2.7.1.tar.gz
WORKDIR /work/gcc-2.7.1
COPY patches /work/patches
RUN sed -i -- 's/include <varargs.h>/include <stdarg.h>/g' *.c

RUN patch -u -p1 obstack.h -i ../patches/obstack-2.7.2.h.patch
RUN patch -u -p1 configure -i ../patches/configure.patch
RUN patch -u -p1 config.sub -i ../patches/config.sub.patch
RUN patch -u -p1 config/mips/mips.h -i ../patches/mipsel-2.7.patch

RUN ./configure \
--target=mips-linux-gnu \
--prefix=/opt/cross \
Expand All @@ -24,8 +27,10 @@ RUN ./configure \
--host=i386-pc-linux \
--build=i386-pc-linux

RUN make -j cpp cc1 xgcc cc1plus g++ CFLAGS="-std=gnu89 -m32 -static" || true
RUN test -f cc1
RUN make -j cpp cc1 xgcc cc1plus g++ CFLAGS="-std=gnu89 -m32 -static"

COPY tests /work/tests
RUN ./cc1 -quiet -O2 /work/tests/little_endian.c && grep -E 'lbu\s\$2,0\(\$4\)' /work/tests/little_endian.s

COPY entrypoint.sh /work/
RUN chmod +x /work/entrypoint.sh
Expand Down
10 changes: 7 additions & 3 deletions gcc-2.7.2.1.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM ubuntu:focal
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update
RUN apt-get install -y build-essential bison file gperf gcc gcc-multilib git wget
RUN apt-get install -y build-essential gcc gcc-multilib wget

ENV VERSION=2.7.2.1
ENV GNUPATH=old-gnu
Expand All @@ -23,13 +24,16 @@ RUN ./configure \

COPY patches /work/patches
RUN sed -i -- 's/include <varargs.h>/include <stdarg.h>/g' *.c

RUN patch -u -p1 obstack.h -i ../patches/obstack-2.7.2.h.patch
RUN patch -u -p1 configure -i ../patches/configure.patch
RUN patch -u -p1 config.sub -i ../patches/config.sub.patch
RUN patch -u -p1 config/mips/mips.h -i ../patches/mipsel-2.7.patch

RUN make -j cpp cc1 xgcc cc1plus g++ CFLAGS="-std=gnu89 -m32 -static"
RUN test -f cc1
RUN file cc1

COPY tests /work/tests
RUN ./cc1 -quiet -O2 /work/tests/little_endian.c && grep -E 'lbu\s\$2,0\(\$4\)' /work/tests/little_endian.s

COPY entrypoint.sh /work/
RUN chmod +x /work/entrypoint.sh
Expand Down
10 changes: 7 additions & 3 deletions gcc-2.7.2.2.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM ubuntu:focal
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update
RUN apt-get install -y build-essential bison file gperf gcc gcc-multilib git wget
RUN apt-get install -y build-essential gcc gcc-multilib wget

ENV VERSION=2.7.2.2
ENV GNUPATH=old-gnu
Expand All @@ -23,13 +24,16 @@ RUN ./configure \

COPY patches /work/patches
RUN sed -i -- 's/include <varargs.h>/include <stdarg.h>/g' *.c

RUN patch -u -p1 obstack.h -i ../patches/obstack-2.7.2.h.patch
RUN patch -u -p1 configure -i ../patches/configure.patch
RUN patch -u -p1 config.sub -i ../patches/config.sub.patch
RUN patch -u -p1 config/mips/mips.h -i ../patches/mipsel-2.7.patch

RUN make -j cpp cc1 xgcc cc1plus g++ CFLAGS="-std=gnu89 -m32 -static"
RUN test -f cc1
RUN file cc1

COPY tests /work/tests
RUN ./cc1 -quiet -O2 /work/tests/little_endian.c && grep -E 'lbu\s\$2,0\(\$4\)' /work/tests/little_endian.s

COPY entrypoint.sh /work/
RUN chmod +x /work/entrypoint.sh
Expand Down
10 changes: 7 additions & 3 deletions gcc-2.7.2.3.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM ubuntu:focal
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update
RUN apt-get install -y build-essential bison file gperf gcc gcc-multilib git wget
RUN apt-get install -y build-essential gcc gcc-multilib wget

ENV VERSION=2.7.2.3
ENV GNUPATH=gnu
Expand All @@ -23,11 +24,14 @@ RUN ./configure \

COPY patches /work/patches
RUN sed -i -- 's/include <varargs.h>/include <stdarg.h>/g' *.c

RUN patch -u -p1 obstack.h -i ../patches/obstack-2.7.2.h.patch
RUN patch -u -p1 config/mips/mips.h -i ../patches/mipsel-2.7.patch

RUN make -j cpp cc1 xgcc cc1plus g++ CFLAGS="-std=gnu89 -m32 -static"
RUN test -f cc1
RUN file cc1

COPY tests /work/tests
RUN ./cc1 -quiet -O2 /work/tests/little_endian.c && grep -E 'lbu\s\$2,0\(\$4\)' /work/tests/little_endian.s

COPY entrypoint.sh /work/
RUN chmod +x /work/entrypoint.sh
Expand Down
10 changes: 7 additions & 3 deletions gcc-2.7.2.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM ubuntu:focal
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update
RUN apt-get install -y build-essential bison file gperf gcc gcc-multilib git wget
RUN apt-get install -y build-essential gcc gcc-multilib wget

ENV VERSION=2.7.2
ENV GNUPATH=old-gnu
Expand All @@ -23,13 +24,16 @@ RUN ./configure \

COPY patches /work/patches
RUN sed -i -- 's/include <varargs.h>/include <stdarg.h>/g' *.c

RUN patch -u -p1 obstack.h -i ../patches/obstack-2.7.2.h.patch
RUN patch -u -p1 configure -i ../patches/configure.patch
RUN patch -u -p1 config.sub -i ../patches/config.sub.patch
RUN patch -u -p1 config/mips/mips.h -i ../patches/mipsel-2.7.patch

RUN make -j cpp cc1 xgcc cc1plus g++ CFLAGS="-std=gnu89 -m32 -static"
RUN test -f cc1
RUN file cc1

COPY tests /work/tests
RUN ./cc1 -quiet -O2 /work/tests/little_endian.c && grep -E 'lbu\s\$2,0\(\$4\)' /work/tests/little_endian.s

COPY entrypoint.sh /work/
RUN chmod +x /work/entrypoint.sh
Expand Down
9 changes: 6 additions & 3 deletions gcc-2.8.0.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM ubuntu:focal
RUN apt-get update
RUN apt-get install -y build-essential bison file gperf gcc gcc-multilib git wget
RUN apt-get install -y build-essential bison gperf gcc gcc-multilib git wget

ENV VERSION=2.8.0
ENV GNUPATH=gnu
Expand All @@ -25,9 +25,12 @@ COPY patches /work/patches
RUN sed -i -- 's/include <varargs.h>/include <stdarg.h>/g' *.c
RUN patch -u -p1 obstack.h -i ../patches/obstack-2.8.0.h.patch

RUN patch -u -p1 config/mips/mips.h -i ../patches/mipsel-2.7.patch

RUN make cpp cc1 xgcc cc1plus g++ CFLAGS="-std=gnu89 -m32 -static"
RUN test -f cc1
RUN file cc1

COPY tests /work/tests
RUN ./cc1 -quiet -O2 /work/tests/little_endian.c && grep -E 'lbu\s\$2,0\(\$4\)' /work/tests/little_endian.s

COPY entrypoint.sh /work/
RUN chmod +x /work/entrypoint.sh
Expand Down
9 changes: 6 additions & 3 deletions gcc-2.8.1.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM ubuntu:focal
RUN apt-get update
RUN apt-get install -y build-essential bison file gperf gcc gcc-multilib git wget
RUN apt-get install -y build-essential bison gperf gcc gcc-multilib git wget

ENV VERSION=2.8.1
ENV GNUPATH=gnu
Expand All @@ -25,9 +25,12 @@ COPY patches /work/patches
RUN sed -i -- 's/include <varargs.h>/include <stdarg.h>/g' *.c
RUN patch -u -p1 obstack.h -i ../patches/obstack-2.8.1.h.patch

RUN patch -u -p1 config/mips/mips.h -i ../patches/mipsel-2.7.patch

RUN make -j cpp cc1 xgcc cc1plus g++ CFLAGS="-std=gnu89 -m32 -static"
RUN test -f cc1
RUN file cc1

COPY tests /work/tests
RUN ./cc1 -quiet -O2 /work/tests/little_endian.c && grep -E 'lbu\s\$2,0\(\$4\)' /work/tests/little_endian.s

COPY entrypoint.sh /work/
RUN chmod +x /work/entrypoint.sh
Expand Down
7 changes: 4 additions & 3 deletions gcc-2.91.66.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM ubuntu:focal as build
RUN apt-get update
RUN apt-get install -y build-essential bison file gperf gcc gcc-multilib git wget
RUN apt-get install -y build-essential bison gperf gcc gcc-multilib git wget

ARG VERSION=2.91.66
ENV VERSION=${VERSION}
Expand Down Expand Up @@ -29,12 +29,13 @@ COPY patches /work/patches

RUN sed -i -- 's/include <varargs.h>/include <stdarg.h>/g' **/*.c
RUN patch -u -p1 gcc/obstack.h -i ../patches/obstack-${VERSION}.h.patch
RUN patch -u -p1 gcc/config/mips/mips.h -i ../patches/mipsel-2.7.patch

RUN make -C libiberty/ CFLAGS="-std=gnu89 -m32 -static"
RUN make -C gcc/ -j cpp cc1 xgcc cc1plus g++ CFLAGS="-std=gnu89 -m32 -static"

RUN test -f gcc/cc1
RUN file gcc/cc1
COPY tests /work/tests
RUN ./gcc/cc1 -quiet -O2 /work/tests/little_endian.c && grep -E 'lbu\s\$2,0\(\$4\)' /work/tests/little_endian.s

### STAGE 2

Expand Down
7 changes: 4 additions & 3 deletions gcc-2.95.2.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM ubuntu:focal as build
RUN apt-get update
RUN apt-get install -y build-essential bison file gperf gcc gcc-multilib git wget
RUN apt-get install -y build-essential bison gperf gcc gcc-multilib git wget

ARG VERSION=2.95.2
ENV VERSION=${VERSION}
Expand Down Expand Up @@ -29,12 +29,13 @@ COPY patches /work/patches

RUN sed -i -- 's/include <varargs.h>/include <stdarg.h>/g' **/*.c
RUN patch -u -p1 include/obstack.h -i ../patches/obstack-${VERSION}.h.patch
RUN patch -u -p1 gcc/config/mips/mips.h -i ../patches/mipsel-2.7.patch

RUN make -C libiberty/ CFLAGS="-std=gnu89 -m32 -static"
RUN make -C gcc/ -j cpp cc1 xgcc cc1plus g++ CFLAGS="-std=gnu89 -m32 -static"

RUN test -f gcc/cc1
RUN file gcc/cc1
COPY tests /work/tests
RUN ./gcc/cc1 -mel -quiet -O2 /work/tests/little_endian.c && grep -E 'lbu\s\$2,0\(\$4\)' /work/tests/little_endian.s

### STAGE 2

Expand Down
25 changes: 25 additions & 0 deletions patches/mipsel-2.6.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--- mips.h 1994-07-11 19:22:16.000000000 +0100
+++ mips-patched.h 2023-10-04 08:36:53.516458765 +0100
@@ -544,8 +544,8 @@
/* Names to predefine in the preprocessor for this target machine. */

#ifndef CPP_PREDEFINES
-#define CPP_PREDEFINES "-Dmips -Dunix -Dhost_mips -DMIPSEB -DR3000 -DSYSTYPE_BSD43 \
--D_mips -D_unix -D_host_mips -D_MIPSEB -D_R3000 -D_SYSTYPE_BSD43 \
+#define CPP_PREDEFINES "-Dmips -Dunix -Dhost_mips -DMIPSEL -DR3000 -DSYSTYPE_BSD43 \
+-D_mips -D_unix -D_host_mips -D_MIPSEL -D_R3000 -D_SYSTYPE_BSD43 \
-Asystem(unix) -Asystem(bsd) -Acpu(mips) -Amachine(mips)"
#endif

@@ -901,6 +901,11 @@
*/
#define BITS_BIG_ENDIAN 0

+/* Force little-endian */
+#define MIPSEL
+#define BYTES_BIG_ENDIAN 0
+#define WORDS_BIG_ENDIAN 0
+
/* Define this if most significant byte of a word is the lowest numbered. */
#ifndef BYTES_BIG_ENDIAN
#ifndef DECSTATION
12 changes: 12 additions & 0 deletions patches/mipsel-2.7.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--- mips.h 1995-06-15 19:32:41.000000000 +0000
+++ mips-patched.h 2023-10-04 09:29:22.998515730 +0000
@@ -406,6 +406,9 @@
| TARGET_ENDIAN_DEFAULT)} \
}

+/* Default little-endian */
+#define TARGET_ENDIAN_DEFAULT -MASK_BIG_ENDIAN
+
/* Default target_flags if no switches are specified */

#ifndef TARGET_DEFAULT
2 changes: 1 addition & 1 deletion patches/sdbout-2.6.3.c.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- gcc-2.6.3/sdbout.c 1994-09-30 22:23:57.000000000 +0100
+++ gcc-2.7.1/sdbout.c 1995-06-15 13:07:11.000000000 +0100
@@ -53,2 +54,2 @@
@@ -56,2 +57,2 @@
-#if defined(USG) && !defined(MIPS) && !defined (hpux) && !defined(WINNT)
+#if defined(USG) && !defined(MIPS) && !defined (hpux) && !defined(_WIN32) && !defined(__linux__)
#include <syms.h>
7 changes: 7 additions & 0 deletions tests/little_endian.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
typedef struct {
unsigned int field;
} Foo;

unsigned char bar(Foo* foo) {
return foo->field;
}

0 comments on commit 0c233b8

Please sign in to comment.