Skip to content

Commit bb505bc

Browse files
authored
Merge pull request #183 from Decompollaborate/develop
1.32.2
2 parents 31415fc + 593bffc commit bb505bc

File tree

6 files changed

+38
-14
lines changed

6 files changed

+38
-14
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [1.32.2] - 2025-02-12
11+
12+
### Fixed
13+
14+
- Fix to avoid incorrectly inferring the symbol's type if the given symbol is
15+
referenced on complex control flows.
16+
- Avoid symbolizing $gp accesses if the current function set that register to a
17+
different value.
18+
1019
## [1.32.1] - 2025-02-02
1120

1221
### Changed
@@ -1742,6 +1751,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
17421751
- Version 1.0.0
17431752

17441753
[unreleased]: https://github.com/Decompollaborate/spimdisasm/compare/master...develop
1754+
[1.32.2]: https://github.com/Decompollaborate/spimdisasm/compare/1.32.1...1.32.2
17451755
[1.32.1]: https://github.com/Decompollaborate/spimdisasm/compare/1.32.0...1.32.1
17461756
[1.32.0]: https://github.com/Decompollaborate/spimdisasm/compare/1.31.3...1.32.0
17471757
[1.31.3]: https://github.com/Decompollaborate/spimdisasm/compare/1.31.2...1.31.3

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ If you use a `requirements.txt` file in your repository, then you can add
6969
this library with the following line:
7070

7171
```txt
72-
spimdisasm>=1.32.1,<2.0.0
72+
spimdisasm>=1.32.2,<2.0.0
7373
```
7474

7575
### Development version

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[project]
55
name = "spimdisasm"
66
# Version should be synced with spimdisasm/__init__.py
7-
version = "1.32.1"
7+
version = "1.32.2"
88
description = "MIPS disassembler"
99
readme = "README.md"
1010
license = {file = "LICENSE"}

spimdisasm/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from __future__ import annotations
77

8-
__version_info__: tuple[int, int, int] = (1, 32, 1)
8+
__version_info__: tuple[int, int, int] = (1, 32, 2)
99
__version__ = ".".join(map(str, __version_info__))# + "-dev0"
1010
__author__ = "Decompollaborate"
1111

spimdisasm/mips/symbols/MipsSymbolFunction.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def __init__(self, context: common.Context, vromStart: int, vromEnd: int, inFile
1919

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

22-
self.branchesTaken: set[int] = set()
22+
self.branchesTaken: set[tuple[int, bool]] = set()
2323

2424
self.pointersOffsets: set[int] = set()
2525
self.pointersRemoved: bool = False
@@ -40,7 +40,7 @@ def sizew(self) -> int:
4040
def isFunction(self) -> bool:
4141
return True
4242

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

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

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

61-
if instructionOffset in self.branchesTaken:
61+
if (instructionOffset, prev_is_likely) in self.branchesTaken:
6262
return
63-
self.branchesTaken.add(instructionOffset)
63+
self.branchesTaken.add((instructionOffset, prev_is_likely))
6464

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

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

72-
self._lookAheadSymbolFinder(targetInstr, prevTargetInstr, branch, regsTracker)
72+
self._lookAheadSymbolFinder(targetInstr, prevTargetInstr, branch, regsTracker, prev_is_likely or prevTargetInstr.isBranchLikely())
7373

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

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

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

382382
for instrOffset, gpInfo in self.instrAnalyzer.gpSets.items():
383+
if gpInfo is None:
384+
continue
383385
hiInstrOffset = gpInfo.hiOffset
384386
hiInstr = self.instructions[hiInstrOffset//4]
385387
instr = self.instructions[instrOffset//4]

spimdisasm/mips/symbols/analysis/InstrAnalyzer.py

+17-5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ def __init__(self, funcVram: int, context: common.Context) -> None:
4848
self.context = context
4949
"read-only"
5050

51+
self.currentGpValue: int|None = common.GlobalConfig.GP_VALUE
52+
5153
self.referencedVrams: set[int] = set()
5254
"Every referenced vram found"
5355
self.referencedConstants: set[int] = set()
@@ -124,7 +126,7 @@ def __init__(self, funcVram: int, context: common.Context) -> None:
124126

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

130132

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

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

240242
if hiValue is not None:
241243
upperHalf = hiValue
242244
else:
243-
assert common.GlobalConfig.GP_VALUE is not None
244-
upperHalf = common.GlobalConfig.GP_VALUE
245+
assert self.currentGpValue is not None
246+
upperHalf = self.currentGpValue
245247

246248
return upperHalf + lowerHalf
247249

@@ -393,9 +395,12 @@ def symbolFinder(self, regsTracker: rabbitizer.RegistersTracker, instr: rabbitiz
393395
else:
394396
hiGpValue = luiInstr.getProcessedImmediate() << 16
395397
loGpValue = instr.getProcessedImmediate()
396-
self.gpSets[instrOffset] = GpSetInfo(luiOffset, instrOffset, hiGpValue+loGpValue)
398+
gpValue = hiGpValue+loGpValue
399+
self.gpSets[instrOffset] = GpSetInfo(luiOffset, instrOffset, gpValue)
397400
self.gpSetsOffsets.add(luiOffset)
398401
self.gpSetsOffsets.add(instrOffset)
402+
if not common.GlobalConfig.PIC:
403+
self.currentGpValue = gpValue
399404
# early return to avoid counting this pairing as a normal symbol
400405
return
401406

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

486491
regsTracker.overwriteRegisters(instr, instrOffset)
492+
if not common.GlobalConfig.PIC:
493+
dstReg = instr.getDestinationGpr()
494+
if dstReg is not None and (dstReg == rabbitizer.RegGprO32.gp or dstReg == rabbitizer.RegGprN32.gp):
495+
if instrOffset not in self.gpSets:
496+
self.gpSets[instrOffset] = None
497+
self.gpSetsOffsets.add(instrOffset)
498+
self.currentGpValue = None
487499

488500

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

0 commit comments

Comments
 (0)