mirror of
https://github.com/zeldaret/oot.git
synced 2024-11-15 06:06:04 +00:00
Make BSS ordering script check ordering for all sections (#1920)
* Rename bss_reordering.py -> check_ordering.py * Check all segments for ordering issues, not just bss * Reword error message * mapfile_segments -> source_code_segments * Remove redundant vram check
This commit is contained in:
parent
0159d43352
commit
17d683780d
1 changed files with 24 additions and 23 deletions
|
@ -94,10 +94,11 @@ def read_s16(f: BinaryIO, offset: int) -> int:
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description="Report BSS reorderings between the baserom and the current build "
|
description="Report data/bss reorderings between the baserom and the current build "
|
||||||
"by parsing relocations from the built object files and comparing their final values "
|
"by parsing relocations from the built object files and comparing their final values "
|
||||||
"between the baserom and the current build. "
|
"between the baserom and the current build. "
|
||||||
"Assumes that the only differences are due to BSS ordering."
|
"Assumes that the only differences are due to ordering and that the text sections of the "
|
||||||
|
"ROMS are not shifted."
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--oot-version",
|
"--oot-version",
|
||||||
|
@ -118,30 +119,34 @@ def main():
|
||||||
mapfile = mapfile_parser.mapfile.MapFile()
|
mapfile = mapfile_parser.mapfile.MapFile()
|
||||||
mapfile.readMapFile(f"build/{version}/oot-{version}.map")
|
mapfile.readMapFile(f"build/{version}/oot-{version}.map")
|
||||||
|
|
||||||
reloc_mapfile_segments = []
|
# Segments built from source code (filtering out assets)
|
||||||
|
source_code_segments = []
|
||||||
for mapfile_segment in mapfile:
|
for mapfile_segment in mapfile:
|
||||||
if args.segment and mapfile_segment.name != f"..{args.segment}":
|
if (
|
||||||
continue
|
args.segment
|
||||||
if not (
|
and mapfile_segment.name != f"..{args.segment}"
|
||||||
mapfile_segment.name == "..boot"
|
and mapfile_segment.name != f"..{args.segment}.bss"
|
||||||
or mapfile_segment.name == "..code"
|
|
||||||
or (
|
|
||||||
mapfile_segment.name.startswith("..ovl_")
|
|
||||||
and not mapfile_segment.name.endswith(".bss")
|
|
||||||
)
|
|
||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
reloc_mapfile_segments.append(mapfile_segment)
|
if not (
|
||||||
|
mapfile_segment.name.startswith("..boot")
|
||||||
|
or mapfile_segment.name.startswith("..code")
|
||||||
|
or mapfile_segment.name.startswith("..ovl_")
|
||||||
|
):
|
||||||
|
continue
|
||||||
|
source_code_segments.append(mapfile_segment)
|
||||||
|
|
||||||
base = open(f"baseroms/{version}/baserom-decompressed.z64", "rb")
|
base = open(f"baseroms/{version}/baserom-decompressed.z64", "rb")
|
||||||
build = open(f"build/{version}/oot-{version}.z64", "rb")
|
build = open(f"build/{version}/oot-{version}.z64", "rb")
|
||||||
|
|
||||||
# Find all pointers with different values
|
# Find all pointers with different values
|
||||||
pointers = []
|
pointers = []
|
||||||
for mapfile_segment in reloc_mapfile_segments:
|
for mapfile_segment in source_code_segments:
|
||||||
for file in mapfile_segment:
|
for file in mapfile_segment:
|
||||||
if not str(file.filepath).endswith(".o"):
|
if not str(file.filepath).endswith(".o"):
|
||||||
continue
|
continue
|
||||||
|
if file.sectionType == ".bss":
|
||||||
|
continue
|
||||||
for reloc in read_relocs(file.filepath, file.sectionType):
|
for reloc in read_relocs(file.filepath, file.sectionType):
|
||||||
if reloc.offset_32 is not None:
|
if reloc.offset_32 is not None:
|
||||||
base_value = read_u32(base, file.vrom + reloc.offset_32)
|
base_value = read_u32(base, file.vrom + reloc.offset_32)
|
||||||
|
@ -153,8 +158,8 @@ def main():
|
||||||
build, file.vrom + reloc.offset_hi16
|
build, file.vrom + reloc.offset_hi16
|
||||||
):
|
):
|
||||||
print(
|
print(
|
||||||
f"Error: Relocation for {reloc.name} in {file.filepath} references a shifted portion of the ROM.\n"
|
f"Error: Reference to {reloc.name} in {file.filepath} is in a shifted portion of the ROM.\n"
|
||||||
"Please ensure that the only differences between the baserom and the current build are due to BSS reordering.",
|
"Please ensure that the only differences between the baserom and the current build are due to data ordering.",
|
||||||
file=sys.stderr,
|
file=sys.stderr,
|
||||||
)
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
@ -177,20 +182,16 @@ def main():
|
||||||
pointers = list({p.base_value: p for p in pointers}.values())
|
pointers = list({p.base_value: p for p in pointers}.values())
|
||||||
pointers.sort(key=lambda p: p.base_value)
|
pointers.sort(key=lambda p: p.base_value)
|
||||||
|
|
||||||
# Go through BSS sections and report differences
|
# Go through sections and report differences
|
||||||
i = 0
|
for mapfile_segment in source_code_segments:
|
||||||
for mapfile_segment in mapfile:
|
|
||||||
for file in mapfile_segment:
|
for file in mapfile_segment:
|
||||||
if not file.sectionType == ".bss":
|
|
||||||
continue
|
|
||||||
|
|
||||||
pointers_in_section = [
|
pointers_in_section = [
|
||||||
p for p in pointers if file.vram <= p.build_value < file.vram + file.size
|
p for p in pointers if file.vram <= p.build_value < file.vram + file.size
|
||||||
]
|
]
|
||||||
if not pointers_in_section:
|
if not pointers_in_section:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
print(f"{file.filepath} BSS is reordered:")
|
print(f"{file.filepath} {file.sectionType} is reordered:")
|
||||||
for i, p in enumerate(pointers_in_section):
|
for i, p in enumerate(pointers_in_section):
|
||||||
if p.addend > 0:
|
if p.addend > 0:
|
||||||
addend_str = f"+0x{p.addend:X}"
|
addend_str = f"+0x{p.addend:X}"
|
Loading…
Reference in a new issue