Skip to content

Commit

Permalink
Fix rodata addresses referenced _only_ by other rodata symbols on the…
Browse files Browse the repository at this point in the history
… same file not being properly symbolized.
  • Loading branch information
AngheloAlf committed Jul 21, 2024
1 parent a0ec7ba commit 0b4dd5c
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Fix rodata addresses referenced _only_ by other rodata symbols on the same
file not being properly symbolized.
- elfObjDisasm's readelf:
- Fix name column not displaying the section's name.
- Fix relocation sections not displaying anything on the name columns for
Expand Down
17 changes: 17 additions & 0 deletions spimdisasm/common/ContextSymbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,23 @@ def isLateRodata(self) -> bool:
# if self.referenceCounter > 1: return False # ?
return self.isJumpTable() or self.isFloat() or self.isDouble()


def notPointerByType(self) -> bool:
if self.isByte():
return True
if self.isShort():
return True
if self.isFloat():
return True
if self.isDouble():
return True
if self.isString():
return True
if self.isPascalString():
return True
return False


def hasUserDeclaredSize(self) -> bool:
return self.userDeclaredSize is not None

Expand Down
1 change: 0 additions & 1 deletion spimdisasm/mips/sections/MipsSectionData.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def analyze(self) -> None:
localOffset = 0
for w in self.words:
currentVram = self.getVramOffset(localOffset)
currentVrom = self.getVromOffset(localOffset)

if self.popPointerInDataReference(currentVram) is not None and localOffset not in localOffsetsWithSymbols:
contextSym = self._addOwnedSymbol(localOffset)
Expand Down
40 changes: 35 additions & 5 deletions spimdisasm/mips/sections/MipsSectionRodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@ def _analyze_processJumptable(self, localOffset: int, w: int, contextSym: common
def analyze(self) -> None:
lastVramSymbol: common.ContextSymbol = self._checkAndCreateFirstSymbol()

symbolList: list[tuple[int, int]] = []
symbolList: list[tuple[int, common.ContextSymbol]] = []
localOffset = 0
localOffsetsWithSymbols: set[int] = set()

needsFurtherAnalyzis = False

jumpTableSym: common.ContextSymbol|None = None
firstJumptableWord = -1
Expand All @@ -97,17 +100,43 @@ def analyze(self) -> None:
self.checkWordIsASymbolReference(w)

if contextSym is not None:
self.symbolsVRams.add(currentVram)
symbolList.append((localOffset, currentVram))
symbolList.append((localOffset, contextSym))
localOffsetsWithSymbols.add(localOffset)

self._createAutoPadFromSymbol(localOffset, contextSym)

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

if not lastVramSymbol.notPointerByType():
if self.checkWordIsASymbolReference(w):
if w < currentVram and self.containsVram(w):
# References a data symbol from this section and it is behind this current symbol
needsFurtherAnalyzis = True

localOffset += 4

if needsFurtherAnalyzis:
localOffset = 0
for w in self.words:
currentVram = self.getVramOffset(localOffset)

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

localOffset += 4

# Since we appended new symbols, this list is not sorted anymore
symbolList.sort()

previousSymbolWasLateRodata = False
previousSymbolExtraPadding = 0

for i, (offset, vram) in enumerate(symbolList):
for i, (offset, contextSym) in enumerate(symbolList):
if i + 1 == len(symbolList):
words = self.words[offset//4:]
else:
Expand All @@ -116,12 +145,13 @@ def analyze(self) -> None:

vrom = self.getVromOffset(offset)
vromEnd = vrom + len(words)*4
sym = symbols.SymbolRodata(self.context, vrom, vromEnd, offset + self.inFileOffset, vram, words, self.segmentVromStart, self.overlayCategory)
sym = symbols.SymbolRodata(self.context, vrom, vromEnd, offset + self.inFileOffset, contextSym.vram, words, self.segmentVromStart, self.overlayCategory)
sym.parent = self
sym.setCommentOffset(self.commentOffset)
sym.stringEncoding = self.stringEncoding
sym.analyze()
self.symbolList.append(sym)
self.symbolsVRams.add(contextSym.vram)

# File boundaries detection
if sym.inFileOffset % 16 == 0:
Expand Down

0 comments on commit 0b4dd5c

Please sign in to comment.