Skip to content

Commit 156a182

Browse files
authored
Allow bss_size for bss subsegments (#541)
* Allow `bss_size` for bss subsegments * whoopsie * remove old comment
1 parent 724a6c3 commit 156a182

6 files changed

Lines changed: 54 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# splat Release Notes
22

3+
### 0.41.0
4+
5+
* Add `bss_size` attribute for `bss` subsegments.
6+
* Allows to specify a size for bss subsegments when the size for the subsegment can't be infered.
7+
* splat may be unable to infer the size when the bss subsegment is followed by a segment that doesn't define a vram address, like `lib`, so this option is provided as a fallback.
8+
* `bss_size` for `bss` segments can only be used if the size can't be infered. It is a hard error to define one when splat can infer the size.
9+
310
### 0.40.1
411

512
* Always write the link dependency file.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The brackets corresponds to the optional dependencies to install while installin
2121
If you use a `requirements.txt` file in your repository, then you can add this library with the following line:
2222

2323
```txt
24-
splat64[mips]>=0.40.1,<1.0.0
24+
splat64[mips]>=0.41.0,<1.0.0
2525
```
2626

2727
### Optional dependencies

docs/Segments.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ The `.rdata` segment behaves the same as the `.rodata` segment but supports roda
245245

246246
Note that the `bss_size` option needs to be set at segment level for `bss` segments to work correctly.
247247

248+
It is possible to specify a `bss_size` for a given `bss` subsegment only if it is impossible for splat to determine the size of the bss subsegment.
249+
This may happen if a `bss` subsegment is followed by a subsegment that doesn't have a vram address.
250+
It is not possible to specify a `bss_size` for a specific `bss` subsegment if splat can infer the size.
251+
248252
**Example:**
249253

250254
```yaml

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "splat64"
33
# Should be synced with src/splat/__init__.py
4-
version = "0.40.1"
4+
version = "0.41.0"
55
description = "A binary splitting tool to assist with decompilation and modding projects"
66
readme = "README.md"
77
license = {file = "LICENSE"}

src/splat/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
__package_name__ = __name__
22

33
# Should be synced with pyproject.toml
4-
__version__ = "0.40.1"
4+
__version__ = "0.41.0"
55
__author__ = "ethteck"
66

77
from . import util as util

src/splat/segtypes/common/bss.py

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Optional
1+
from typing import Optional, Union
22

33
from ...util import options, symbols, log
44

@@ -10,6 +10,39 @@
1010

1111

1212
class CommonSegBss(CommonSegData):
13+
def __init__(
14+
self,
15+
rom_start: Optional[int],
16+
rom_end: Optional[int],
17+
type: str,
18+
name: str,
19+
vram_start: Optional[int],
20+
args: list,
21+
yaml: Union[dict, list],
22+
bss_size: Optional[int] = None,
23+
):
24+
parsed_bss_size = self.parse_bss_size(yaml)
25+
if bss_size is not None:
26+
if parsed_bss_size is not None:
27+
log.error(
28+
f"Error: Passing bss_size attribute to bss section {self.name} (0x{vram_start:08X}) is not allowed when the size of the bss section can be inferred (was inferred to 0x{bss_size:X}).\n"
29+
" Setting this attribute is only allowed when the bss size can't be inferred."
30+
)
31+
self.bss_size = bss_size
32+
else:
33+
self.bss_size = parsed_bss_size
34+
35+
super().__init__(
36+
rom_start,
37+
rom_end,
38+
type,
39+
name,
40+
vram_start,
41+
args=args,
42+
yaml=yaml,
43+
bss_size=self.bss_size,
44+
)
45+
1346
def get_linker_section(self) -> str:
1447
return ".bss"
1548

@@ -60,8 +93,12 @@ def disassemble_data(self, rom_bytes: bytes):
6093
f"Segment '{self.name}' (type '{self.type}') requires a vram address. Got '{self.vram_start}'"
6194
)
6295

63-
# Supposedly logic error, not user error
64-
assert isinstance(self.bss_size, int), f"{self.name} {self.bss_size}"
96+
if self.bss_size is None:
97+
log.error(
98+
f"Unable to infer the size for segment '{self.name}' (type '{self.type}', vram 0x{self.vram_start:08X}).\n"
99+
" This may happen when this segment is followed by a segment that doesn't use a vram address.\n"
100+
" HINT: Try setting a vram address to the next segment in the yaml or set `bss_size=0xXXXX` for this segment."
101+
)
65102
bss_end = self.vram_start + self.bss_size
66103

67104
self.spim_section = make_bss_section(

0 commit comments

Comments
 (0)