Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.29.0 #173

Merged
merged 3 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.29.0] - 2024-09-09

### Added

- New `ContextSymbol.functionOwnerForMigration` attribute.
- Allows to override to which function a given rodata symbol should be
migrated to.
- Specially useful for unreferenced symbols.
- WARNING: It is undefined behavior if during rodata migration the listed
function does not exists on the given text section. For example this symbol
may get lost in limbo.

### 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 Expand Up @@ -1608,6 +1627,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Version 1.0.0

[unreleased]: https://github.com/Decompollaborate/spimdisasm/compare/master...develop
[1.29.0]: https://github.com/Decompollaborate/spimdisasm/compare/1.28.1...1.29.0
[1.28.1]: https://github.com/Decompollaborate/spimdisasm/compare/1.28.0...1.28.1
[1.28.0]: https://github.com/Decompollaborate/spimdisasm/compare/1.27.0...1.28.0
[1.27.0]: https://github.com/Decompollaborate/spimdisasm/compare/1.26.1...1.27.0
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ If you use a `requirements.txt` file in your repository, then you can add
this library with the following line:

```txt
spimdisasm>=1.28.1,<2.0.0
spimdisasm>=1.29.0,<2.0.0
```

### Development version
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[project]
name = "spimdisasm"
# Version should be synced with spimdisasm/__init__.py
version = "1.28.1"
version = "1.29.0"
description = "MIPS disassembler"
readme = "README.md"
license = {file = "LICENSE"}
Expand Down
2 changes: 1 addition & 1 deletion spimdisasm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from __future__ import annotations

__version_info__: tuple[int, int, int] = (1, 28, 1)
__version_info__: tuple[int, int, int] = (1, 29, 0)
__version__ = ".".join(map(str, __version_info__))# + "-dev0"
__author__ = "Decompollaborate"

Expand Down
33 changes: 26 additions & 7 deletions spimdisasm/common/ContextSymbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,18 +186,37 @@ class ContextSymbol:
isElfNotype: bool = False

forceMigration: bool = False
"""Ignore rules for migrating rodata and force migration of this symbol to any
"""
Ignore rules for migrating rodata and force migration of this symbol to any
function which references it.

Enabling both forceMigration and forceNotMigration on the same symbol is
undefined behaviour.
WARNING: Enabling both forceMigration and forceNotMigration on the same
symbol is undefined behaviour.
"""
forceNotMigration: bool = False
"""Ignore rules for migrating rodata and prevent migration of this symbol to any
function which references it.
"""
Ignore rules for migrating rodata and prevent migration of this symbol to
any function which references it.

WARNING: Enabling both forceMigration and forceNotMigration on the same
symbol is undefined behaviour.
"""
functionOwnerForMigration: str|None = None
"""
Force migrating to the function that matches the specified name.

Overrides all logic for determining if this symbol should be migrated or
not and to which function should be migrated. This completely ignores both
`forceMigration` and `forceNotMigration` attributes.

This can be specially useful for unreferenced symbols that should be
defined in-between actually referenced symbols.

This field is ignored if applied on anything that is not a rodata symbol.

Enabling both forceMigration and forceNotMigration on the same symbol is
undefined behaviour.
WARNING: It is undefined behavior if during rodata migration the listed
function does not exists on the given text section. For example this symbol
may get lost in limbo.
"""

allowedToReferenceAddends: bool = False
Expand Down
1 change: 1 addition & 0 deletions spimdisasm/common/SymbolsSegment.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ def readSplatSymbolAddrs(self, filepath: Path) -> None:
forceNotMigration = Utils.getMaybeBooleyFromMaybeStr(pairs.get("force_not_migration"))
if forceNotMigration is not None:
contextSym.forceNotMigration = forceNotMigration
contextSym.functionOwnerForMigration = pairs.get("function_owner")

allowAddend = Utils.getMaybeBooleyFromMaybeStr(pairs.get("allow_addend"))
if allowAddend is not None:
Expand Down
4 changes: 3 additions & 1 deletion spimdisasm/mips/FuncRodataEntry.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ def getEntryForFuncFromSection(func: symbols.SymbolFunction, rodataSection: sect
if len(intersection) == 0:
return FunctionRodataEntry(func)

funcName = func.getName()

for rodataSym in rodataSection.symbolList:
if rodataSym.vram not in intersection:
if rodataSym.vram not in intersection and rodataSym.contextSym.functionOwnerForMigration != funcName:
continue

if not rodataSym.shouldMigrate():
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
3 changes: 3 additions & 0 deletions spimdisasm/mips/symbols/MipsSymbolRodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ def isRdata(self) -> bool:
return True

def shouldMigrate(self) -> bool:
if self.contextSym.functionOwnerForMigration is not None:
return True

if self.contextSym.forceMigration:
return True

Expand Down
Loading