Skip to content

Commit

Permalink
ld_align_section_vram_end (ethteck#309)
Browse files Browse the repository at this point in the history
* ld_align_section_vram_end

* changelog

* unit test

* fix

* Update util/options.py

Co-authored-by: Ethan Roseman <[email protected]>

---------

Co-authored-by: Ethan Roseman <[email protected]>
  • Loading branch information
AngheloAlf and ethteck authored Nov 26, 2023
1 parent b4cec55 commit 3e9e7cb
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 8 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# splat Release Notes

### 0.19.6

* The `*_END` linker symbol of every section for each segment is now aligned to the configured alignment by default.
* New yaml option: `ld_align_section_vram_end`
* Allows to toggle aligning the `*_END` linker symbol of each section.
* Defaults to `True`.

### 0.19.5

* The `*_VRAM_END` linker symbol is now aligned to the configured alignment by default.
* The `*_VRAM_END` linker symbol for each segment is now aligned to the configured alignment by default.
* New yaml option: `ld_align_segment_vram_end`
* Allows to toggle aligning the `*_VRAM_END` linker symbol.
* Defaults to `True`.
Expand Down
9 changes: 9 additions & 0 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,15 @@ Setting this to `True` will make the `*_VRAM_END` to be aligned to the configure
Defaults to `True`.


### ld_align_section_vram_end

Allows to toggle aligning the `*_VRAM_END` linker symbol of each section for every segment.

Setting this to `True` will make the `*_END` linker symbol of every section to be aligned to the configured alignment of the segment.

Defaults to `True`.


## C file options

### create_c_files
Expand Down
12 changes: 7 additions & 5 deletions segtypes/linker_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def add_legacy(self, segment: Segment, entries: List[LinkerEntry]):
self._write_linker_entry(entry)

if entry in last_seen_sections:
self._end_section(seg_name, entry.section_order_type)
self._end_section(seg_name, entry.section_order_type, segment)

i += 1

Expand All @@ -303,7 +303,7 @@ def add_legacy(self, segment: Segment, entries: List[LinkerEntry]):
self._write_linker_entry(entry)

if entry in last_seen_sections:
self._end_section(seg_name, entry.section_order_type)
self._end_section(seg_name, entry.section_order_type, segment)

self._end_segment(segment, all_bss=False)

Expand Down Expand Up @@ -407,7 +407,7 @@ def add_partial_segment(self, segment: Segment):
for entry in entries:
self._write_linker_entry(entry)

self._end_section(seg_name, section_name)
self._end_section(seg_name, section_name, segment)

self._end_partial_segment(section_name)

Expand Down Expand Up @@ -582,10 +582,12 @@ def _begin_section(self, seg_name: str, cur_section: str) -> None:
section_start = get_segment_section_start(seg_name, cur_section)
self._write_symbol(section_start, ".")

def _end_section(self, seg_name: str, cur_section: str) -> None:
def _end_section(self, seg_name: str, cur_section: str, segment: Segment) -> None:
section_start = get_segment_section_start(seg_name, cur_section)
section_end = get_segment_section_end(seg_name, cur_section)
section_size = get_segment_section_size(seg_name, cur_section)
if options.opts.ld_align_section_vram_end and segment.align is not None:
self._writeln(f". = ALIGN(., {segment.align});")
self._write_symbol(section_end, ".")
self._write_symbol(
section_size,
Expand Down Expand Up @@ -642,4 +644,4 @@ def _write_segment_sections(
self._begin_section(seg_name, section_name)
for entry in entries:
self._write_linker_entry(entry)
self._end_section(seg_name, section_name)
self._end_section(seg_name, section_name, segment)
2 changes: 1 addition & 1 deletion split.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from segtypes.segment import Segment
from util import log, options, palettes, symbols, relocs

VERSION = "0.19.5"
VERSION = "0.19.6"

parser = argparse.ArgumentParser(
description="Split a rom given a rom, a config, and output directory"
Expand Down
5 changes: 5 additions & 0 deletions test/basic_app/expected/basic_app.ld
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ SECTIONS
dummy_ipl3_DATA_START = .;
dummy_ipl3_bin = .;
build/split/assets/dummy_ipl3.bin.o(.data);
. = ALIGN(., 16);
dummy_ipl3_DATA_END = .;
dummy_ipl3_DATA_SIZE = ABSOLUTE(dummy_ipl3_DATA_END - dummy_ipl3_DATA_START);
}
Expand All @@ -42,15 +43,18 @@ SECTIONS
boot_TEXT_START = .;
build/split/src/main.c.o(.text);
build/split/asm/handwritten.s.o(.text);
. = ALIGN(., 16);
boot_TEXT_END = .;
boot_TEXT_SIZE = ABSOLUTE(boot_TEXT_END - boot_TEXT_START);
boot_DATA_START = .;
main_data__s = .;
build/split/asm/data/main.data.s.o(.data);
. = ALIGN(., 16);
boot_DATA_END = .;
boot_DATA_SIZE = ABSOLUTE(boot_DATA_END - boot_DATA_START);
boot_RODATA_START = .;
build/split/asm/data/main.rodata.s.o(.rodata);
. = ALIGN(., 16);
boot_RODATA_END = .;
boot_RODATA_SIZE = ABSOLUTE(boot_RODATA_END - boot_RODATA_START);
}
Expand All @@ -60,6 +64,7 @@ SECTIONS
FILL(0x00000000);
boot_BSS_START = .;
build/split/asm/data/main.bss.s.o(.bss);
. = ALIGN(., 16);
boot_BSS_END = .;
boot_BSS_SIZE = ABSOLUTE(boot_BSS_END - boot_BSS_START);
}
Expand Down
5 changes: 4 additions & 1 deletion util/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@ class SplatOpts:
ld_fill_value: Optional[int]
# Allows to control if `bss` sections (and derivatived sections) will be put on a `NOLOAD` segment on the generated linker script or not.
ld_bss_is_noload: bool
# Allows to toggle aligning the `*_VRAM_END` linker.
# Allows to toggle aligning the `*_VRAM_END` linker symbol for each segment.
ld_align_segment_vram_end: bool
# Allows to toggle aligning the `*_END` linker symbol for each section of each section.
ld_align_section_vram_end: bool

################################################################################
# C file options
Expand Down Expand Up @@ -445,6 +447,7 @@ def parse_endianness() -> Literal["big", "little"]:
ld_fill_value=p.parse_optional_opt_with_default("ld_fill_value", int, 0),
ld_bss_is_noload=p.parse_opt("ld_bss_is_noload", bool, True),
ld_align_segment_vram_end=p.parse_opt("ld_align_segment_vram_end", bool, True),
ld_align_section_vram_end=p.parse_opt("ld_align_section_vram_end", bool, True),
create_c_files=p.parse_opt("create_c_files", bool, True),
auto_decompile_empty_functions=p.parse_opt(
"auto_decompile_empty_functions", bool, True
Expand Down

0 comments on commit 3e9e7cb

Please sign in to comment.