Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add get_section_flags method to Segment #263

Merged
merged 3 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# splat Release Notes

### 0.16.4

* Add `get_section_flags` method to the `Segment` class.
* Useful for providing linker section flags when creating a custom section when making splat extensions.
* This may be necessary for some custom section types, because sections unrecognized by the linker will not link its data properly.
* More info about section flags: <https://sourceware.org/binutils/docs/as/Section.html#ELF-Version>

### 0.16.3

* Add `--stdout-only` flag. Redirects the progress bar output to `stdout` instead of `stderr`.
Expand Down
7 changes: 6 additions & 1 deletion segtypes/common/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ def split(self, rom_bytes: bytes):
preamble = options.opts.generated_s_preamble
if preamble:
f.write(preamble + "\n")
f.write(f".section {self.get_linker_section()}\n\n")

f.write(f".section {self.get_linker_section()}")
section_flags = self.get_section_flags()
if section_flags:
f.write(f', "{section_flags}"')
f.write("\n\n")

f.write(self.spim_section.disassemble())

Expand Down
18 changes: 18 additions & 0 deletions segtypes/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,24 @@ def cache(self):
def get_linker_section(self) -> str:
return ".data"

def get_section_flags(self) -> Optional[str]:
"""
Allows specifying flags for a section.

This can be useful when creating a custom section, since sections not recognized by the linker will not be linked properly.

GNU as docs about the section directive and flags: https://sourceware.org/binutils/docs/as/Section.html#ELF-Version

Example:

```
def get_section_flags(self) -> Optional[str]:
# Tells the linker to allocate this section
return "a"
```
"""
return None

def out_path(self) -> Optional[Path]:
return None

Expand Down
2 changes: 1 addition & 1 deletion split.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from segtypes.segment import Segment
from util import log, options, palettes, symbols, relocs

VERSION = "0.16.3"
VERSION = "0.16.4"

parser = argparse.ArgumentParser(
description="Split a rom given a rom, a config, and output directory"
Expand Down
Loading