From b11e16421d857f5fc030f128ac695bab4f7e8fa0 Mon Sep 17 00:00:00 2001 From: WhenGryphonsFly <84215159+WhenGryphonsFly@users.noreply.github.com> Date: Tue, 6 Jun 2023 12:26:35 -0500 Subject: [PATCH 1/2] Fix prologue issue --- gcc/flags.h | 3 +++ gcc/thumb.c | 7 +++++-- gcc/toplev.c | 13 +++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/gcc/flags.h b/gcc/flags.h index 52f5228a..39e998e7 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 be corrected rather than match the original (buggy) GCC 2.95.x output. */ extern int flag_fixed_debug_line_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 0629081e..696598e3 100755 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -588,6 +588,9 @@ int flag_hex_asm = 0; /* Fix buggy DWARF line info generation. */ int flag_fixed_debug_line_info = 0; +/* Fix prologue bug in new compiler. */ +int flag_prologue_bugfix = 0; + typedef struct { char *string; @@ -729,6 +732,16 @@ lang_independent_options f_options[] = "Use hex instead of decimal in assembly output"}, {"fix-debug-line", &flag_fixed_debug_line_info, 1, "Generate fixed DWARF line info"}, + /* 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. + + This flag is defined under OLD_COMPILER to prevent a situation where a game + that uses both agbcc and old_agbcc (e.g., pokepinballrs) needs to maintain two + separate lists of flags depending on the compiler used for a specific file. + Otherwise, old_agbcc will throw an error. */ + {"prologue-bugfix", &flag_prologue_bugfix, 1, + "Prevent unnecessary saving of the lr register to the stack"}, }; #define NUM_ELEM(a) (sizeof (a) / sizeof ((a)[0])) From 5458d3dfa12e6ec3dce3ddc79ce4a658d377accc Mon Sep 17 00:00:00 2001 From: WhenGryphonsFly <84215159+WhenGryphonsFly@users.noreply.github.com> Date: Tue, 6 Jun 2023 15:44:19 -0500 Subject: [PATCH 2/2] Update toplev.c --- gcc/toplev.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/gcc/toplev.c b/gcc/toplev.c index 696598e3..f707c28b 100755 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -732,16 +732,13 @@ lang_independent_options f_options[] = "Use hex instead of decimal in assembly output"}, {"fix-debug-line", &flag_fixed_debug_line_info, 1, "Generate fixed 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. - - This flag is defined under OLD_COMPILER to prevent a situation where a game - that uses both agbcc and old_agbcc (e.g., pokepinballrs) needs to maintain two - separate lists of flags depending on the compiler used for a specific file. - Otherwise, old_agbcc will throw an error. */ + 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]))