Skip to content

Commit

Permalink
Add support for __attribute__((section(".data"))) (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkst authored Nov 15, 2023
1 parent 8b5401c commit 1fca423
Show file tree
Hide file tree
Showing 20 changed files with 120 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gcc-2.5.7.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
1 change: 1 addition & 0 deletions gcc-2.6.0.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
1 change: 1 addition & 0 deletions gcc-2.6.3-psx.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions gcc-2.6.3.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions gcc-2.7.0.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
1 change: 1 addition & 0 deletions gcc-2.7.1.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
1 change: 1 addition & 0 deletions gcc-2.7.2.1.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
1 change: 1 addition & 0 deletions gcc-2.7.2.2.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
1 change: 1 addition & 0 deletions gcc-2.7.2.3.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
1 change: 1 addition & 0 deletions gcc-2.7.2.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
3 changes: 2 additions & 1 deletion gcc-2.8.0.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ 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 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/
Expand Down
3 changes: 2 additions & 1 deletion gcc-2.8.1.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ 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 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/
Expand Down
3 changes: 2 additions & 1 deletion gcc-2.91.66.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ 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 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/
Expand Down
3 changes: 2 additions & 1 deletion gcc-2.95.2.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ 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 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/
Expand Down
25 changes: 25 additions & 0 deletions patches/mipsel-2.5.patch
Original file line number Diff line number Diff line change
@@ -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
15 changes: 13 additions & 2 deletions patches/mipsel-2.6.patch
Original file line number Diff line number Diff line change
@@ -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. */

Expand All @@ -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)
+
31 changes: 27 additions & 4 deletions patches/mipsel-2.7.patch
Original file line number Diff line number Diff line change
@@ -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 */

35 changes: 35 additions & 0 deletions patches/mipsel-2.8.patch
Original file line number Diff line number Diff line change
@@ -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 */

1 change: 1 addition & 0 deletions tests/section_attribute.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
int some_var __attribute__((section(".data"))) = 100;

0 comments on commit 1fca423

Please sign in to comment.