From 5c6310306f0a494c6fa54436b6fce5ef2ff0d715 Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Thu, 19 Sep 2024 18:22:39 -0700 Subject: [PATCH] Remove include_data_with_rodata spec hack by incremental link of z_game_over (#1691) --- Makefile | 11 ++++++++++- linker_scripts/audio_table_rodata.ld | 17 ----------------- linker_scripts/data_with_rodata.ld | 22 ++++++++++++++++++++++ spec | 2 +- tools/buildtools/mkldscript.c | 15 ++++----------- tools/buildtools/spec.c | 5 +---- tools/buildtools/spec.h | 2 -- 7 files changed, 38 insertions(+), 36 deletions(-) delete mode 100644 linker_scripts/audio_table_rodata.ld create mode 100644 linker_scripts/data_with_rodata.ld diff --git a/Makefile b/Makefile index e25e98f232..50e45425ec 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 27eab49fc4..0000000000 --- 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 0000000000..07b69cda56 --- /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 e3030f1b0f..4491b07563 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 76191b86d8..6a9a066e4f 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 26c3c134da..86620c628b 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 8d9a66b264..2c86507ce0 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 {