From 0b2b7366a87700ba08fa10be6a8d5b5b0f219ddc Mon Sep 17 00:00:00 2001 From: Stan H Date: Wed, 2 Mar 2022 20:23:07 +0100 Subject: [PATCH 01/10] backport fix for .debug_line head generation and add flag for restoring old behavior --- gcc/dwarf2out.c | 38 ++++++++++++++++++++++++++++++++++++-- gcc/flags.h | 4 ++++ gcc/toplev.c | 5 +++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 03555d57..98e7e7b9 100755 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -232,6 +232,10 @@ static unsigned reg_number (rtx); #define FDE_AFTER_SIZE_LABEL "LSFDE" #define FDE_END_LABEL "LEFDE" #define FDE_LENGTH_LABEL "LLFDE" +#define LINE_NUMBER_BEGIN_LABEL "LSLT" +#define LINE_NUMBER_END_LABEL "LELT" +#define LN_PROLOG_AS_LABEL "LASLTP" +#define LN_PROLOG_END_LABEL "LELTP" /* Definitions of defaults for various types of primitive assembly language output operations. These may be overridden from within the tm.h file, @@ -4301,6 +4305,7 @@ output_aranges () static void output_line_info () { + char l1[20], l2[20], p1[20], p2[20]; char line_label[MAX_ARTIFICIAL_LABEL_BYTES]; char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES]; register unsigned opc; @@ -4313,22 +4318,44 @@ output_line_info () register unsigned long current_file; register unsigned long function; - ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_info ()); + ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0); + ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0); + ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0); + ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0); + + if (flag_legacy_debug_info) + ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_info ()); + else + ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1); + if (flag_debug_asm) fprintf (asm_out_file, "\t%s Length of Source Line Info.", ASM_COMMENT_START); fputc ('\n', asm_out_file); + + if (!flag_legacy_debug_info) + ASM_OUTPUT_LABEL(asm_out_file, l1); + ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION); if (flag_debug_asm) fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START); fputc ('\n', asm_out_file); - ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ()); + + if (flag_legacy_debug_info) + ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ()); + else + ASM_OUTPUT_DWARF_DELTA (asm_out_file, p2, p1); + if (flag_debug_asm) fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START); fputc ('\n', asm_out_file); + + if (!flag_legacy_debug_info) + ASM_OUTPUT_LABEL(asm_out_file, p1); + ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH); if (flag_debug_asm) fprintf (asm_out_file, "\t%s Minimum Instruction Length", @@ -4423,6 +4450,9 @@ output_line_info () ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); fputc ('\n', asm_out_file); + if (!flag_legacy_debug_info) + ASM_OUTPUT_LABEL (asm_out_file, p2); + /* Set the address register to the first location in the text section */ ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); if (flag_debug_asm) @@ -4738,6 +4768,10 @@ output_line_info () fputc ('\n', asm_out_file); } } + + if (!flag_legacy_debug_info) + /* Output the marker for the end of the line number info. */ + ASM_OUTPUT_LABEL (asm_out_file, l2); } /* Given a pointer to a BLOCK node return non-zero if (and only if) the node diff --git a/gcc/flags.h b/gcc/flags.h index 754096f7..cf2931ff 100755 --- a/gcc/flags.h +++ b/gcc/flags.h @@ -450,3 +450,7 @@ extern enum graph_dump_types graph_dump_format; /* Nonzero if ASM output should use hex instead of decimal. */ extern int flag_hex_asm; + +/* Nonzero if generated DWARF debug info should match (buggy) original + GCC 2.95.x behavior. */ +extern int flag_legacy_debug_info; diff --git a/gcc/toplev.c b/gcc/toplev.c index e80ed20c..b748a1a5 100755 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -585,6 +585,9 @@ int flag_instrument_function_entry_exit = 0; /* Use hex instead of decimal in ASM output. */ int flag_hex_asm = 0; +/* Use old (buggy) DWARF line info generator. */ +int flag_legacy_debug_info = 0; + typedef struct { char *string; @@ -724,6 +727,8 @@ lang_independent_options f_options[] = "Instrument function entry/exit with profiling calls"}, {"hex-asm", &flag_hex_asm, 1, "Use hex instead of decimal in assembly output"}, + {"legacy-debug-line-info", &flag_legacy_debug_info, 1, + "Generate old (buggy) DWARF line info"}, }; #define NUM_ELEM(a) (sizeof (a) / sizeof ((a)[0])) From 2bf742a691757e43b9aa1bbdff322ea2a06debb8 Mon Sep 17 00:00:00 2001 From: "Colton G. Rushton" Date: Sat, 18 Jun 2022 15:11:17 -0300 Subject: [PATCH 02/10] Create README.md --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 00000000..b39d7877 --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# agbcc +A fork of gcc 2.95.1 that allows for compilation of Game Boy Advance games. + +To build, simply run: +`./build.sh` + +To install, simply run: +`./install.sh` + +You'll now have a working compiler with which you can build your Game Boy Advance game. From d4cf8e02d18ef37e71fd02c24cff5f05c33508dd Mon Sep 17 00:00:00 2001 From: "Colton G. Rushton" Date: Sat, 18 Jun 2022 15:13:18 -0300 Subject: [PATCH 03/10] add clean.sh instructions --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index b39d7877..f12d4ca7 100644 --- a/README.md +++ b/README.md @@ -8,3 +8,8 @@ To install, simply run: `./install.sh` You'll now have a working compiler with which you can build your Game Boy Advance game. + +To clean your build directory, simply run: +`./clean.sh` + +and your compiler will be ready for another compile From a6fc728b1bad1916abc8dc0dfd9f286089961c77 Mon Sep 17 00:00:00 2001 From: "Colton G. Rushton" Date: Sat, 18 Jun 2022 17:18:42 -0300 Subject: [PATCH 04/10] Fix all warnings --- clean.sh | 3 +++ gcc/c-typeck.c | 2 +- gcc/genrecog.c | 1 + gcc/real.c | 2 +- gcc/rtl.h | 2 +- gcc/thumb.h | 2 +- gcc/toplev.c | 2 +- 7 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 clean.sh diff --git a/clean.sh b/clean.sh new file mode 100644 index 00000000..c6a62d7c --- /dev/null +++ b/clean.sh @@ -0,0 +1,3 @@ +make -C gcc clean +make -C libgcc clean +make -C libc clean diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 807dfcfa..b0bfd9c4 100755 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -3133,7 +3133,7 @@ build_unary_op (code, xarg, noconvert) return fold (build1 (code, argtype, arg)); } - error (errstring); + error ("%s", errstring); return error_mark_node; } diff --git a/gcc/genrecog.c b/gcc/genrecog.c index eefde454..5c2085e5 100755 --- a/gcc/genrecog.c +++ b/gcc/genrecog.c @@ -151,6 +151,7 @@ static struct pred_table {"address_operand", {CONST_INT, CONST_DOUBLE, CONST, SYMBOL_REF, LABEL_REF, SUBREG, REG, MEM, PLUS, MINUS, MULT}}, {"register_operand", {SUBREG, REG}}, + {"s_register_operand", {SUBREG, REG}}, {"scratch_operand", {SCRATCH, REG}}, {"immediate_operand", {CONST_INT, CONST_DOUBLE, CONST, SYMBOL_REF, LABEL_REF}}, diff --git a/gcc/real.c b/gcc/real.c index 456edda0..14469ea7 100755 --- a/gcc/real.c +++ b/gcc/real.c @@ -4068,7 +4068,7 @@ mtherr (name, code) name = "square root"; sprintf (errstr, "%s during real %s", ermsg[code], name); if (extra_warnings) - warning (errstr); + warning ("%s", errstr); /* Set global error message word */ merror = code + 1; } diff --git a/gcc/rtl.h b/gcc/rtl.h index bbaa7155..7013374e 100755 --- a/gcc/rtl.h +++ b/gcc/rtl.h @@ -1127,7 +1127,7 @@ extern rtx gen_rtx_MEM (enum machine_mode, rtx); /* We need the cast here to ensure that we get the same result both with and without prototypes. */ -#define GEN_INT(N) gen_rtx_CONST_INT (VOIDmode, (HOST_WIDE_INT) (N)) +#define GEN_INT(N) gen_rtx_CONST_INT (VOIDmode, (HOST_WIDE_INT) (intptr_t) (N)) #define arg_pointer_rtx (&global_rtl.arg_pointer_val) diff --git a/gcc/thumb.h b/gcc/thumb.h index 9911f761..b3e40124 100755 --- a/gcc/thumb.h +++ b/gcc/thumb.h @@ -112,7 +112,7 @@ extern int target_flags; fprintf((STREAM), ", %d\t%s %d\n", (ROUNDED), (ASM_COMMENT_START), (SIZE))) #define ASM_GENERATE_INTERNAL_LABEL(STRING,PREFIX,NUM) \ - sprintf ((STRING), "*%s%s%d", (LOCAL_LABEL_PREFIX), (PREFIX), (NUM)) + sprintf ((STRING), "*%s%s%ld", (LOCAL_LABEL_PREFIX), (PREFIX+2), (long unsigned int) (NUM)) /* This is how to output an internal numbered label where PREFIX is the class of label and NUM is the number within the class. */ diff --git a/gcc/toplev.c b/gcc/toplev.c index e80ed20c..7401ffcd 100755 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -1046,7 +1046,7 @@ fatal_io_error(char *name) void fatal_insn(char *message, rtx insn) { - error(message); + error("%s", message); debug_rtx(insn); if (asm_out_file) fflush(asm_out_file); From b603a3129ef49e7b4951858e6b218b0024dad18e Mon Sep 17 00:00:00 2001 From: "Colton G. Rushton" Date: Sat, 18 Jun 2022 17:28:04 -0300 Subject: [PATCH 05/10] two warnings still exist augh --- gcc/thumb.h | 2 +- gcc_arm/toplev.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gcc/thumb.h b/gcc/thumb.h index b3e40124..3fca1c08 100755 --- a/gcc/thumb.h +++ b/gcc/thumb.h @@ -112,7 +112,7 @@ extern int target_flags; fprintf((STREAM), ", %d\t%s %d\n", (ROUNDED), (ASM_COMMENT_START), (SIZE))) #define ASM_GENERATE_INTERNAL_LABEL(STRING,PREFIX,NUM) \ - sprintf ((STRING), "*%s%s%ld", (LOCAL_LABEL_PREFIX), (PREFIX+2), (long unsigned int) (NUM)) + sprintf ((STRING), "*%s%s%ld", (LOCAL_LABEL_PREFIX), (PREFIX), (long unsigned int) (NUM)) /* This is how to output an internal numbered label where PREFIX is the class of label and NUM is the number within the class. */ diff --git a/gcc_arm/toplev.c b/gcc_arm/toplev.c index 29833dad..c16480e4 100755 --- a/gcc_arm/toplev.c +++ b/gcc_arm/toplev.c @@ -1393,7 +1393,7 @@ fatal_insn (message, insn) char *message; rtx insn; { - error (message); + error ("%s", message); debug_rtx (insn); if (asm_out_file) fflush (asm_out_file); From 6777bd83111be4834ba1e42824e7009cf3e35635 Mon Sep 17 00:00:00 2001 From: "Colton G. Rushton" Date: Sat, 18 Jun 2022 17:42:06 -0300 Subject: [PATCH 06/10] All debug info fixes added --- gcc/dwarf2out.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 98e7e7b9..5e5e094e 100755 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -3701,6 +3701,14 @@ output_abbrev_section () fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP); } + + if (flag_legacy_debug_info) + { + /* We need to properly terminate the abbrev table for this + compilation unit, as per the standard, and not rely on + workarounds in e.g. gdb. */ + fprintf (asm_out_file, "\t%s\t0\n", ASM_BYTE_OP); + } } /* Output location description stack opcode's operands (if any). */ From f5ce72c34a5ab8a9d4ca2157246d349cf5a53675 Mon Sep 17 00:00:00 2001 From: "Colton G. Rushton" Date: Sat, 18 Jun 2022 18:02:56 -0300 Subject: [PATCH 07/10] Parallel builds fixed and configure artifacts gone --- Makefile | 54 +++++++++++++++++++++++++++++++++++++++++++++ build.sh | 33 ++++++++++++++------------- gcc/Makefile | 6 ++--- gcc_arm/Make-hooks | 21 ------------------ gcc_arm/Make-host | 0 gcc_arm/Make-lang | 0 gcc_arm/Make-target | 35 ----------------------------- gcc_arm/config.h | 12 ---------- gcc_arm/cstamp-h | 1 - gcc_arm/gencheck.h | 0 gcc_arm/hconfig.h | 12 ---------- gcc_arm/options.h | 0 gcc_arm/specs.h | 0 gcc_arm/tconfig.h | 2 -- gcc_arm/tm.h | 3 --- install.sh | 10 ++++----- libc/Makefile | 11 +++++++-- libgcc/Makefile | 25 +++++++++++++-------- 18 files changed, 103 insertions(+), 122 deletions(-) create mode 100644 Makefile delete mode 100644 gcc_arm/Make-hooks delete mode 100644 gcc_arm/Make-host delete mode 100644 gcc_arm/Make-lang delete mode 100644 gcc_arm/Make-target delete mode 100644 gcc_arm/config.h delete mode 100644 gcc_arm/cstamp-h delete mode 100644 gcc_arm/gencheck.h delete mode 100644 gcc_arm/hconfig.h delete mode 100644 gcc_arm/options.h delete mode 100644 gcc_arm/specs.h delete mode 100644 gcc_arm/tconfig.h delete mode 100644 gcc_arm/tm.h diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..d21b4c2e --- /dev/null +++ b/Makefile @@ -0,0 +1,54 @@ +.PHONY = agbcc old_agbcc agbcc_arm libc.a libgcc.a + +# needed for out-of-tree builds of agbcc and old_agbcc +export srcdir = ../gcc + +all: agbcc old_agbcc agbcc_arm libc.a libgcc.a + +clean: + rm -rf build_agbcc build_old_agbcc + -$(MAKE) -C gcc_arm distclean + $(MAKE) -C libc clean + $(MAKE) -C libgcc clean + +agbcc: + mkdir -p build_agbcc + $(MAKE) -C build_agbcc -f ../gcc/Makefile clean + $(MAKE) -C build_agbcc -f ../gcc/Makefile normal + +old_agbcc: + mkdir -p build_old_agbcc + $(MAKE) -C build_old_agbcc -f ../gcc/Makefile clean + $(MAKE) -C build_old_agbcc -f ../gcc/Makefile old + +agbcc_arm: + -$(MAKE) -C gcc_arm distclean + cd gcc_arm && ./configure --target=arm-elf --host=i386-linux-gnu + $(MAKE) -C gcc_arm cc1 + +libc.a: old_agbcc + $(MAKE) -C libc clean + $(MAKE) -C libc + +libgcc.a: old_agbcc + $(MAKE) -C libgcc clean + $(MAKE) -C libgcc + +install: all +ifeq ($(PREFIX),) + $(error PREFIX is empty! Specify a PREFIX to install to) +endif + $(info Installing into $(PREFIX)) + mkdir -p $(PREFIX)/tools/agbcc + mkdir -p $(PREFIX)/tools/agbcc/bin + mkdir -p $(PREFIX)/tools/agbcc/include + mkdir -p $(PREFIX)/tools/agbcc/lib + cp build_agbcc/agbcc $(PREFIX)/tools/agbcc/bin/ + cp build_old_agbcc/old_agbcc $(PREFIX)/tools/agbcc/bin/ + cp gcc_arm/cc1 $(PREFIX)/tools/agbcc/bin/agbcc_arm + @# drop include, because we don't want include/include + cp -R libc/include $(PREFIX)/tools/agbcc/ + cp ginclude/* $(PREFIX)/tools/agbcc/include/ + cp libgcc/libgcc.a $(PREFIX)/tools/agbcc/lib/ + cp libc/libc.a $(PREFIX)/tools/agbcc/lib/ + diff --git a/build.sh b/build.sh index a1671fd4..db2a948e 100755 --- a/build.sh +++ b/build.sh @@ -1,29 +1,28 @@ #!/bin/sh + set -e CCOPT= CXXOPT= -# error if devkitarm is not installed and binutils-arm-none-eabi is not installed -if ! ([ -n "$DEVKITARM" ] && [ -d "$DEVKITARM/bin" ]) && ! (command -v arm-none-eabi-as &> /dev/null && command -v arm-none-eabi-ar &> /dev/null) ; then - echo "Could not find a binutils installation! Re-read the instructions and make sure you've installed either devkitARM or binutils-arm-none-eabi, depending on your system." - exit 1 -fi - if [ ! -z "$CC" ]; then CCOPT=CC=$CC; fi if [ ! -z "$CXX" ]; then CXXOPT=CXX=$CXX; fi -make -C gcc clean -make -C gcc old $CCOPT $CXXOPT -mv gcc/old_agbcc . -make -C gcc clean -make -C gcc $CCOPT $CXXOPT -mv gcc/agbcc . + +mkdir -p build_old_agbcc +srcdir=../gcc make -C build_old_agbcc -f ../gcc/Makefile clean +srcdir=../gcc make -C build_old_agbcc -f ../gcc/Makefile old $CCOPT $CXXOPT + +mkdir -p build_agbcc +srcdir=../gcc make -C build_agbcc -f ../gcc/Makefile clean +srcdir=../gcc make -C build_agbcc -f ../gcc/Makefile normal $CCOPT $CXXOPT + # not sure if the ARM compiler is the old one or the new one (-DOLD_COMPILER) -rm -f gcc_arm/config.status gcc_arm/config.cache -cd gcc_arm && ./configure --target=arm-elf --host=i386-linux-gnu && make cc1 && cd .. -mv gcc_arm/cc1 agbcc_arm +# || true is needed to keep going if the distclean fails, such as when no configure has been done before +make -C gcc_arm distclean || true +cd gcc_arm && ./configure --target=arm-elf --host=i386-linux-gnu && cd .. +make -C gcc_arm cc1 + make -C libgcc clean make -C libgcc $CCOPT $CXXOPT -mv libgcc/libgcc.a . + make -C libc clean make -C libc $CCOPT $CXXOPT -mv libc/libc.a . diff --git a/gcc/Makefile b/gcc/Makefile index 9756e901..abba7270 100644 --- a/gcc/Makefile +++ b/gcc/Makefile @@ -19,12 +19,12 @@ #Boston MA 02111-1307, USA. # Directory where sources are, from where we are. -srcdir = . +srcdir ?= . VPATH = $(srcdir) CC = gcc -BASE_CFLAGS = -g -std=gnu11 -Werror-implicit-function-declaration +BASE_CFLAGS = -g -std=gnu11 INCLUDES = -I. -I$(srcdir) @@ -81,7 +81,7 @@ $(OBJS): %.o: %.c $(DEPDIR)/%.d | $(GENERATED) $(COMPILE) $< $(POSTCOMPILE) -$(RTL_OBJS) $(RTLANAL_OBJS) $(PRINT_OBJS): %.o: %.c $(DEPDIR)/%.d +$(RTL_OBJS) $(RTLANAL_OBJS) $(PRINT_OBJS): %.o: %.c $(DEPDIR)/%.d genrtl.h $(COMPILE) $< $(POSTCOMPILE) diff --git a/gcc_arm/Make-hooks b/gcc_arm/Make-hooks deleted file mode 100644 index 1fa9bbdf..00000000 --- a/gcc_arm/Make-hooks +++ /dev/null @@ -1,21 +0,0 @@ -lang.all.build: -lang.all.cross: -lang.start.encap: -lang.rest.encap: -lang.info: -lang.dvi: -lang.install-normal: -lang.install-common: -lang.install-info: -lang.install-man: -lang.uninstall: -lang.distdir: -lang.mostlyclean: -lang.clean: -lang.distclean: -lang.extraclean: -lang.maintainer-clean: -lang.stage1: -lang.stage2: -lang.stage3: -lang.stage4: diff --git a/gcc_arm/Make-host b/gcc_arm/Make-host deleted file mode 100644 index e69de29b..00000000 diff --git a/gcc_arm/Make-lang b/gcc_arm/Make-lang deleted file mode 100644 index e69de29b..00000000 diff --git a/gcc_arm/Make-target b/gcc_arm/Make-target deleted file mode 100644 index b57eeca9..00000000 --- a/gcc_arm/Make-target +++ /dev/null @@ -1,35 +0,0 @@ -CROSS_LIBGCC1 = libgcc1-asm.a -LIB1ASMSRC = arm/lib1funcs.asm -# CYGNUS LOCAL interworking -LIB1ASMFUNCS = _udivsi3 _divsi3 _umodsi3 _modsi3 _dvmd_tls _call_via_rX -# END CYGNUS LOCAL interworking - -# These are really part of libgcc1, but this will cause them to be -# built correctly, so... - -LIB2FUNCS_EXTRA = fp-bit.c dp-bit.c - -fp-bit.c: $(srcdir)/config/fp-bit.c - echo '#define FLOAT' > fp-bit.c - echo '#ifndef __ARMEB__' >> fp-bit.c - echo '#define FLOAT_BIT_ORDER_MISMATCH' >> fp-bit.c - echo '#endif' >> fp-bit.c - cat $(srcdir)/config/fp-bit.c >> fp-bit.c - -dp-bit.c: $(srcdir)/config/fp-bit.c - echo '#ifndef __ARMEB__' > dp-bit.c - echo '#define FLOAT_BIT_ORDER_MISMATCH' >> dp-bit.c - echo '#define FLOAT_WORD_ORDER_MISMATCH' >> dp-bit.c - echo '#endif' >> dp-bit.c - cat $(srcdir)/config/fp-bit.c >> dp-bit.c - -# CYGNUS LOCAL -MULTILIB_OPTIONS = mlittle-endian/mbig-endian mhard-float/msoft-float mapcs-32/mapcs-26 mno-thumb-interwork/mthumb-interwork fno-leading-underscore/fleading-underscore mcpu=arm7 -MULTILIB_DIRNAMES = le be fpu soft 32bit 26bit normal interwork elf under nofmult -MULTILIB_EXCEPTIONS = *mapcs-26/*mthumb-interwork* *mthumb-interwork*/*mcpu=arm7* -MULTILIB_MATCHES = mbig-endian=mbe mlittle-endian=mle mcpu?arm7=mcpu?arm7d mcpu?arm7=mcpu?arm7di mcpu?arm7=mcpu?arm70 mcpu?arm7=mcpu?arm700 mcpu?arm7=mcpu?arm700i mcpu?arm7=mcpu?arm710 mcpu?arm7=mcpu?arm710c mcpu?arm7=mcpu?arm7100 mcpu?arm7=mcpu?arm7500 mcpu?arm7=mcpu?arm7500fe mcpu?arm7=mcpu?arm6 mcpu?arm7=mcpu?arm60 mcpu?arm7=mcpu?arm600 mcpu?arm7=mcpu?arm610 mcpu?arm7=mcpu?arm620 -LIBGCC = stmp-multilib -INSTALL_LIBGCC = install-multilib -# END CYGNUS LOCAL - -TARGET_LIBGCC2_CFLAGS = -Dinhibit_libc diff --git a/gcc_arm/config.h b/gcc_arm/config.h deleted file mode 100644 index 0c48f968..00000000 --- a/gcc_arm/config.h +++ /dev/null @@ -1,12 +0,0 @@ -#include "auto-host.h" -#include "gansidecl.h" -#include "i386/xm-i386.h" -#ifndef HAVE_ATEXIT -#define HAVE_ATEXIT -#endif -#ifndef POSIX -#define POSIX -#endif -#ifndef BSTRING -#define BSTRING -#endif diff --git a/gcc_arm/cstamp-h b/gcc_arm/cstamp-h deleted file mode 100644 index 8b137891..00000000 --- a/gcc_arm/cstamp-h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/gcc_arm/gencheck.h b/gcc_arm/gencheck.h deleted file mode 100644 index e69de29b..00000000 diff --git a/gcc_arm/hconfig.h b/gcc_arm/hconfig.h deleted file mode 100644 index 0c48f968..00000000 --- a/gcc_arm/hconfig.h +++ /dev/null @@ -1,12 +0,0 @@ -#include "auto-host.h" -#include "gansidecl.h" -#include "i386/xm-i386.h" -#ifndef HAVE_ATEXIT -#define HAVE_ATEXIT -#endif -#ifndef POSIX -#define POSIX -#endif -#ifndef BSTRING -#define BSTRING -#endif diff --git a/gcc_arm/options.h b/gcc_arm/options.h deleted file mode 100644 index e69de29b..00000000 diff --git a/gcc_arm/specs.h b/gcc_arm/specs.h deleted file mode 100644 index e69de29b..00000000 diff --git a/gcc_arm/tconfig.h b/gcc_arm/tconfig.h deleted file mode 100644 index 1fa5d1e7..00000000 --- a/gcc_arm/tconfig.h +++ /dev/null @@ -1,2 +0,0 @@ -#include "gansidecl.h" -#include "arm/xm-arm.h" diff --git a/gcc_arm/tm.h b/gcc_arm/tm.h deleted file mode 100644 index bda15db0..00000000 --- a/gcc_arm/tm.h +++ /dev/null @@ -1,3 +0,0 @@ -#define TARGET_CPU_DEFAULT (TARGET_CPU_generic) -#include "gansidecl.h" -#include "arm/unknown-elf.h" diff --git a/install.sh b/install.sh index 637a21da..67ad4ddb 100755 --- a/install.sh +++ b/install.sh @@ -6,13 +6,13 @@ if [ "$1" != "" ]; then mkdir -p $1/tools/agbcc/bin mkdir -p $1/tools/agbcc/include mkdir -p $1/tools/agbcc/lib - cp agbcc $1/tools/agbcc/bin/ - cp old_agbcc $1/tools/agbcc/bin/ - cp agbcc_arm $1/tools/agbcc/bin/ + cp build_agbcc/agbcc $1/tools/agbcc/bin/ + cp build_old_agbcc/old_agbcc $1/tools/agbcc/bin/ + cp gcc_arm/cc1 $1/tools/agbcc/bin/agbcc_arm cp -R libc/include $1/tools/agbcc/ #drop include, because we don't want include/include cp ginclude/* $1/tools/agbcc/include/ - cp libgcc.a $1/tools/agbcc/lib/ - cp libc.a $1/tools/agbcc/lib/ + cp libgcc/libgcc.a $1/tools/agbcc/lib/ + cp libc/libc.a $1/tools/agbcc/lib/ echo "agbcc successfully installed!" else if [ -d "../$1" ]; then diff --git a/libc/Makefile b/libc/Makefile index d9de489f..0fef62de 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -9,17 +9,24 @@ else DKA_EXISTS=0 endif -ifneq ($(DKA_EXISTS),1) PREFIX := arm-none-eabi- export AR := $(PREFIX)ar export AS := $(PREFIX)as + +ifeq ($(DKA_EXISTS),0) +ifeq ($(shell which $(AR)),) +$(info DKA_EXISTS=$(DKA_EXISTS)) +$(info DEVKITARM=$(DEVKITARM)) +$(info which arm-none-eabi-ar is $(shell which arm-none-eabi-ar)) +$(error Cannot find $(AR) or devkitARM, make sure you have an arm-none-eabi toolchain or devkitARM installed and your environment variables properly set up) +endif endif SHELL := /bin/bash -o pipefail ASFLAGS := -mcpu=arm7tdmi -CC1 := ../old_agbcc +CC1 := ../build_old_agbcc/old_agbcc CFLAGS := -O2 -fno-builtin CPPFLAGS := -I ../ginclude -I include -nostdinc -undef \ diff --git a/libgcc/Makefile b/libgcc/Makefile index 0e96527d..d46bd841 100644 --- a/libgcc/Makefile +++ b/libgcc/Makefile @@ -9,17 +9,24 @@ else DKA_EXISTS=0 endif -ifneq ($(DKA_EXISTS),1) PREFIX := arm-none-eabi- export AR := $(PREFIX)ar export AS := $(PREFIX)as + +ifeq ($(DKA_EXISTS),0) +ifeq ($(shell which $(AR)),) +$(info DKA_EXISTS=$(DKA_EXISTS)) +$(info DEVKITARM=$(DEVKITARM)) +$(info which arm-none-eabi-ar is $(shell which arm-none-eabi-ar)) +$(error Cannot find $(AR) or devkitARM, make sure you have an arm-none-eabi toolchain or devkitARM installed and your environment variables properly set up) +endif endif -CC1 = ../old_agbcc +CC1 = ../build_old_agbcc/old_agbcc libgcc.a: libgcc1.a libgcc2.a fp-bit.o dp-bit.o - $(AR) -x libgcc1.a; - $(AR) -x libgcc2.a; + $(AR) -x libgcc1.a + $(AR) -x libgcc2.a $(AR) -rc libgcc.a *.o LIB1ASMFUNCS = _udivsi3 _divsi3 _umodsi3 _modsi3 _dvmd_tls _call_via_rX @@ -66,19 +73,19 @@ libgcc2.a: libgcc2.c longlong.h mv tmplibgcc2.a libgcc2.a fp-bit.o: fp-bit.c - $(CPP) -undef -I ../ginclude -nostdinc -o fp-bit.i fp-bit.c; + $(CPP) -undef -I ../ginclude -nostdinc -o fp-bit.i fp-bit.c $(CC1) -O2 fp-bit.i rm -f fp-bit.i bash -c 'echo -e ".text\n\t.align\t2, 0\n"' >> fp-bit.s - $(AS) -mcpu=arm7tdmi -o fp-bit.o fp-bit.s; + $(AS) -mcpu=arm7tdmi -o fp-bit.o fp-bit.s rm -f fp-bit.s dp-bit.o: dp-bit.c - $(CPP) -undef -I ../ginclude -nostdinc -o dp-bit.i dp-bit.c; + $(CPP) -undef -I ../ginclude -nostdinc -o dp-bit.i dp-bit.c $(CC1) -O2 dp-bit.i rm -f dp-bit.i bash -c 'echo -e ".text\n\t.align\t2, 0\n"' >> dp-bit.s - $(AS) -mcpu=arm7tdmi -o dp-bit.o dp-bit.s; + $(AS) -mcpu=arm7tdmi -o dp-bit.o dp-bit.s rm -f dp-bit.s fp-bit.c: fp-bit-base.c @@ -94,4 +101,4 @@ dp-bit.c: fp-bit-base.c .PHONY: clean clean: - rm -f *.o *.a *.s *.i \ No newline at end of file + rm -f *.o *.a *.s *.i From 1d6e89930db91ab9e2888aa5eb9a6c19bab32446 Mon Sep 17 00:00:00 2001 From: "Colton G. Rushton" Date: Sat, 18 Jun 2022 18:05:01 -0300 Subject: [PATCH 08/10] Make sure the implicit function declaration errors still come through --- gcc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/Makefile b/gcc/Makefile index abba7270..8a087191 100644 --- a/gcc/Makefile +++ b/gcc/Makefile @@ -24,7 +24,7 @@ VPATH = $(srcdir) CC = gcc -BASE_CFLAGS = -g -std=gnu11 +BASE_CFLAGS = -g -std=gnu11 -Werror-implicit-function-declaration INCLUDES = -I. -I$(srcdir) From 60a72a15b8e00fecc3c5e8534442bc1a3d56acdd Mon Sep 17 00:00:00 2001 From: "Colton G. Rushton" Date: Sat, 18 Jun 2022 18:09:26 -0300 Subject: [PATCH 09/10] unnecessary push/pop fix --- gcc/flags.h | 3 +++ gcc/thumb.c | 7 +++++-- gcc/toplev.c | 10 ++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/gcc/flags.h b/gcc/flags.h index cf2931ff..476b809e 100755 --- a/gcc/flags.h +++ b/gcc/flags.h @@ -454,3 +454,6 @@ extern int flag_hex_asm; /* Nonzero if generated DWARF debug info should match (buggy) original GCC 2.95.x behavior. */ extern int flag_legacy_debug_info; + +/* Nonzero if prologue bug should be fixed. */ +extern int flag_prologue_bugfix; diff --git a/gcc/thumb.c b/gcc/thumb.c index ac122f7c..f773ec08 100755 --- a/gcc/thumb.c +++ b/gcc/thumb.c @@ -717,8 +717,11 @@ far_jump_used_p() rtx insn; #ifndef OLD_COMPILER - if (current_function_has_far_jump) - return 1; + if (!flag_prologue_bugfix) + { + if (current_function_has_far_jump) + return 1; + } #endif for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) diff --git a/gcc/toplev.c b/gcc/toplev.c index 1dae1e7a..1e59335c 100755 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -588,6 +588,9 @@ int flag_hex_asm = 0; /* Use old (buggy) DWARF line info generator. */ int flag_legacy_debug_info = 0; +/* Fix prologue bug in new compiler. */ +int flag_prologue_bugfix = 0; + typedef struct { char *string; @@ -729,6 +732,13 @@ lang_independent_options f_options[] = "Use hex instead of decimal in assembly output"}, {"legacy-debug-line-info", &flag_legacy_debug_info, 1, "Generate old (buggy) DWARF line info"}, + #ifndef OLD_COMPILER + /* This flag fixes a bug in the newer agbcc version that causes `lr` to be + saved onto the stack in functions where it is not necessary. This is + needed to produce matching code for certain GBA games. */ + {"prologue-bugfix", &flag_prologue_bugfix, 1, + "Prevent unnecessary saving of the lr register to the stack"}, +#endif }; #define NUM_ELEM(a) (sizeof (a) / sizeof ((a)[0])) From dccced7d5ad1e09e0929e7a917c0b5456242e6d0 Mon Sep 17 00:00:00 2001 From: "Colton G. Rushton" Date: Sat, 18 Jun 2022 18:29:37 -0300 Subject: [PATCH 10/10] Finish clean script and tweak makefile --- Makefile | 1 - clean.sh | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d21b4c2e..18f90ffe 100644 --- a/Makefile +++ b/Makefile @@ -51,4 +51,3 @@ endif cp ginclude/* $(PREFIX)/tools/agbcc/include/ cp libgcc/libgcc.a $(PREFIX)/tools/agbcc/lib/ cp libc/libc.a $(PREFIX)/tools/agbcc/lib/ - diff --git a/clean.sh b/clean.sh index c6a62d7c..5729262d 100644 --- a/clean.sh +++ b/clean.sh @@ -1,3 +1,4 @@ make -C gcc clean make -C libgcc clean make -C libc clean +rm -f agbcc old_agbcc agbcc_arm libc.a libgcc.a