Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix most warnings, parallel builds, unnecessary push/pop, debug parameters, remove gcc_arm configure artifacts, remove forced DEVKITARM, and add README and clean script #53

Closed
wants to merge 11 commits into from
Closed
53 changes: 53 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
.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/
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 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.

To clean your build directory, simply run:
`./clean.sh`

and your compiler will be ready for another compile
33 changes: 16 additions & 17 deletions build.sh
Original file line number Diff line number Diff line change
@@ -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 .
4 changes: 4 additions & 0 deletions clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +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
4 changes: 2 additions & 2 deletions gcc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#Boston MA 02111-1307, USA.

# Directory where sources are, from where we are.
srcdir = .
srcdir ?= .
VPATH = $(srcdir)

CC = gcc
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion gcc/c-typeck.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
46 changes: 44 additions & 2 deletions gcc/dwarf2out.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -3697,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). */
Expand Down Expand Up @@ -4301,6 +4313,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;
Expand All @@ -4313,22 +4326,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",
Expand Down Expand Up @@ -4423,6 +4458,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)
Expand Down Expand Up @@ -4738,6 +4776,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
Expand Down
7 changes: 7 additions & 0 deletions gcc/flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,3 +450,10 @@ 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;

/* Nonzero if prologue bug should be fixed. */
extern int flag_prologue_bugfix;
1 change: 1 addition & 0 deletions gcc/genrecog.c
Original file line number Diff line number Diff line change
Expand Up @@ -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}},
Expand Down
2 changes: 1 addition & 1 deletion gcc/real.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion gcc/rtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
7 changes: 5 additions & 2 deletions gcc/thumb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion gcc/thumb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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), (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. */
Expand Down
17 changes: 16 additions & 1 deletion gcc/toplev.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,12 @@ 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;

/* Fix prologue bug in new compiler. */
int flag_prologue_bugfix = 0;

typedef struct
{
char *string;
Expand Down Expand Up @@ -724,6 +730,15 @@ 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"},
#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]))
Expand Down Expand Up @@ -1046,7 +1061,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);
Expand Down
21 changes: 0 additions & 21 deletions gcc_arm/Make-hooks

This file was deleted.

Empty file removed gcc_arm/Make-host
Empty file.
Empty file removed gcc_arm/Make-lang
Empty file.
Loading