summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerek Hensley <hensley.derek58@gmail.com>2024-09-19 18:22:39 -0700
committerGitHub <noreply@github.com>2024-09-19 18:22:39 -0700
commit5c6310306f0a494c6fa54436b6fce5ef2ff0d715 (patch)
tree5df7c7d9fef309bd4071de6643d26b6f8032c467
parent34dcfbccc6c64a9394b54e6968791da92fcd18f5 (diff)
Remove include_data_with_rodata spec hack by incremental link of z_game_over (#1691)
-rw-r--r--Makefile11
-rw-r--r--linker_scripts/audio_table_rodata.ld17
-rw-r--r--linker_scripts/data_with_rodata.ld22
-rw-r--r--spec2
-rw-r--r--tools/buildtools/mkldscript.c15
-rw-r--r--tools/buildtools/spec.c5
-rw-r--r--tools/buildtools/spec.h2
7 files changed, 38 insertions, 36 deletions
diff --git a/Makefile b/Makefile
index e25e98f23..50e45425e 100644
--- a/Makefile
+++ b/Makefile
@@ -556,6 +556,15 @@ $(BUILD_DIR)/src/overlays/%_reloc.o: $(BUILD_DIR)/$(SPEC)
$(FADO) $$(tools/buildtools/reloc_prereq $< $(*F)) -n $(*F) -o $(@:.o=.s) -M $(@:.o=.d)
$(AS) $(ASFLAGS) $(ENDIAN) $(IINC) $(@:.o=.s) -o $@
+# Incremental link z_game_over data into rodata
+$(BUILD_DIR)/src/code/z_game_over.o: src/code/z_game_over.c
+ $(CC_CHECK_COMP) $(CC_CHECK_FLAGS) $(IINC) $(CC_CHECK_WARNINGS) $(C_DEFINES) $(MIPS_BUILTIN_DEFS) -o $(@:.o=.tmp) $<
+ $(CC) -c $(CFLAGS) $(IINC) $(WARNINGS) $(C_DEFINES) $(MIPS_VERSION) $(ENDIAN) $(OPTFLAGS) -o $(@:.o=.tmp) $<
+ $(LD) -r -T linker_scripts/data_with_rodata.ld $(@:.o=.tmp) -o $@
+ @$(RM) $(@:.o=.tmp)
+ $(OBJDUMP_CMD)
+ $(RM_MDEBUG)
+
$(SHIFTJIS_O_FILES): $(BUILD_DIR)/src/%.o: src/%.c
$(SHIFTJIS_CONV) -o $(@:.o=.enc.c) $<
$(CC_CHECK_COMP) $(CC_CHECK_FLAGS) $(IINC) $(CC_CHECK_WARNINGS) $(C_DEFINES) $(MIPS_BUILTIN_DEFS) -o $@ $(@:.o=.enc.c)
@@ -731,7 +740,7 @@ $(BUILD_DIR)/src/audio/tables/sequence_table.o: CFLAGS += -I include/tables
$(BUILD_DIR)/src/audio/tables/%.o: src/audio/tables/%.c
$(CC_CHECK_COMP) $(CC_CHECK_FLAGS) $(IINC) $(CC_CHECK_WARNINGS) $(C_DEFINES) $(MIPS_BUILTIN_DEFS) -o $(@:.o=.tmp) $<
$(CC) -c $(CFLAGS) $(IINC) $(WARNINGS) $(C_DEFINES) $(MIPS_VERSION) $(ENDIAN) $(OPTFLAGS) -o $(@:.o=.tmp) $<
- $(LD) -r -T linker_scripts/audio_table_rodata.ld $(@:.o=.tmp) -o $@
+ $(LD) -r -T linker_scripts/data_with_rodata.ld $(@:.o=.tmp) -o $@
@$(RM) $(@:.o=.tmp)
$(RM_MDEBUG)
diff --git a/linker_scripts/audio_table_rodata.ld b/linker_scripts/audio_table_rodata.ld
deleted file mode 100644
index 27eab49fc..000000000
--- a/linker_scripts/audio_table_rodata.ld
+++ /dev/null
@@ -1,17 +0,0 @@
-OUTPUT_ARCH (mips)
-
-/* Audio Table Linker Script, maps data into rodata */
-
-SECTIONS {
-
- .rodata :
- {
- *(.data*)
- *(.rodata*)
- }
-
- /DISCARD/ :
- {
- *(*);
- }
-}
diff --git a/linker_scripts/data_with_rodata.ld b/linker_scripts/data_with_rodata.ld
new file mode 100644
index 000000000..07b69cda5
--- /dev/null
+++ b/linker_scripts/data_with_rodata.ld
@@ -0,0 +1,22 @@
+OUTPUT_ARCH (mips)
+
+/* Maps data into rodata, used for audio tables and z_game_over */
+
+SECTIONS {
+ .rodata :
+ {
+ *(.data)
+ *(.rodata)
+ *(.rodata.str*)
+ *(.rodata.cst*)
+ }
+
+ /DISCARD/ :
+ {
+ /* GNU ld assumes that the linker script always combines .gptab.data and
+ * .gptab.sdata into .gptab.sdata, and likewise for .gptab.bss and .gptab.sbss.
+ * To avoid dealing with this, we just discard all .gptab sections.
+ */
+ *(.gptab.*)
+ }
+}
diff --git a/spec b/spec
index e3030f1b0..4491b0756 100644
--- a/spec
+++ b/spec
@@ -773,7 +773,7 @@ beginseg
include "$(BUILD_DIR)/src/audio/session_config.o"
include "$(BUILD_DIR)/src/code/jpegutils.o"
include "$(BUILD_DIR)/src/code/jpegdecoder.o"
- include_data_with_rodata "$(BUILD_DIR)/src/code/z_game_over.o"
+ include "$(BUILD_DIR)/src/code/z_game_over.o"
include "$(BUILD_DIR)/src/code/z_construct.o"
include "$(BUILD_DIR)/src/audio/tables/soundfont_table.o"
include "$(BUILD_DIR)/assets/audio/sequence_font_table.o"
diff --git a/tools/buildtools/mkldscript.c b/tools/buildtools/mkldscript.c
index 76191b86d..6a9a066e4 100644
--- a/tools/buildtools/mkldscript.c
+++ b/tools/buildtools/mkldscript.c
@@ -85,11 +85,10 @@ static void write_ld_script(FILE* fout) {
fprintf(fout, " _%sSegmentDataStart = .;\n", seg->name);
for (j = 0; j < seg->includesCount; j++) {
- if (!seg->includes[j].dataWithRodata)
- fprintf(fout,
- " %s (.data)\n"
- " . = ALIGN(0x10);\n",
- seg->includes[j].fpath);
+ fprintf(fout,
+ " %s (.data)\n"
+ " . = ALIGN(0x10);\n",
+ seg->includes[j].fpath);
}
/*
@@ -109,12 +108,6 @@ static void write_ld_script(FILE* fout) {
fprintf(fout, " _%sSegmentRoDataStart = .;\n", seg->name);
for (j = 0; j < seg->includesCount; j++) {
- if (seg->includes[j].dataWithRodata)
- fprintf(fout,
- " %s (.data)\n"
- " . = ALIGN(0x10);\n",
- seg->includes[j].fpath);
-
fprintf(fout,
" %s (.rodata)\n"
" . = ALIGN(0x10);\n",
diff --git a/tools/buildtools/spec.c b/tools/buildtools/spec.c
index 26c3c134d..86620c628 100644
--- a/tools/buildtools/spec.c
+++ b/tools/buildtools/spec.c
@@ -124,7 +124,6 @@ static const char* const stmtNames[] = {
[STMT_entry] = "entry",
[STMT_flags] = "flags",
[STMT_include] = "include",
- [STMT_include_data_with_rodata] = "include_data_with_rodata",
[STMT_name] = "name",
[STMT_number] = "number",
[STMT_romalign] = "romalign",
@@ -147,7 +146,7 @@ STMTId get_stmt_id_by_stmt_name(const char* stmtName, int lineNum) {
bool parse_segment_statement(struct Segment* currSeg, STMTId stmt, char* args, int lineNum) {
// ensure no duplicates (except for 'include' or 'pad_text')
- if (stmt != STMT_include && stmt != STMT_include_data_with_rodata && stmt != STMT_pad_text &&
+ if (stmt != STMT_include && stmt != STMT_pad_text &&
(currSeg->fields & (1 << stmt)))
util_fatal_error("line %i: duplicate '%s' statement", lineNum, stmtNames[stmt]);
@@ -208,7 +207,6 @@ bool parse_segment_statement(struct Segment* currSeg, STMTId stmt, char* args, i
break;
case STMT_include:
- case STMT_include_data_with_rodata:
currSeg->includesCount++;
currSeg->includes = realloc(currSeg->includes, currSeg->includesCount * sizeof(*currSeg->includes));
@@ -216,7 +214,6 @@ bool parse_segment_statement(struct Segment* currSeg, STMTId stmt, char* args, i
util_fatal_error("line %i: invalid filename", lineNum);
currSeg->includes[currSeg->includesCount - 1].linkerPadding = 0;
- currSeg->includes[currSeg->includesCount - 1].dataWithRodata = (stmt == STMT_include_data_with_rodata);
break;
case STMT_increment:
if (!parse_number(args, &currSeg->increment))
diff --git a/tools/buildtools/spec.h b/tools/buildtools/spec.h
index 8d9a66b26..2c86507ce 100644
--- a/tools/buildtools/spec.h
+++ b/tools/buildtools/spec.h
@@ -14,7 +14,6 @@ typedef enum {
STMT_entry,
STMT_flags,
STMT_include,
- STMT_include_data_with_rodata,
STMT_name,
STMT_number,
STMT_romalign,
@@ -34,7 +33,6 @@ enum {
struct Include {
char* fpath;
int linkerPadding;
- uint8_t dataWithRodata;
};
typedef struct Segment {