Skip to content

Commit

Permalink
Fix data references to symbols with adends being symbolized instead o…
Browse files Browse the repository at this point in the history
…f just using an addend to the symbol.
  • Loading branch information
AngheloAlf committed Aug 26, 2024
1 parent 49b8cce commit 2aa4feb
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Fix data references to symbols with adends (that have user declared sizes)
being symbolized instead of just using an addend to the symbol.
- This bug seems like was only happening if the referenced symbol was in the
same section as the one who was referencing it.

## [1.28.1] - 2024-08-19

### Changed
Expand Down
6 changes: 4 additions & 2 deletions spimdisasm/mips/sections/MipsSectionBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,13 @@ def _getOwnedSymbol(self, localOffset: int) -> common.ContextSymbol|None:

return contextSym

def _addOwnedSymbol(self, localOffset: int) -> common.ContextSymbol:
def _addOwnedSymbol(self, localOffset: int) -> common.ContextSymbol|None:
currentVram = self.getVramOffset(localOffset)
currentVrom = self.getVromOffsetNone(localOffset)

contextSym = self.addSymbol(currentVram, sectionType=self.sectionType, isAutogenerated=True, symbolVrom=currentVrom)
contextSym = self.addSymbol(currentVram, sectionType=self.sectionType, isAutogenerated=True, symbolVrom=currentVrom, allowAddendInstead=True)
if contextSym.vram != currentVram:
return None

if self.typeForOwnedSymbols is not None:
contextSym.autodetectedType = self.typeForOwnedSymbols
Expand Down
10 changes: 6 additions & 4 deletions spimdisasm/mips/sections/MipsSectionData.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ def analyze(self) -> None:

elif self.popPointerInDataReference(currentVram) is not None:
contextSym = self._addOwnedSymbol(localOffset)
symbolList.append((localOffset, contextSym))
localOffsetsWithSymbols.add(localOffset)
if contextSym is not None:
symbolList.append((localOffset, contextSym))
localOffsetsWithSymbols.add(localOffset)

if self.checkWordIsASymbolReference(w):
if w < currentVram and self.containsVram(w):
Expand All @@ -57,8 +58,9 @@ def analyze(self) -> None:

if self.popPointerInDataReference(currentVram) is not None and localOffset not in localOffsetsWithSymbols:
contextSym = self._addOwnedSymbol(localOffset)
symbolList.append((localOffset, contextSym))
localOffsetsWithSymbols.add(localOffset)
if contextSym is not None:
symbolList.append((localOffset, contextSym))
localOffsetsWithSymbols.add(localOffset)

localOffset += 4

Expand Down
8 changes: 5 additions & 3 deletions spimdisasm/mips/sections/MipsSectionGccExceptTable.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ def analyze(self) -> None:
if negativeOneCounter >= 2 and w != 0:
# The except table ended
contextSym = self._addOwnedSymbol(localOffset)
lastVramSymbol = contextSym
self.addGccExceptTable(currentVram, isAutogenerated=True, symbolVrom=currentVrom)
if contextSym is not None:
lastVramSymbol = contextSym
self.addGccExceptTable(currentVram, isAutogenerated=True, symbolVrom=currentVrom)

negativeOneCounter = 0

Expand All @@ -126,7 +127,8 @@ def analyze(self) -> None:
if contextSym is not None or self.popPointerInDataReference(currentVram) is not None or (lastVramSymbol.isGccExceptTable() and w != 0):
# Somehow this isn't an except table? TODO: check if this can happen
contextSym = self._addOwnedSymbol(localOffset)
lastVramSymbol = contextSym
if contextSym is not None:
lastVramSymbol = contextSym

self.checkWordIsASymbolReference(w)

Expand Down
13 changes: 8 additions & 5 deletions spimdisasm/mips/sections/MipsSectionRodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ def analyze(self) -> None:
if jumpTableSym is None:
if contextSym is not None or self.popPointerInDataReference(currentVram) is not None or (lastVramSymbol.isJumpTable() and w != 0):
contextSym = self._addOwnedSymbol(localOffset)
lastVramSymbol = contextSym
if contextSym is not None:
lastVramSymbol = contextSym

self.checkWordIsASymbolReference(w)

Expand All @@ -108,8 +109,9 @@ def analyze(self) -> None:

elif jumpTableSym is None and self.popPointerInDataReference(currentVram) is not None:
contextSym = self._addOwnedSymbol(localOffset)
symbolList.append((localOffset, contextSym))
localOffsetsWithSymbols.add(localOffset)
if contextSym is not None:
symbolList.append((localOffset, contextSym))
localOffsetsWithSymbols.add(localOffset)

if not lastVramSymbol.notPointerByType():
if self.checkWordIsASymbolReference(w):
Expand All @@ -126,8 +128,9 @@ def analyze(self) -> None:

if self.popPointerInDataReference(currentVram) is not None and localOffset not in localOffsetsWithSymbols:
contextSym = self._addOwnedSymbol(localOffset)
symbolList.append((localOffset, contextSym))
localOffsetsWithSymbols.add(localOffset)
if contextSym is not None:
symbolList.append((localOffset, contextSym))
localOffsetsWithSymbols.add(localOffset)

localOffset += 4

Expand Down

0 comments on commit 2aa4feb

Please sign in to comment.