diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..414487d --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +build-*/ diff --git a/Makefile b/Makefile index 615a453..cecef6d 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/gcc-2.6.0.Dockerfile b/gcc-2.6.0.Dockerfile index 1976580..d86daad 100644 --- a/gcc-2.6.0.Dockerfile +++ b/gcc-2.6.0.Dockerfile @@ -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 \ @@ -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 diff --git a/gcc-2.6.3-psx.Dockerfile b/gcc-2.6.3-psx.Dockerfile index b247e75..7eb0805 100644 --- a/gcc-2.6.3-psx.Dockerfile +++ b/gcc-2.6.3-psx.Dockerfile @@ -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 /include /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 \ @@ -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" ] diff --git a/gcc-2.6.3.Dockerfile b/gcc-2.6.3.Dockerfile index 07741ea..17ec882 100644 --- a/gcc-2.6.3.Dockerfile +++ b/gcc-2.6.3.Dockerfile @@ -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 /include /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 \ @@ -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 diff --git a/gcc-2.7.0.Dockerfile b/gcc-2.7.0.Dockerfile index 1f0b10f..0db6864 100644 --- a/gcc-2.7.0.Dockerfile +++ b/gcc-2.7.0.Dockerfile @@ -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 /include /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 \ @@ -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 diff --git a/gcc-2.7.1.Dockerfile b/gcc-2.7.1.Dockerfile index c6c9a6b..506a896 100644 --- a/gcc-2.7.1.Dockerfile +++ b/gcc-2.7.1.Dockerfile @@ -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 /include /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 \ @@ -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 diff --git a/gcc-2.7.2.1.Dockerfile b/gcc-2.7.2.1.Dockerfile index 2dc3bf8..3225a53 100644 --- a/gcc-2.7.2.1.Dockerfile +++ b/gcc-2.7.2.1.Dockerfile @@ -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 @@ -23,13 +24,16 @@ RUN ./configure \ COPY patches /work/patches RUN sed -i -- 's/include /include /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 diff --git a/gcc-2.7.2.2.Dockerfile b/gcc-2.7.2.2.Dockerfile index 51c1141..9af4869 100644 --- a/gcc-2.7.2.2.Dockerfile +++ b/gcc-2.7.2.2.Dockerfile @@ -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 @@ -23,13 +24,16 @@ RUN ./configure \ COPY patches /work/patches RUN sed -i -- 's/include /include /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 diff --git a/gcc-2.7.2.3.Dockerfile b/gcc-2.7.2.3.Dockerfile index 45b3e99..25bd63e 100644 --- a/gcc-2.7.2.3.Dockerfile +++ b/gcc-2.7.2.3.Dockerfile @@ -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 @@ -23,11 +24,14 @@ RUN ./configure \ COPY patches /work/patches RUN sed -i -- 's/include /include /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 diff --git a/gcc-2.7.2.Dockerfile b/gcc-2.7.2.Dockerfile index a8cb3ff..c81e858 100644 --- a/gcc-2.7.2.Dockerfile +++ b/gcc-2.7.2.Dockerfile @@ -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 @@ -23,13 +24,16 @@ RUN ./configure \ COPY patches /work/patches RUN sed -i -- 's/include /include /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 diff --git a/gcc-2.8.0.Dockerfile b/gcc-2.8.0.Dockerfile index 313df82..8025dcb 100644 --- a/gcc-2.8.0.Dockerfile +++ b/gcc-2.8.0.Dockerfile @@ -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 @@ -25,9 +25,12 @@ COPY patches /work/patches RUN sed -i -- 's/include /include /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 diff --git a/gcc-2.8.1.Dockerfile b/gcc-2.8.1.Dockerfile index 8a838a2..76c384f 100644 --- a/gcc-2.8.1.Dockerfile +++ b/gcc-2.8.1.Dockerfile @@ -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 @@ -25,9 +25,12 @@ COPY patches /work/patches RUN sed -i -- 's/include /include /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 diff --git a/gcc-2.91.66.Dockerfile b/gcc-2.91.66.Dockerfile index b972fd3..0308b66 100644 --- a/gcc-2.91.66.Dockerfile +++ b/gcc-2.91.66.Dockerfile @@ -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} @@ -29,12 +29,13 @@ COPY patches /work/patches RUN sed -i -- 's/include /include /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 diff --git a/gcc-2.95.2.Dockerfile b/gcc-2.95.2.Dockerfile index b3e7aad..158fed7 100644 --- a/gcc-2.95.2.Dockerfile +++ b/gcc-2.95.2.Dockerfile @@ -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} @@ -29,12 +29,13 @@ COPY patches /work/patches RUN sed -i -- 's/include /include /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 diff --git a/patches/mipsel-2.6.patch b/patches/mipsel-2.6.patch new file mode 100644 index 0000000..a292b46 --- /dev/null +++ b/patches/mipsel-2.6.patch @@ -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 diff --git a/patches/mipsel-2.7.patch b/patches/mipsel-2.7.patch new file mode 100644 index 0000000..46e1108 --- /dev/null +++ b/patches/mipsel-2.7.patch @@ -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 diff --git a/patches/sdbout-2.6.3.c.patch b/patches/sdbout-2.6.3.c.patch index c179292..99d92c2 100644 --- a/patches/sdbout-2.6.3.c.patch +++ b/patches/sdbout-2.6.3.c.patch @@ -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 diff --git a/tests/little_endian.c b/tests/little_endian.c new file mode 100644 index 0000000..4a741f6 --- /dev/null +++ b/tests/little_endian.c @@ -0,0 +1,7 @@ +typedef struct { + unsigned int field; +} Foo; + +unsigned char bar(Foo* foo) { + return foo->field; +}