Skip to content

Commit

Permalink
Merge pull request #183 from Decompollaborate/develop
Browse files Browse the repository at this point in the history
1.32.2
  • Loading branch information
AngheloAlf authored Feb 12, 2025
2 parents 31415fc + 593bffc commit bb505bc
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 14 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.32.2] - 2025-02-12

### Fixed

- Fix to avoid incorrectly inferring the symbol's type if the given symbol is
referenced on complex control flows.
- Avoid symbolizing $gp accesses if the current function set that register to a
different value.

## [1.32.1] - 2025-02-02

### Changed
Expand Down Expand Up @@ -1742,6 +1751,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.32.2]: https://github.com/Decompollaborate/spimdisasm/compare/1.32.1...1.32.2
[1.32.1]: https://github.com/Decompollaborate/spimdisasm/compare/1.32.0...1.32.1
[1.32.0]: https://github.com/Decompollaborate/spimdisasm/compare/1.31.3...1.32.0
[1.31.3]: https://github.com/Decompollaborate/spimdisasm/compare/1.31.2...1.31.3
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.32.1,<2.0.0
spimdisasm>=1.32.2,<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.32.1"
version = "1.32.2"
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, 32, 1)
__version_info__: tuple[int, int, int] = (1, 32, 2)
__version__ = ".".join(map(str, __version_info__))# + "-dev0"
__author__ = "Decompollaborate"

Expand Down
14 changes: 8 additions & 6 deletions spimdisasm/mips/symbols/MipsSymbolFunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, context: common.Context, vromStart: int, vromEnd: int, inFile

self.instrAnalyzer = analysis.InstrAnalyzer(self.vram, context)

self.branchesTaken: set[int] = set()
self.branchesTaken: set[tuple[int, bool]] = set()

self.pointersOffsets: set[int] = set()
self.pointersRemoved: bool = False
Expand All @@ -40,7 +40,7 @@ def sizew(self) -> int:
def isFunction(self) -> bool:
return True

def _lookAheadSymbolFinder(self, instr: rabbitizer.Instruction, prevInstr: rabbitizer.Instruction, instructionOffset: int, trackedRegistersOriginal: rabbitizer.RegistersTracker) -> None:
def _lookAheadSymbolFinder(self, instr: rabbitizer.Instruction, prevInstr: rabbitizer.Instruction, instructionOffset: int, trackedRegistersOriginal: rabbitizer.RegistersTracker, prev_is_likely: bool) -> None:
if not prevInstr.isBranch() and not prevInstr.isUnconditionalBranch():
return

Expand All @@ -58,9 +58,9 @@ def _lookAheadSymbolFinder(self, instr: rabbitizer.Instruction, prevInstr: rabbi

self.instrAnalyzer.processInstr(regsTracker, instr, instructionOffset, currentVram, None)

if instructionOffset in self.branchesTaken:
if (instructionOffset, prev_is_likely) in self.branchesTaken:
return
self.branchesTaken.add(instructionOffset)
self.branchesTaken.add((instructionOffset, prev_is_likely))

sizew = len(self.instructions)*4
while branch < sizew:
Expand All @@ -69,7 +69,7 @@ def _lookAheadSymbolFinder(self, instr: rabbitizer.Instruction, prevInstr: rabbi

self.instrAnalyzer.processInstr(regsTracker, targetInstr, branch, self.getVramOffset(branch), prevTargetInstr)

self._lookAheadSymbolFinder(targetInstr, prevTargetInstr, branch, regsTracker)
self._lookAheadSymbolFinder(targetInstr, prevTargetInstr, branch, regsTracker, prev_is_likely or prevTargetInstr.isBranchLikely())

if prevTargetInstr.isUnconditionalBranch():
# Since we took the branch on the previous _lookAheadSymbolFinder
Expand Down Expand Up @@ -129,7 +129,7 @@ def _runInstructionAnalyzer(self) -> None:
self.instrAnalyzer.processInstr(regsTracker, instr, instructionOffset, currentVram, prevInstr)

# look-ahead symbol finder
self._lookAheadSymbolFinder(instr, prevInstr, instructionOffset, regsTracker)
self._lookAheadSymbolFinder(instr, prevInstr, instructionOffset, regsTracker, prevInstr.isBranchLikely())

if prevInstr.isJumpWithAddress() and not prevInstr.doesLink():
targetVram = prevInstr.getBranchVramGeneric()
Expand Down Expand Up @@ -380,6 +380,8 @@ def _generateRelocsFromInstructionAnalyzer(self) -> None:
self.relocs[instrOffset] = common.RelocationInfo(relocType, "_gp_disp")

for instrOffset, gpInfo in self.instrAnalyzer.gpSets.items():
if gpInfo is None:
continue
hiInstrOffset = gpInfo.hiOffset
hiInstr = self.instructions[hiInstrOffset//4]
instr = self.instructions[instrOffset//4]
Expand Down
22 changes: 17 additions & 5 deletions spimdisasm/mips/symbols/analysis/InstrAnalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def __init__(self, funcVram: int, context: common.Context) -> None:
self.context = context
"read-only"

self.currentGpValue: int|None = common.GlobalConfig.GP_VALUE

self.referencedVrams: set[int] = set()
"Every referenced vram found"
self.referencedConstants: set[int] = set()
Expand Down Expand Up @@ -124,7 +126,7 @@ def __init__(self, funcVram: int, context: common.Context) -> None:

self.gpSetsOffsets: set[int] = set()
"Offsets of every instruction that set the $gp register"
self.gpSets: dict[int, GpSetInfo] = dict()
self.gpSets: dict[int, GpSetInfo|None] = dict()
"Instructions setting the $gp register, key: offset of the low instruction"


Expand Down Expand Up @@ -233,15 +235,15 @@ def pairHiLo(self, hiValue: int|None, luiOffset: int|None, lowerInstr: rabbitize
else:
return self.symbolLoInstrOffset[lowerOffset]

if hiValue is None and common.GlobalConfig.GP_VALUE is None:
if hiValue is None and self.currentGpValue is None:
# Trying to pair a gp relative offset, but we don't know the gp address
return None

if hiValue is not None:
upperHalf = hiValue
else:
assert common.GlobalConfig.GP_VALUE is not None
upperHalf = common.GlobalConfig.GP_VALUE
assert self.currentGpValue is not None
upperHalf = self.currentGpValue

return upperHalf + lowerHalf

Expand Down Expand Up @@ -393,9 +395,12 @@ def symbolFinder(self, regsTracker: rabbitizer.RegistersTracker, instr: rabbitiz
else:
hiGpValue = luiInstr.getProcessedImmediate() << 16
loGpValue = instr.getProcessedImmediate()
self.gpSets[instrOffset] = GpSetInfo(luiOffset, instrOffset, hiGpValue+loGpValue)
gpValue = hiGpValue+loGpValue
self.gpSets[instrOffset] = GpSetInfo(luiOffset, instrOffset, gpValue)
self.gpSetsOffsets.add(luiOffset)
self.gpSetsOffsets.add(instrOffset)
if not common.GlobalConfig.PIC:
self.currentGpValue = gpValue
# early return to avoid counting this pairing as a normal symbol
return

Expand Down Expand Up @@ -484,6 +489,13 @@ def processInstr(self, regsTracker: rabbitizer.RegistersTracker, instr: rabbitiz
self.cploads[instrOffset] = cpload

regsTracker.overwriteRegisters(instr, instrOffset)
if not common.GlobalConfig.PIC:
dstReg = instr.getDestinationGpr()
if dstReg is not None and (dstReg == rabbitizer.RegGprO32.gp or dstReg == rabbitizer.RegGprN32.gp):
if instrOffset not in self.gpSets:
self.gpSets[instrOffset] = None
self.gpSetsOffsets.add(instrOffset)
self.currentGpValue = None


def processPrevFuncCall(self, regsTracker: rabbitizer.RegistersTracker, instr: rabbitizer.Instruction, prevInstr: rabbitizer.Instruction, currentVram: int | None = None) -> None:
Expand Down

0 comments on commit bb505bc

Please sign in to comment.