Moved symbol tomls to submodule, switched from objcopy to recompiler output binary mechanism for patch recompilation

This commit is contained in:
Mr-Wiseguy 2024-06-28 21:22:50 -04:00
parent 49901d8ce1
commit b765e8d3c8
8 changed files with 16 additions and 69008 deletions

3
.gitmodules vendored
View File

@ -19,3 +19,6 @@
[submodule "lib/N64ModernRuntime"] [submodule "lib/N64ModernRuntime"]
path = lib/N64ModernRuntime path = lib/N64ModernRuntime
url = https://github.com/N64Recomp/N64ModernRuntime.git url = https://github.com/N64Recomp/N64ModernRuntime.git
[submodule "Zelda64RecompSyms"]
path = Zelda64RecompSyms
url = https://github.com:Zelda64Recomp/Zelda64RecompSyms

View File

@ -95,7 +95,7 @@ endif()
add_custom_target(PatchesBin add_custom_target(PatchesBin
COMMAND ${CMAKE_COMMAND} -E env CC=${PATCHES_C_COMPILER} LD=${PATCHES_LD} OBJCOPY=${PATCHES_OBJCOPY} make COMMAND ${CMAKE_COMMAND} -E env CC=${PATCHES_C_COMPILER} LD=${PATCHES_LD} OBJCOPY=${PATCHES_OBJCOPY} make
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/patches WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/patches
BYPRODUCTS ${CMAKE_SOURCE_DIR}/patches/patches.bin BYPRODUCTS ${CMAKE_SOURCE_DIR}/patches/patches.elf
) )
# Generate patches_bin.c from patches.bin # Generate patches_bin.c from patches.bin
@ -104,15 +104,16 @@ add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/RecompiledPatches/patches_bin.c
DEPENDS ${CMAKE_SOURCE_DIR}/patches/patches.bin DEPENDS ${CMAKE_SOURCE_DIR}/patches/patches.bin
) )
# Recompile patches elf into patches.c # Recompile patches elf into patches.c and patches.bin
add_custom_command(OUTPUT add_custom_command(OUTPUT
${CMAKE_SOURCE_DIR}/patches/patches.bin
${CMAKE_SOURCE_DIR}/RecompiledPatches/patches.c ${CMAKE_SOURCE_DIR}/RecompiledPatches/patches.c
${CMAKE_SOURCE_DIR}/RecompiledPatches/recomp_overlays.inl ${CMAKE_SOURCE_DIR}/RecompiledPatches/recomp_overlays.inl
${CMAKE_SOURCE_DIR}/RecompiledPatches/funcs.h ${CMAKE_SOURCE_DIR}/RecompiledPatches/funcs.h
# TODO: Look into why modifying patches requires two builds to take # TODO: Look into why modifying patches requires two builds to take
COMMAND ./N64Recomp patches.toml COMMAND ./N64Recomp patches.toml
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
DEPENDS ${CMAKE_SOURCE_DIR}/patches/patches.bin DEPENDS ${CMAKE_SOURCE_DIR}/patches/patches.elf
) )
# Download controller db file for controller support via SDL2 # Download controller db file for controller support via SDL2

1
Zelda64RecompSyms Submodule

@ -0,0 +1 @@
Subproject commit 8e93e558b04cc6866b635838099823f51a3941a0

View File

@ -10,5 +10,7 @@ use_absolute_symbols = true
# Emit R_MIPS_32 relocations so they can be populated when loading the patch overlay. # Emit R_MIPS_32 relocations so they can be populated when loading the patch overlay.
emit_mips_32_relocs = true emit_mips_32_relocs = true
# Point the recompiler at the symbol files so that it can resolve relocations during recompilation. # Point the recompiler at the symbol files so that it can resolve relocations during recompilation.
func_reference_syms_file = "us.rev1.syms.toml" func_reference_syms_file = "Zelda64RecompSyms/mm.us.rev1.syms.toml"
data_reference_syms_files = [ "us.rev1.datasyms.toml", "us.rev1.datasyms_static.toml" ] data_reference_syms_files = [ "Zelda64RecompSyms/mm.us.rev1.datasyms.toml", "Zelda64RecompSyms/mm.us.rev1.datasyms_static.toml" ]
# Tell the recompiler to write the output binary. Doing this instead of using objcopy allows the recompiler to patch MIPS32 relocs.
output_binary_path = "patches/patches.bin"

View File

@ -2,24 +2,17 @@ TARGET = patches.elf
CC ?= clang CC ?= clang
LD ?= ld.lld LD ?= ld.lld
OBJCOPY ?= llvm-objcopy
CFLAGS := -target mips -mips2 -mabi=32 -O2 -G0 -mno-abicalls -mno-odd-spreg -mno-check-zero-division \ CFLAGS := -target mips -mips2 -mabi=32 -O2 -G0 -mno-abicalls -mno-odd-spreg -mno-check-zero-division \
-fomit-frame-pointer -ffast-math -fno-unsafe-math-optimizations -fno-builtin-memset \ -fomit-frame-pointer -ffast-math -fno-unsafe-math-optimizations -fno-builtin-memset \
-Wall -Wextra -Wno-incompatible-library-redeclaration -Wno-unused-parameter -Wno-unknown-pragmas -Wno-unused-variable -Wno-missing-braces -Wno-unsupported-floating-point-opt -Wall -Wextra -Wno-incompatible-library-redeclaration -Wno-unused-parameter -Wno-unknown-pragmas -Wno-unused-variable -Wno-missing-braces -Wno-unsupported-floating-point-opt
CPPFLAGS := -nostdinc -D_LANGUAGE_C -DMIPS -I dummy_headers -I ../lib/mm-decomp/include -I ../lib/mm-decomp/src -I ../lib/mm-decomp/assets -I../lib/rt64/include CPPFLAGS := -nostdinc -D_LANGUAGE_C -DMIPS -I dummy_headers -I ../lib/mm-decomp/include -I ../lib/mm-decomp/src -I ../lib/mm-decomp/assets -I../lib/rt64/include
LDFLAGS := -nostdlib -T patches.ld -T syms.ld -Map patches.map --unresolved-symbols=ignore-all --emit-relocs LDFLAGS := -nostdlib -T patches.ld -T syms.ld -Map patches.map --unresolved-symbols=ignore-all --emit-relocs
BINFLAGS := -O binary --only-section=.ctors --only-section=.dtors --only-section=.rodata --only-section=.data
C_SRCS := $(wildcard *.c) C_SRCS := $(wildcard *.c)
C_OBJS := $(C_SRCS:.c=.o) C_OBJS := $(C_SRCS:.c=.o)
C_DEPS := $(C_SRCS:.c=.d) C_DEPS := $(C_SRCS:.c=.d)
DATABIN := $(TARGET:.elf=.bin)
$(DATABIN): $(TARGET)
$(OBJCOPY) $(BINFLAGS) $(TARGET) $@
$(TARGET): $(C_OBJS) patches.ld syms.ld $(TARGET): $(C_OBJS) patches.ld syms.ld
$(LD) $(C_OBJS) $(LDFLAGS) -o $@ $(LD) $(C_OBJS) $(LDFLAGS) -o $@
@ -27,7 +20,7 @@ $(C_OBJS): %.o : %.c
$(CC) $(CFLAGS) $(CPPFLAGS) $< -MMD -MF $(@:.o=.d) -c -o $@ $(CC) $(CFLAGS) $(CPPFLAGS) $< -MMD -MF $(@:.o=.d) -c -o $@
clean: clean:
rm -rf $(C_OBJS) $(TARGET) $(DATABIN) $(C_DEPS) rm -rf $(C_OBJS) $(TARGET) $(C_DEPS)
-include $(C_DEPS) -include $(C_DEPS)

View File

@ -9,16 +9,11 @@ MEMORY {
SECTIONS { SECTIONS {
.ctors : { *(.ctors*) *(.init_array*) } >extram AT >rom .ctors : { *(.ctors*) *(.init_array*) } >extram AT >rom
.dtors : { *(.dtors*) } >extram AT >rom .dtors : { *(.dtors*) } >extram AT >rom
.text : { *(.text*) } >extram AT >rom
.rodata : { *(.rodata*) } >extram AT >rom .rodata : { *(.rodata*) } >extram AT >rom
.data : { *(.data*) } >extram AT >rom .data : { *(.data*) } >extram AT >rom
.bss (NOLOAD) : { *(.bss*) *(COMMON) } >extram
/* The following sections will be removed from the objcopy */
/* bss isn't noload to make .text rom addresses valid for the recompiler */
.bss : { *(.bss*) *(COMMON) } >extram AT >rom
ASSERT(. < RAMBASE + EXTRA_RAM_SIZE, "Maxed out recomp extra ram") ASSERT(. < RAMBASE + EXTRA_RAM_SIZE, "Maxed out recomp extra ram")
/* Padding to push .text to avoid conflicts with original function addresses */
.pad : { . += 0x1000000; } >extram AT >rom
.text : { *(.text*) } >extram AT >rom
.reloc 0 : { *(.reloc*) } .reloc 0 : { *(.reloc*) }
.symtab 0 : { *(.symtab) } .symtab 0 : { *(.symtab) }

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,7 @@ entrypoint = 0x80080000
# Paths are relative to the location of this config file. # Paths are relative to the location of this config file.
output_func_path = "RecompiledFuncs" output_func_path = "RecompiledFuncs"
relocatable_sections_path = "overlays.us.rev1.txt" relocatable_sections_path = "overlays.us.rev1.txt"
symbols_file_path = "us.rev1.syms.toml" symbols_file_path = "Zelda64RecompSyms/mm.us.rev1.syms.toml"
rom_file_path = "mm.us.rev1.rom_uncompressed.z64" rom_file_path = "mm.us.rev1.rom_uncompressed.z64"
[patches] [patches]