diff options
| author | cadmic <cadmic24@gmail.com> | 2025-02-15 13:24:25 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-15 16:24:25 -0500 |
| commit | a64fd8dea8724afef8ecd0e88fabeabda810e3a1 (patch) | |
| tree | fe2dd63c1b1d16a4d7a09b1a582dd2d99e159578 /tools | |
| parent | 6f8b4d82d55a31957740a49f29ab6908f64e64ab (diff) | |
fix_bss.py: Try to handle one-past-the-end pointers (#2471)
* fix_bss.py: Try to handle one-past-the-end pointers
* Proofread
Diffstat (limited to 'tools')
| -rwxr-xr-x | tools/fix_bss.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/tools/fix_bss.py b/tools/fix_bss.py index 2a775765a..61cb4985d 100755 --- a/tools/fix_bss.py +++ b/tools/fix_bss.py @@ -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: |
