From c61aa428ff92402672eaffec7ea091ecf1a63e58 Mon Sep 17 00:00:00 2001 From: angie Date: Fri, 9 Aug 2024 11:38:39 -0400 Subject: [PATCH 1/7] Avoid emitting "global" visibility on labels --- CHANGELOG.md | 4 ++++ spimdisasm/common/ElementBase.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91a3e80d..5355571d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Avoid emitting "global" visibility on labels. + ## [1.28.0] - 2024-08-09 ### Added diff --git a/spimdisasm/common/ElementBase.py b/spimdisasm/common/ElementBase.py index 1ff68c09..63cbaefc 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: From 5334c6e7944ddb4b58b4d712168834f83188010c Mon Sep 17 00:00:00 2001 From: angie Date: Fri, 9 Aug 2024 11:59:04 -0400 Subject: [PATCH 2/7] Avoid emitting a rom offset comment on bss symbols. --- CHANGELOG.md | 1 + pyproject.toml | 2 +- spimdisasm/__init__.py | 4 ++-- spimdisasm/mips/symbols/MipsSymbolBase.py | 9 ++++++--- spimdisasm/mips/symbols/MipsSymbolBss.py | 2 +- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5355571d..7010909d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Avoid emitting "global" visibility on labels. +- Avoid emitting a rom offset comment on bss symbols. ## [1.28.0] - 2024-08-09 diff --git a/pyproject.toml b/pyproject.toml index bb27a2cf..ac31f3db 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-dev0" description = "MIPS disassembler" readme = "README.md" license = {file = "LICENSE"} diff --git a/spimdisasm/__init__.py b/spimdisasm/__init__.py index bc6bed0d..3b1e0635 100644 --- a/spimdisasm/__init__.py +++ b/spimdisasm/__init__.py @@ -5,8 +5,8 @@ from __future__ import annotations -__version_info__: tuple[int, int, int] = (1, 28, 0) -__version__ = ".".join(map(str, __version_info__))# + "-dev0" +__version_info__: tuple[int, int, int] = (1, 28, 1) +__version__ = ".".join(map(str, __version_info__)) + "-dev0" __author__ = "Decompollaborate" from . import common as common diff --git a/spimdisasm/mips/symbols/MipsSymbolBase.py b/spimdisasm/mips/symbols/MipsSymbolBase.py index 0cc5f56d..f1458d8e 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 04245d2f..6457cb80 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() From 692c071c1cdc789d62b3cd2a5d9eae0d2ac65bc1 Mon Sep 17 00:00:00 2001 From: angie Date: Sat, 10 Aug 2024 20:08:18 -0400 Subject: [PATCH 3/7] `gpRelHack`: Emit `.extern`s with dummy size at the top of the function for all the `%gp_rel`-accessed symbols within the function. --- CHANGELOG.md | 3 +++ spimdisasm/mips/symbols/MipsSymbolFunction.py | 8 ++++++++ spimdisasm/mips/symbols/analysis/InstrAnalyzer.py | 2 ++ 3 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7010909d..5dbefeeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - 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. ## [1.28.0] - 2024-08-09 diff --git a/spimdisasm/mips/symbols/MipsSymbolFunction.py b/spimdisasm/mips/symbols/MipsSymbolFunction.py index d4612cc0..7c19f522 100644 --- a/spimdisasm/mips/symbols/MipsSymbolFunction.py +++ b/spimdisasm/mips/symbols/MipsSymbolFunction.py @@ -787,6 +787,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 cb3ecba3..7b845b4c 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 From ac619c854a0250c9dfadd32e2ce51ef8df082089 Mon Sep 17 00:00:00 2001 From: angie Date: Sun, 18 Aug 2024 09:03:19 -0400 Subject: [PATCH 4/7] Set parent filename on function symbols --- CHANGELOG.md | 5 +++++ spimdisasm/common/ContextSymbols.py | 2 +- spimdisasm/mips/symbols/MipsSymbolFunction.py | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5dbefeeb..f9a0ac75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - 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 not acknowledging their parent file. + - Used mainly for debugging purposes. + ## [1.28.0] - 2024-08-09 ### Added diff --git a/spimdisasm/common/ContextSymbols.py b/spimdisasm/common/ContextSymbols.py index 21f3b616..ec14675f 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/mips/symbols/MipsSymbolFunction.py b/spimdisasm/mips/symbols/MipsSymbolFunction.py index 7c19f522..bd6bc677 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: From bcc273cacd451e35adb9856f9ddeff4928d415dc Mon Sep 17 00:00:00 2001 From: angie Date: Sun, 18 Aug 2024 09:24:06 -0400 Subject: [PATCH 5/7] Fix labels not having an parent file --- CHANGELOG.md | 2 +- spimdisasm/mips/sections/MipsSectionRodata.py | 1 + spimdisasm/mips/symbols/MipsSymbolFunction.py | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9a0ac75..dc2a5369 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- Fix function symbols not acknowledging their parent file. +- Fix function symbols and labels not acknowledging their parent file. - Used mainly for debugging purposes. ## [1.28.0] - 2024-08-09 diff --git a/spimdisasm/mips/sections/MipsSectionRodata.py b/spimdisasm/mips/sections/MipsSectionRodata.py index 04536ecf..181ef1cf 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/MipsSymbolFunction.py b/spimdisasm/mips/symbols/MipsSymbolFunction.py index bd6bc677..fa78991a 100644 --- a/spimdisasm/mips/symbols/MipsSymbolFunction.py +++ b/spimdisasm/mips/symbols/MipsSymbolFunction.py @@ -427,6 +427,8 @@ def analyze(self) -> None: labelSym.referenceCounter += 1 labelSym.referenceFunctions.add(self.contextSym) labelSym.parentFunction = self.contextSym + if self.parent is not None: + labelSym.parentFileName = self.parent.getName() self.contextSym.branchLabels.add(labelSym.vram, labelSym) # Function calls From cf1d4807e92417ddcd573a1a6e7ac57ce88d8175 Mon Sep 17 00:00:00 2001 From: angie Date: Sun, 18 Aug 2024 09:35:36 -0400 Subject: [PATCH 6/7] simplify thingy --- spimdisasm/mips/symbols/MipsSymbolFunction.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spimdisasm/mips/symbols/MipsSymbolFunction.py b/spimdisasm/mips/symbols/MipsSymbolFunction.py index fa78991a..170e64e7 100644 --- a/spimdisasm/mips/symbols/MipsSymbolFunction.py +++ b/spimdisasm/mips/symbols/MipsSymbolFunction.py @@ -427,8 +427,7 @@ def analyze(self) -> None: labelSym.referenceCounter += 1 labelSym.referenceFunctions.add(self.contextSym) labelSym.parentFunction = self.contextSym - if self.parent is not None: - labelSym.parentFileName = self.parent.getName() + labelSym.parentFileName = self.contextSym.parentFileName self.contextSym.branchLabels.add(labelSym.vram, labelSym) # Function calls From bc52b19c2010e50c25ec1f241879f49532157fc2 Mon Sep 17 00:00:00 2001 From: angie Date: Mon, 19 Aug 2024 10:03:32 -0400 Subject: [PATCH 7/7] version bump --- CHANGELOG.md | 3 +++ README.md | 2 +- pyproject.toml | 2 +- spimdisasm/__init__.py | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc2a5369..6bd47348 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ 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. @@ -1606,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 1b3d6be3..095e9554 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 ac31f3db..10c0d041 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.1-dev0" +version = "1.28.1" description = "MIPS disassembler" readme = "README.md" license = {file = "LICENSE"} diff --git a/spimdisasm/__init__.py b/spimdisasm/__init__.py index 3b1e0635..d57e797a 100644 --- a/spimdisasm/__init__.py +++ b/spimdisasm/__init__.py @@ -6,7 +6,7 @@ from __future__ import annotations __version_info__: tuple[int, int, int] = (1, 28, 1) -__version__ = ".".join(map(str, __version_info__)) + "-dev0" +__version__ = ".".join(map(str, __version_info__))# + "-dev0" __author__ = "Decompollaborate" from . import common as common