diff --git a/CHANGELOG.md b/CHANGELOG.md index 91a3e80..6bd4734 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.28.1] - 2024-08-19 + +### Changed + +- Avoid emitting "global" visibility on labels. +- Avoid emitting a rom offset comment on bss symbols. +- Change on `gpRelHack` behavior: + - Emit `.extern`s with dummy size at the top of the function for all the + `%gp_rel`-accessed symbols within the function. + +### Fixed + +- Fix function symbols and labels not acknowledging their parent file. + - Used mainly for debugging purposes. + ## [1.28.0] - 2024-08-09 ### Added @@ -1593,6 +1608,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.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 [1.26.1]: https://github.com/Decompollaborate/spimdisasm/compare/1.26.0...1.26.1 diff --git a/README.md b/README.md index 1b3d6be..095e955 100644 --- a/README.md +++ b/README.md @@ -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.0,<2.0.0 +spimdisasm>=1.28.1,<2.0.0 ``` ### Development version diff --git a/pyproject.toml b/pyproject.toml index bb27a2c..10c0d04 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ [project] name = "spimdisasm" # Version should be synced with spimdisasm/__init__.py -version = "1.28.0" +version = "1.28.1" description = "MIPS disassembler" readme = "README.md" license = {file = "LICENSE"} diff --git a/spimdisasm/__init__.py b/spimdisasm/__init__.py index bc6bed0..d57e797 100644 --- a/spimdisasm/__init__.py +++ b/spimdisasm/__init__.py @@ -5,7 +5,7 @@ from __future__ import annotations -__version_info__: tuple[int, int, int] = (1, 28, 0) +__version_info__: tuple[int, int, int] = (1, 28, 1) __version__ = ".".join(map(str, __version_info__))# + "-dev0" __author__ = "Decompollaborate" diff --git a/spimdisasm/common/ContextSymbols.py b/spimdisasm/common/ContextSymbols.py index 21f3b61..ec14675 100644 --- a/spimdisasm/common/ContextSymbols.py +++ b/spimdisasm/common/ContextSymbols.py @@ -469,7 +469,7 @@ def _defaultName_uniqueIdentifier(self, symType: SymbolSpecialType|str|None) -> return f"{self.parentFunction.getName()}_{index + 1}" if GlobalConfig.AUTOGENERATED_NAMES_BASED_ON_FILE_NAME: - if self.parentFileName is not None and self.inFileOffset is not None: + if self.parentFileName is not None and self.inFileOffset is not None and symType != SymbolSpecialType.function: sectionName = self.sectionType.toStr().replace(".", "_") return f"{self.parentFileName}{sectionName}_{self.inFileOffset:06X}" diff --git a/spimdisasm/common/ElementBase.py b/spimdisasm/common/ElementBase.py index 1ff68c0..63cbaef 100644 --- a/spimdisasm/common/ElementBase.py +++ b/spimdisasm/common/ElementBase.py @@ -103,7 +103,7 @@ def getLabelFromSymbol(self, sym: ContextSymbol|None, symName: str|None) -> str: if label is None: return "" label += f" {symName or sym.getName()}" - if sym.visibility is not None: + if sym.visibility is not None and sym.visibility != "global": label += f", {sym.visibility}" if GlobalConfig.GLABEL_ASM_COUNT: if self.index is not None: diff --git a/spimdisasm/mips/sections/MipsSectionRodata.py b/spimdisasm/mips/sections/MipsSectionRodata.py index 04536ec..181ef1c 100644 --- a/spimdisasm/mips/sections/MipsSectionRodata.py +++ b/spimdisasm/mips/sections/MipsSectionRodata.py @@ -64,6 +64,7 @@ def _analyze_processJumptable(self, localOffset: int, w: int, contextSym: common labelSym.referenceCounter += 1 if jumpTableSym.parentFunction is not None: labelSym.parentFunction = jumpTableSym.parentFunction + labelSym.parentFileName = jumpTableSym.parentFunction.parentFileName jumpTableSym.parentFunction.branchLabels.add(labelSym.vram, labelSym) return jumpTableSym, firstJumptableWord diff --git a/spimdisasm/mips/symbols/MipsSymbolBase.py b/spimdisasm/mips/symbols/MipsSymbolBase.py index 0cc5f56..f1458d8 100644 --- a/spimdisasm/mips/symbols/MipsSymbolBase.py +++ b/spimdisasm/mips/symbols/MipsSymbolBase.py @@ -64,11 +64,14 @@ def canUseConstantsOnData(self) -> bool: return self.contextSym.allowedToReferenceConstants - def generateAsmLineComment(self, localOffset: int, wordValue: int|None=None, *, isDouble: bool=False) -> str: + def generateAsmLineComment(self, localOffset: int, wordValue: int|None=None, *, isDouble: bool=False, emitRomOffset: bool=True) -> str: if not common.GlobalConfig.ASM_COMMENT: return "" - offsetHex = "{0:0{1}X}".format(localOffset + self.inFileOffset + self.commentOffset, common.GlobalConfig.ASM_COMMENT_OFFSET_WIDTH) + if emitRomOffset: + offsetHex = "{0:0{1}X} ".format(localOffset + self.inFileOffset + self.commentOffset, common.GlobalConfig.ASM_COMMENT_OFFSET_WIDTH) + else: + offsetHex = "" currentVram = self.getVramOffset(localOffset) vramHex = f"{currentVram:08X}" @@ -80,7 +83,7 @@ def generateAsmLineComment(self, localOffset: int, wordValue: int|None=None, *, else: wordValueHex = f"{common.Utils.wordToCurrenEndian(wordValue):08X} " - return f"/* {offsetHex} {vramHex} {wordValueHex}*/" + return f"/* {offsetHex}{vramHex} {wordValueHex}*/" def getSymbolAsmDeclaration(self, symName: str, useGlobalLabel: bool=True) -> str: diff --git a/spimdisasm/mips/symbols/MipsSymbolBss.py b/spimdisasm/mips/symbols/MipsSymbolBss.py index 04245d2..6457cb8 100644 --- a/spimdisasm/mips/symbols/MipsSymbolBss.py +++ b/spimdisasm/mips/symbols/MipsSymbolBss.py @@ -61,7 +61,7 @@ def disassembleAsBss(self, useGlobalLabel: bool = True) -> str: output += self.getPrevAlignDirective(0) output += self.getSymbolAsmDeclaration(self.getName(), useGlobalLabel) - output += self.generateAsmLineComment(0) + output += self.generateAsmLineComment(0, emitRomOffset=False) output += f" .space 0x{self.spaceSize:02X}{common.GlobalConfig.LINE_ENDS}" nameEnd = self.getNameEnd() diff --git a/spimdisasm/mips/symbols/MipsSymbolFunction.py b/spimdisasm/mips/symbols/MipsSymbolFunction.py index d4612cc..170e64e 100644 --- a/spimdisasm/mips/symbols/MipsSymbolFunction.py +++ b/spimdisasm/mips/symbols/MipsSymbolFunction.py @@ -396,6 +396,10 @@ def _generateRelocsFromInstructionAnalyzer(self) -> None: def analyze(self) -> None: + self.contextSym.inFileOffset = self.inFileOffset + if self.parent is not None: + self.contextSym.parentFileName = self.parent.getName() + if not common.GlobalConfig.DISASSEMBLE_UNKNOWN_INSTRUCTIONS and self.hasUnimplementedIntrs: offset = 0 for instr in self.instructions: @@ -423,6 +427,7 @@ def analyze(self) -> None: labelSym.referenceCounter += 1 labelSym.referenceFunctions.add(self.contextSym) labelSym.parentFunction = self.contextSym + labelSym.parentFileName = self.contextSym.parentFileName self.contextSym.branchLabels.add(labelSym.vram, labelSym) # Function calls @@ -787,6 +792,14 @@ def disassemble(self, migrate: bool=False, useGlobalLabel: bool=True, isSplitted if self.hasUnimplementedIntrs: return self.disassembleAsData(useGlobalLabel=useGlobalLabel, isSplittedSymbol=isSplittedSymbol) + if not common.GlobalConfig.PIC and self.gpRelHack and len(self.instrAnalyzer.gpReferencedSymbols) > 0: + output += f"/* Symbols accessed via $gp register */{common.GlobalConfig.LINE_ENDS}" + for gpAddress in self.instrAnalyzer.gpReferencedSymbols: + gpSym = self.getSymbol(gpAddress, tryPlusOffset=False) + if gpSym is not None: + output += f".extern {gpSym.getName()}, 1{common.GlobalConfig.LINE_ENDS}" + output += common.GlobalConfig.LINE_ENDS + output += self.contextSym.getReferenceeSymbols() output += self.getPrevAlignDirective(0) diff --git a/spimdisasm/mips/symbols/analysis/InstrAnalyzer.py b/spimdisasm/mips/symbols/analysis/InstrAnalyzer.py index cb3ecba..7b845b4 100644 --- a/spimdisasm/mips/symbols/analysis/InstrAnalyzer.py +++ b/spimdisasm/mips/symbols/analysis/InstrAnalyzer.py @@ -95,6 +95,7 @@ def __init__(self, funcVram: int, context: common.Context) -> None: "key: offset of instruction which is setting the %lo symbol, value: symbol" self.symbolGpInstrOffset: dict[int, int] = dict() + self.gpReferencedSymbols: set[int] = set() self.symbolInstrOffset: dict[int, int] = dict() @@ -300,6 +301,7 @@ def processSymbol(self, address: int, luiOffset: int|None, lowerInstr: rabbitize self.lowToHiDict[lowerOffset] = luiOffset else: self.symbolGpInstrOffset[lowerOffset] = address + self.gpReferencedSymbols.add(address) self.symbolInstrOffset[lowerOffset] = address self.referencedVramsInstrOffset[lowerOffset] = address