From 1fca423d4e6ea325d7431ade8de912b6aeee2e1f Mon Sep 17 00:00:00 2001 From: Mark Street <22226349+mkst@users.noreply.github.com> Date: Wed, 15 Nov 2023 06:59:05 +0000 Subject: [PATCH] Add support for __attribute__((section(".data"))) (#18) --- README.md | 1 + gcc-2.5.7.Dockerfile | 2 +- gcc-2.6.0.Dockerfile | 1 + gcc-2.6.3-psx.Dockerfile | 1 + gcc-2.6.3.Dockerfile | 1 + gcc-2.7.0.Dockerfile | 1 + gcc-2.7.1.Dockerfile | 1 + gcc-2.7.2.1.Dockerfile | 1 + gcc-2.7.2.2.Dockerfile | 1 + gcc-2.7.2.3.Dockerfile | 1 + gcc-2.7.2.Dockerfile | 1 + gcc-2.8.0.Dockerfile | 3 ++- gcc-2.8.1.Dockerfile | 3 ++- gcc-2.91.66.Dockerfile | 3 ++- gcc-2.95.2.Dockerfile | 3 ++- patches/mipsel-2.5.patch | 25 +++++++++++++++++++++++++ patches/mipsel-2.6.patch | 15 +++++++++++++-- patches/mipsel-2.7.patch | 31 +++++++++++++++++++++++++++---- patches/mipsel-2.8.patch | 35 +++++++++++++++++++++++++++++++++++ tests/section_attribute.c | 1 + 20 files changed, 120 insertions(+), 11 deletions(-) create mode 100644 patches/mipsel-2.5.patch create mode 100644 patches/mipsel-2.8.patch create mode 100644 tests/section_attribute.c diff --git a/README.md b/README.md index 13c25b3..21f6331 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ Run `VERSION=2.7.2.2 make` to build an old version of GCC. Alternatively use one of the prebuild binaries available from the [Releases](https://github.com/decompals/old-gcc/releases) page. **Currently supported versions:** +- GCC 2.5.7 - GCC 2.6.0 - GCC 2.6.3 - GCC 2.7.0 diff --git a/gcc-2.5.7.Dockerfile b/gcc-2.5.7.Dockerfile index 9a1f106..d0cf3c9 100644 --- a/gcc-2.5.7.Dockerfile +++ b/gcc-2.5.7.Dockerfile @@ -18,7 +18,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.5.7.c.patch RUN patch -u -p1 gcc.c -i ../patches/gcc-2.5.7.c.patch RUN patch -u -p1 g++.c -i ../patches/g++-2.5.7.c.patch -RUN patch -u -p1 config/mips/mips.h -i ../patches/mipsel-2.6.patch +RUN patch -u -p1 config/mips/mips.h -i ../patches/mipsel-2.5.patch RUN ./configure \ --target=mips-linux-gnu \ diff --git a/gcc-2.6.0.Dockerfile b/gcc-2.6.0.Dockerfile index 0f864f7..6f55893 100644 --- a/gcc-2.6.0.Dockerfile +++ b/gcc-2.6.0.Dockerfile @@ -31,6 +31,7 @@ RUN make cpp cc1 xgcc cc1plus g++ CFLAGS="-std=gnu89 -m32 -static -Dbsd4_4 -Dmip 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 +RUN ./cc1 -quiet -O2 /work/tests/section_attribute.c RUN mv xgcc gcc RUN mkdir /build && cp cpp cc1 gcc cc1plus g++ /build/ diff --git a/gcc-2.6.3-psx.Dockerfile b/gcc-2.6.3-psx.Dockerfile index 7667371..761fd2b 100644 --- a/gcc-2.6.3-psx.Dockerfile +++ b/gcc-2.6.3-psx.Dockerfile @@ -30,6 +30,7 @@ RUN make -j cpp cc1 xgcc cc1plus g++ CFLAGS="-std=gnu89 -m32 -static -Dbsd4_4 -D 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 +RUN ./cc1 -quiet -O2 /work/tests/section_attribute.c RUN mv xgcc gcc RUN mkdir /build && cp cpp cc1 gcc cc1plus g++ /build/ || true diff --git a/gcc-2.6.3.Dockerfile b/gcc-2.6.3.Dockerfile index cc5bb95..3c856a0 100644 --- a/gcc-2.6.3.Dockerfile +++ b/gcc-2.6.3.Dockerfile @@ -31,6 +31,7 @@ RUN make -j cpp cc1 xgcc cc1plus g++ CFLAGS="-std=gnu89 -m32 -static -Dbsd4_4 -D 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 +RUN ./cc1 -quiet -O2 /work/tests/section_attribute.c RUN mv xgcc gcc RUN mkdir /build && cp cpp cc1 gcc cc1plus g++ /build/ || true diff --git a/gcc-2.7.0.Dockerfile b/gcc-2.7.0.Dockerfile index 1f35138..fd40aa4 100644 --- a/gcc-2.7.0.Dockerfile +++ b/gcc-2.7.0.Dockerfile @@ -31,6 +31,7 @@ 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 +RUN ./cc1 -quiet -O2 /work/tests/section_attribute.c RUN mv xgcc gcc RUN mkdir /build && cp cpp cc1 gcc cc1plus g++ /build/ diff --git a/gcc-2.7.1.Dockerfile b/gcc-2.7.1.Dockerfile index c475d0e..6ae8865 100644 --- a/gcc-2.7.1.Dockerfile +++ b/gcc-2.7.1.Dockerfile @@ -31,6 +31,7 @@ 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 +RUN ./cc1 -quiet -O2 /work/tests/section_attribute.c RUN mv xgcc gcc RUN mkdir /build && cp cpp cc1 gcc cc1plus g++ /build/ diff --git a/gcc-2.7.2.1.Dockerfile b/gcc-2.7.2.1.Dockerfile index ce66e4d..b24a382 100644 --- a/gcc-2.7.2.1.Dockerfile +++ b/gcc-2.7.2.1.Dockerfile @@ -34,6 +34,7 @@ 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 +RUN ./cc1 -quiet -O2 /work/tests/section_attribute.c RUN mv xgcc gcc RUN mkdir /build && cp cpp cc1 gcc cc1plus g++ /build/ diff --git a/gcc-2.7.2.2.Dockerfile b/gcc-2.7.2.2.Dockerfile index c09b255..bc10825 100644 --- a/gcc-2.7.2.2.Dockerfile +++ b/gcc-2.7.2.2.Dockerfile @@ -34,6 +34,7 @@ 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 +RUN ./cc1 -quiet -O2 /work/tests/section_attribute.c RUN mv xgcc gcc RUN mkdir /build && cp cpp cc1 gcc cc1plus g++ /build/ diff --git a/gcc-2.7.2.3.Dockerfile b/gcc-2.7.2.3.Dockerfile index 8dff220..62f893e 100644 --- a/gcc-2.7.2.3.Dockerfile +++ b/gcc-2.7.2.3.Dockerfile @@ -32,6 +32,7 @@ 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 +RUN ./cc1 -quiet -O2 /work/tests/section_attribute.c RUN mv xgcc gcc RUN mkdir /build && cp cpp cc1 gcc cc1plus g++ /build/ diff --git a/gcc-2.7.2.Dockerfile b/gcc-2.7.2.Dockerfile index 5d8277c..ea30887 100644 --- a/gcc-2.7.2.Dockerfile +++ b/gcc-2.7.2.Dockerfile @@ -34,6 +34,7 @@ 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 +RUN ./cc1 -quiet -O2 /work/tests/section_attribute.c RUN mv xgcc gcc RUN mkdir /build && cp cpp cc1 gcc cc1plus g++ /build/ diff --git a/gcc-2.8.0.Dockerfile b/gcc-2.8.0.Dockerfile index 58ef5f7..2494b28 100644 --- a/gcc-2.8.0.Dockerfile +++ b/gcc-2.8.0.Dockerfile @@ -26,12 +26,13 @@ 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 patch -u -p1 config/mips/mips.h -i ../patches/mipsel-2.8.patch RUN make 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 +RUN ./cc1 -quiet -O2 /work/tests/section_attribute.c RUN mv xgcc gcc RUN mkdir /build && cp cpp cc1 gcc cc1plus g++ /build/ diff --git a/gcc-2.8.1.Dockerfile b/gcc-2.8.1.Dockerfile index 303ca98..71db517 100644 --- a/gcc-2.8.1.Dockerfile +++ b/gcc-2.8.1.Dockerfile @@ -26,12 +26,13 @@ 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 patch -u -p1 config/mips/mips.h -i ../patches/mipsel-2.8.patch 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 +RUN ./cc1 -quiet -O2 /work/tests/section_attribute.c RUN mv xgcc gcc RUN mkdir /build && cp cpp cc1 gcc cc1plus g++ /build/ diff --git a/gcc-2.91.66.Dockerfile b/gcc-2.91.66.Dockerfile index f0376cc..50d94cc 100644 --- a/gcc-2.91.66.Dockerfile +++ b/gcc-2.91.66.Dockerfile @@ -30,13 +30,14 @@ 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 patch -u -p1 gcc/config/mips/mips.h -i ../patches/mipsel-2.8.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" 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 +RUN ./gcc/cc1 -quiet -O2 /work/tests/section_attribute.c RUN mv ./gcc/xgcc ./gcc/gcc RUN mkdir /build && cp ./gcc/cpp ./gcc/cc1 ./gcc/gcc ./gcc/cc1plus ./gcc/g++ /build/ diff --git a/gcc-2.95.2.Dockerfile b/gcc-2.95.2.Dockerfile index 2f7b464..466084d 100644 --- a/gcc-2.95.2.Dockerfile +++ b/gcc-2.95.2.Dockerfile @@ -30,13 +30,14 @@ 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 patch -u -p1 gcc/config/mips/mips.h -i ../patches/mipsel-2.8.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" 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 +RUN ./gcc/cc1 -quiet -O2 /work/tests/section_attribute.c RUN mv ./gcc/xgcc ./gcc/gcc RUN mkdir /build && cp ./gcc/cpp ./gcc/cc1 ./gcc/gcc ./gcc/cc1plus ./gcc/g++ /build/ diff --git a/patches/mipsel-2.5.patch b/patches/mipsel-2.5.patch new file mode 100644 index 0000000..86eb03f --- /dev/null +++ b/patches/mipsel-2.5.patch @@ -0,0 +1,25 @@ +--- config/mips/mips.h 1993-11-15 06:54:12.000000000 +0000 ++++ config/mips/mips-patched.h 2023-11-14 22:48:19.932635363 +0000 +@@ -545,8 +545,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 + +@@ -881,6 +881,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.6.patch b/patches/mipsel-2.6.patch index a292b46..12c12fe 100644 --- a/patches/mipsel-2.6.patch +++ b/patches/mipsel-2.6.patch @@ -1,5 +1,5 @@ ---- mips.h 1994-07-11 19:22:16.000000000 +0100 -+++ mips-patched.h 2023-10-04 08:36:53.516458765 +0100 +--- config/mips/mips.h 1994-07-11 18:22:16.000000000 +0000 ++++ config/mips/mips-patched.h 2023-11-14 20:32:41.282369333 +0000 @@ -544,8 +544,8 @@ /* Names to predefine in the preprocessor for this target machine. */ @@ -23,3 +23,14 @@ /* Define this if most significant byte of a word is the lowest numbered. */ #ifndef BYTES_BIG_ENDIAN #ifndef DECSTATION +@@ -3678,3 +3683,10 @@ + #define NO_BUILTIN_PTRDIFF_TYPE + #define PTRDIFF_TYPE (TARGET_LONG64 ? "long int" : "int") + #endif ++ ++/* Assemble generic sections. ++ This is currently only used to support section attributes. */ ++ ++#define ASM_OUTPUT_SECTION_NAME(FILE, NAME) \ ++ do { fprintf (FILE, ".section\t\"%s\"\n", NAME); } while (0) ++ diff --git a/patches/mipsel-2.7.patch b/patches/mipsel-2.7.patch index 46e1108..aeec4b6 100644 --- a/patches/mipsel-2.7.patch +++ b/patches/mipsel-2.7.patch @@ -1,12 +1,35 @@ ---- mips.h 1995-06-15 19:32:41.000000000 +0000 -+++ mips-patched.h 2023-10-04 09:29:22.998515730 +0000 +--- config/mips/mips.h 1995-06-15 19:32:41.000000000 +0000 ++++ config/mips/mips-patched.h 2023-11-14 22:31:00.506591160 +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 +@@ -954,6 +957,22 @@ + #define ASM_OUTPUT_DESTRUCTOR(file, name) + + #endif /* 0 */ ++ ++/* A C statement to output something to the assembler file to switch to section ++ NAME for object DECL which is either a FUNCTION_DECL, a VAR_DECL or ++ NULL_TREE. Some target formats do not support arbitrary sections. Do not ++ define this macro in such cases. */ ++ ++#define ASM_OUTPUT_SECTION_NAME(F, DECL, NAME) \ ++do { \ ++ extern FILE *asm_out_text_file; \ ++ if ((DECL) && TREE_CODE (DECL) == FUNCTION_DECL) \ ++ fprintf (asm_out_text_file, "\t.section %s,\"ax\",@progbits\n", (NAME)); \ ++ else if ((DECL) && TREE_READONLY (DECL)) \ ++ fprintf (F, "\t.section %s,\"a\",@progbits\n", (NAME)); \ ++ else \ ++ fprintf (F, "\t.section %s,\"aw\",@progbits\n", (NAME)); \ ++} while (0) + + /* Target machine storage layout */ + diff --git a/patches/mipsel-2.8.patch b/patches/mipsel-2.8.patch new file mode 100644 index 0000000..f1c064b --- /dev/null +++ b/patches/mipsel-2.8.patch @@ -0,0 +1,35 @@ +--- config/mips/mips.h 1997-12-29 00:34:57.000000000 +0000 ++++ config/mips/mips-patched.h 2023-11-14 22:29:18.785172634 +0000 +@@ -441,6 +441,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 +@@ -1153,6 +1156,22 @@ + #define ASM_OUTPUT_DESTRUCTOR(file, name) + + #endif /* 0 */ ++ ++/* A C statement to output something to the assembler file to switch to section ++ NAME for object DECL which is either a FUNCTION_DECL, a VAR_DECL or ++ NULL_TREE. Some target formats do not support arbitrary sections. Do not ++ define this macro in such cases. */ ++ ++#define ASM_OUTPUT_SECTION_NAME(F, DECL, NAME, RELOC) \ ++do { \ ++ extern FILE *asm_out_text_file; \ ++ if ((DECL) && TREE_CODE (DECL) == FUNCTION_DECL) \ ++ fprintf (asm_out_text_file, "\t.section %s,\"ax\",@progbits\n", (NAME)); \ ++ else if ((DECL) && DECL_READONLY_SECTION (DECL, RELOC)) \ ++ fprintf (F, "\t.section %s,\"a\",@progbits\n", (NAME)); \ ++ else \ ++ fprintf (F, "\t.section %s,\"aw\",@progbits\n", (NAME)); \ ++} while (0) + + /* Target machine storage layout */ + diff --git a/tests/section_attribute.c b/tests/section_attribute.c new file mode 100644 index 0000000..24f3fe7 --- /dev/null +++ b/tests/section_attribute.c @@ -0,0 +1 @@ +int some_var __attribute__((section(".data"))) = 100;