1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-04-08 15:46:42 +00:00

fix_bss.py: Try to handle one-past-the-end pointers (#2471)

* fix_bss.py: Try to handle one-past-the-end pointers

* Proofread
This commit is contained in:
cadmic 2025-02-15 13:24:25 -08:00 committed by GitHub
parent 6f8b4d82d5
commit a64fd8dea8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -170,9 +170,9 @@ def get_file_pointers(
# For relocations against a global symbol, subtract the addend so that the pointer
# is for the start of the symbol. This can help deal with things like STACK_TOP
# (where the pointer is past the end of the symbol) or negative addends. If the
# relocation is against a section however, it's not useful to subtract the addend,
# so we keep it as-is and hope for the best.
# (where the pointer is past the end of the symbol) or negative addends. We can't
# do this for relocations against a section though, since we need the addend to
# distinguish between different static variables.
if reloc.name.startswith("."): # section
addend = reloc.addend
else: # symbol
@ -446,13 +446,13 @@ def determine_base_bss_ordering(
new_symbol = None
new_offset = 0
for symbol in build_bss_symbols:
if (
symbol.offset <= build_offset
and build_offset < symbol.offset + symbol.size
):
# To handle one-past-the-end pointers, we check <= instead of < for the symbol end.
# This won't work if there is another symbol right after this one, since we'll
# attribute this pointer to that symbol instead. This could prevent us from solving
# BSS ordering, but often the two symbols are adjacent in the baserom too so it works anyway.
if symbol.offset <= build_offset <= symbol.offset + symbol.size:
new_symbol = symbol
new_offset = base_offset - (build_offset - symbol.offset)
break
if new_symbol is None:
if p.addend > 0: