From 0767f4b9ce0ad9dd86e83f5a09674cbc6559df29 Mon Sep 17 00:00:00 2001 From: Michael Panzlaff Date: Sat, 17 Apr 2021 19:00:02 +0200 Subject: [PATCH 1/5] Makefile: resolve libgcc and libc in correct order When actually utilizing functions from libc, linking will fail because the functions used from libc have to be defined after libc. This is the case with libgcc, so we swap their order. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d97634399..c76c24a5d 100644 --- a/Makefile +++ b/Makefile @@ -82,7 +82,7 @@ endif LDFLAGS = -Map ../../$(MAP) -LIB := $(LIBPATH) -lgcc -lc -L../../libagbsyscall -lagbsyscall +LIB := $(LIBPATH) -lc -lgcc -L../../libagbsyscall -lagbsyscall SHA1 := $(shell { command -v sha1sum || command -v shasum; } 2>/dev/null) -c GFX := tools/gbagfx/gbagfx$(EXE) From 7a480adafe1f1f8f5b764ad21a7f8e113c63cb1f Mon Sep 17 00:00:00 2001 From: Michael Panzlaff Date: Sat, 17 Apr 2021 22:46:15 +0200 Subject: [PATCH 2/5] modern: add missing sections to linkerscript In order to correctly link a program which uses libc functions a few sections are required to satisfy the linker. This currently adds 0x3C bytes to IWRAM. --- ld_script_modern.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ld_script_modern.txt b/ld_script_modern.txt index b69ada864..6f8d38453 100644 --- a/ld_script_modern.txt +++ b/ld_script_modern.txt @@ -27,6 +27,8 @@ SECTIONS { /* .bss starts at 0x3000000 */ src/*.o(.bss); gflib/*.o(.bss); + *libc.a:*.o(.bss); + *libnosys.a:*.o(.bss); /* .bss.code starts at 0x3001AA8 */ src/m4a.o(.bss.code); @@ -34,7 +36,8 @@ SECTIONS { /* COMMON starts at 0x30022A8 */ src/*.o(COMMON); gflib/*.o(COMMON); - *libc.a:sbrkr.o(COMMON); + *libc.a:*.o(COMMON); + *libnosys.a:*.o(COMMON); end = .; . = 0x8000; } @@ -82,6 +85,7 @@ SECTIONS { *libagbsyscall.a:*.o(.text*); *libgcc.a:*.o(.text*); *libc.a:*.o(.text*); + *libnosys.a:*.o(.text*); src/libisagbprn.o(.text); } =0 From 38d0cca903b4cc886bf0ed2a4d5714f20b14caef Mon Sep 17 00:00:00 2001 From: Michael Panzlaff Date: Sat, 17 Apr 2021 22:48:57 +0200 Subject: [PATCH 3/5] modern: link against libnosys Without libnosys undefined references will occur if libc functions are used. --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index c76c24a5d..33cde3a01 100644 --- a/Makefile +++ b/Makefile @@ -72,7 +72,7 @@ CC1 = $(shell $(CC) --print-prog-name=cc1) -quiet override CFLAGS += -mthumb -mthumb-interwork -O2 -mabi=apcs-gnu -mtune=arm7tdmi -march=armv4t -fno-toplevel-reorder -Wno-pointer-to-int-cast -g ROM := pokeemerald_modern.gba OBJ_DIR := build/modern -LIBPATH := -L "$(dir $(shell $(CC) -mthumb -print-file-name=libgcc.a))" -L "$(dir $(shell $(CC) -mthumb -print-file-name=libc.a))" +LIBPATH := -L "$(dir $(shell $(CC) -mthumb -print-file-name=libgcc.a))" -L "$(dir $(shell $(CC) -mthumb -print-file-name=libnosys.a))" -L "$(dir $(shell $(CC) -mthumb -print-file-name=libc.a))" endif CPPFLAGS := -iquote include -iquote $(GFLIB_SUBDIR) -Wno-trigraphs -DMODERN=$(MODERN) @@ -82,7 +82,7 @@ endif LDFLAGS = -Map ../../$(MAP) -LIB := $(LIBPATH) -lc -lgcc -L../../libagbsyscall -lagbsyscall +LIB := $(LIBPATH) -lc -lnosys -lgcc -L../../libagbsyscall -lagbsyscall SHA1 := $(shell { command -v sha1sum || command -v shasum; } 2>/dev/null) -c GFX := tools/gbagfx/gbagfx$(EXE) From 2859fa60cb6fd863f9c2bf5b9219ff2045a7d229 Mon Sep 17 00:00:00 2001 From: Michael Panzlaff Date: Sat, 17 Apr 2021 23:19:01 +0200 Subject: [PATCH 4/5] Makefile: use different linker library sets for modern --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 33cde3a01..3cbd7f3f8 100644 --- a/Makefile +++ b/Makefile @@ -67,12 +67,14 @@ override CFLAGS += -mthumb-interwork -Wimplicit -Wparentheses -Werror -O2 -fhex- ROM := pokeemerald.gba OBJ_DIR := build/emerald LIBPATH := -L ../../tools/agbcc/lib +LIB := $(LIBPATH) -lgcc -lc -L../../libagbsyscall -lagbsyscall else CC1 = $(shell $(CC) --print-prog-name=cc1) -quiet override CFLAGS += -mthumb -mthumb-interwork -O2 -mabi=apcs-gnu -mtune=arm7tdmi -march=armv4t -fno-toplevel-reorder -Wno-pointer-to-int-cast -g ROM := pokeemerald_modern.gba OBJ_DIR := build/modern LIBPATH := -L "$(dir $(shell $(CC) -mthumb -print-file-name=libgcc.a))" -L "$(dir $(shell $(CC) -mthumb -print-file-name=libnosys.a))" -L "$(dir $(shell $(CC) -mthumb -print-file-name=libc.a))" +LIB := $(LIBPATH) -lc -lnosys -lgcc -L../../libagbsyscall -lagbsyscall endif CPPFLAGS := -iquote include -iquote $(GFLIB_SUBDIR) -Wno-trigraphs -DMODERN=$(MODERN) @@ -82,8 +84,6 @@ endif LDFLAGS = -Map ../../$(MAP) -LIB := $(LIBPATH) -lc -lnosys -lgcc -L../../libagbsyscall -lagbsyscall - SHA1 := $(shell { command -v sha1sum || command -v shasum; } 2>/dev/null) -c GFX := tools/gbagfx/gbagfx$(EXE) AIF := tools/aif2pcm/aif2pcm$(EXE) From 783a167b76bef461f47d425ecc11c0b9fda30c77 Mon Sep 17 00:00:00 2001 From: Michael Panzlaff Date: Wed, 5 May 2021 00:49:42 +0200 Subject: [PATCH 5/5] ld_script_modern: minor fixes for gcc 11 --- ld_script_modern.txt | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/ld_script_modern.txt b/ld_script_modern.txt index 6f8d38453..59d032bb2 100644 --- a/ld_script_modern.txt +++ b/ld_script_modern.txt @@ -27,8 +27,8 @@ SECTIONS { /* .bss starts at 0x3000000 */ src/*.o(.bss); gflib/*.o(.bss); - *libc.a:*.o(.bss); - *libnosys.a:*.o(.bss); + *libc.a:*.o(.bss*); + *libnosys.a:*.o(.bss*); /* .bss.code starts at 0x3001AA8 */ src/m4a.o(.bss.code); @@ -47,19 +47,10 @@ SECTIONS { .text : ALIGN(4) { - src/crt0.o(.text); - src/*.o(.text); - gflib/*.o(.text); - asm/*.o(.text); - } =0 - - .text.unlikely : - ALIGN(4) - { - src/crt0.o(.text.unlikely); - src/*.o(.text.unlikely); - gflib/*.o(.text.unlikely); - asm/*.o(.text.unlikely); + src/crt0.o(.text*); + src/*.o(.text*); + gflib/*.o(.text*); + asm/*.o(.text*); } =0 script_data :