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():
|
||||
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 "
|
||||
"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(
|
||||
"--oot-version",
|
||||
|
@ -118,30 +119,34 @@ def main():
|
|||
mapfile = mapfile_parser.mapfile.MapFile()
|
||||
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:
|
||||
if args.segment and mapfile_segment.name != f"..{args.segment}":
|
||||
continue
|
||||
if not (
|
||||
mapfile_segment.name == "..boot"
|
||||
or mapfile_segment.name == "..code"
|
||||
or (
|
||||
mapfile_segment.name.startswith("..ovl_")
|
||||
and not mapfile_segment.name.endswith(".bss")
|
||||
)
|
||||
if (
|
||||
args.segment
|
||||
and mapfile_segment.name != f"..{args.segment}"
|
||||
and mapfile_segment.name != f"..{args.segment}.bss"
|
||||
):
|
||||
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")
|
||||
build = open(f"build/{version}/oot-{version}.z64", "rb")
|
||||
|
||||
# Find all pointers with different values
|
||||
pointers = []
|
||||
for mapfile_segment in reloc_mapfile_segments:
|
||||
for mapfile_segment in source_code_segments:
|
||||
for file in mapfile_segment:
|
||||
if not str(file.filepath).endswith(".o"):
|
||||
continue
|
||||
if file.sectionType == ".bss":
|
||||
continue
|
||||
for reloc in read_relocs(file.filepath, file.sectionType):
|
||||
if reloc.offset_32 is not None:
|
||||
base_value = read_u32(base, file.vrom + reloc.offset_32)
|
||||
|
@ -153,8 +158,8 @@ def main():
|
|||
build, file.vrom + reloc.offset_hi16
|
||||
):
|
||||
print(
|
||||
f"Error: Relocation for {reloc.name} in {file.filepath} references 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.",
|
||||
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 data ordering.",
|
||||
file=sys.stderr,
|
||||
)
|
||||
sys.exit(1)
|
||||
|
@ -177,20 +182,16 @@ def main():
|
|||
pointers = list({p.base_value: p for p in pointers}.values())
|
||||
pointers.sort(key=lambda p: p.base_value)
|
||||
|
||||
# Go through BSS sections and report differences
|
||||
i = 0
|
||||
for mapfile_segment in mapfile:
|
||||
# Go through sections and report differences
|
||||
for mapfile_segment in source_code_segments:
|
||||
for file in mapfile_segment:
|
||||
if not file.sectionType == ".bss":
|
||||
continue
|
||||
|
||||
pointers_in_section = [
|
||||
p for p in pointers if file.vram <= p.build_value < file.vram + file.size
|
||||
]
|
||||
if not pointers_in_section:
|
||||
continue
|
||||
|
||||
print(f"{file.filepath} BSS is reordered:")
|
||||
print(f"{file.filepath} {file.sectionType} is reordered:")
|
||||
for i, p in enumerate(pointers_in_section):
|
||||
if p.addend > 0:
|
||||
addend_str = f"+0x{p.addend:X}"
|
Loading…
Reference in a new issue