1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-12-25 06:06:05 +00:00

Detect shifted .bss sections in check_ordering.py (#1992)

* Restrict check_ordering.py to .bss sections by default

* Detect shifted .bss sections in check_ordering.py
This commit is contained in:
cadmic 2024-07-27 19:29:15 -07:00 committed by GitHub
parent 7244cd62a5
commit 294da9e355
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -94,7 +94,7 @@ def read_s16(f: BinaryIO, offset: int) -> int:
def main():
parser = argparse.ArgumentParser(
description="Report data/bss reorderings between the baserom and the current build "
description="Report 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 ordering and that the text sections of the "
@ -112,6 +112,11 @@ def main():
type=str,
help="ROM segment to check, e.g. 'boot', 'code', or 'ovl_player_actor' (default: all)",
)
parser.add_argument(
"--all-sections",
action="store_true",
help="Check ordering for all section types, not just .bss",
)
args = parser.parse_args()
version = args.oot_version
@ -176,10 +181,9 @@ def main():
else:
assert False, "Invalid relocation"
if base_value != build_value:
pointers.append(
Pointer(reloc.name, reloc.addend, base_value, build_value)
)
pointers.append(
Pointer(reloc.name, reloc.addend, base_value, build_value)
)
# Remove duplicates and sort by baserom address
pointers = list({p.base_value: p for p in pointers}.values())
@ -188,6 +192,9 @@ def main():
# Go through sections and report differences
for mapfile_segment in source_code_segments:
for file in mapfile_segment:
if not args.all_sections and not file.sectionType == ".bss":
continue
pointers_in_section = [
p
for p in pointers
@ -196,6 +203,17 @@ def main():
if not pointers_in_section:
continue
# Try to detect if the section is shifted by comparing the lowest
# address among any pointer into the section between base and build
base_min_address = min(p.base_value for p in pointers_in_section)
build_min_address = min(p.build_value for p in pointers_in_section)
section_shift = build_min_address - base_min_address
if all(
p.build_value == p.base_value + section_shift
for p in pointers_in_section
):
continue
print(f"{file.filepath} {file.sectionType} is reordered:")
for i, p in enumerate(pointers_in_section):
if p.addend > 0: