Skip to content

Commit

Permalink
Avoid generating sub-scripts of conditionally excluded segments durin…
Browse files Browse the repository at this point in the history
…g partial linking scripts generation.
  • Loading branch information
AngheloAlf committed Jul 17, 2024
1 parent ce115f0 commit 38f7239
Show file tree
Hide file tree
Showing 10 changed files with 221 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix partial linking related paths not being properly escaped.
- Fix `partial_build_segments_folder` not being properly prefixed on some places.
- Fix `section_order` not being applied to files inside of `group`s.
- Avoid generating sub-scripts of conditionally excluded segments during partial
linking scripts generation.

## [0.2.4] - 2024-07-15

Expand Down
9 changes: 9 additions & 0 deletions slinky/src/partial_linker_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ impl<'a> PartialLinkerWriter<'a> {

self.partial_writers.reserve(segments.len());
for segment in segments {
if !self.rs.should_emit_entry(
&segment.exclude_if_any,
&segment.exclude_if_all,
&segment.include_if_any,
&segment.include_if_all,
) {
continue;
}

let mut partial_writer = LinkerWriter::new(self.d, self.rs);

partial_writer.set_emit_sections_kind_symbols(false);
Expand Down
2 changes: 2 additions & 0 deletions tests/partial_linking/follow_segment.d
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
build/us/rom.elf: \
build/us/segments/boot.o \
build/us/segments/kanji.o \
build/us/segments/ascii.o \
build/us/segments/main.o

build/us/segments/boot.o:
build/us/segments/kanji.o:
build/us/segments/ascii.o:
build/us/segments/main.o:
36 changes: 36 additions & 0 deletions tests/partial_linking/follow_segment.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,42 @@ extern char kanji_VRAM_END[];
extern char kanji_VRAM_SIZE[];
extern char kanji_ROM_END[];
extern char kanji_ROM_SIZE[];
extern char ascii_ROM_START[];
extern char ascii_VRAM[];
extern char ascii_alloc_VRAM[];
extern char ascii_TEXT_START[];
extern char ascii_TEXT_END[];
extern char ascii_TEXT_SIZE[];
extern char ascii_DATA_START[];
extern char ascii_DATA_END[];
extern char ascii_DATA_SIZE[];
extern char ascii_RODATA_START[];
extern char ascii_RODATA_END[];
extern char ascii_RODATA_SIZE[];
extern char ascii_SDATA_START[];
extern char ascii_SDATA_END[];
extern char ascii_SDATA_SIZE[];
extern char ascii_alloc_VRAM_END[];
extern char ascii_alloc_VRAM_SIZE[];
extern char ascii_noload_VRAM[];
extern char ascii_SBSS_START[];
extern char ascii_SBSS_END[];
extern char ascii_SBSS_SIZE[];
extern char ascii_SCOMMON_START[];
extern char ascii_SCOMMON_END[];
extern char ascii_SCOMMON_SIZE[];
extern char ascii_BSS_START[];
extern char ascii_BSS_END[];
extern char ascii_BSS_SIZE[];
extern char asciiCOMMON_START[];
extern char asciiCOMMON_END[];
extern char asciiCOMMON_SIZE[];
extern char ascii_noload_VRAM_END[];
extern char ascii_noload_VRAM_SIZE[];
extern char ascii_VRAM_END[];
extern char ascii_VRAM_SIZE[];
extern char ascii_ROM_END[];
extern char ascii_ROM_SIZE[];
extern char main_ROM_START[];
extern char main_VRAM[];
extern char main_alloc_VRAM[];
Expand Down
80 changes: 80 additions & 0 deletions tests/partial_linking/follow_segment.ld
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,86 @@ SECTIONS
kanji_ROM_END = __romPos;
kanji_ROM_SIZE = ABSOLUTE(kanji_ROM_END - kanji_ROM_START);

__romPos = ALIGN(__romPos, 0x8);
. = ALIGN(., 0x8);
ascii_ROM_START = __romPos;
ascii_VRAM = ADDR(.ascii);
ascii_alloc_VRAM = .;

.ascii : AT(ascii_ROM_START)
{
FILL(0x00000000);
ascii_TEXT_START = .;
build/us/segments/ascii.o(.text*);
. = ALIGN(., 0x8);
ascii_TEXT_END = .;
ascii_TEXT_SIZE = ABSOLUTE(ascii_TEXT_END - ascii_TEXT_START);

ascii_DATA_START = .;
build/us/segments/ascii.o(.data*);
. = ALIGN(., 0x8);
ascii_DATA_END = .;
ascii_DATA_SIZE = ABSOLUTE(ascii_DATA_END - ascii_DATA_START);

ascii_RODATA_START = .;
build/us/segments/ascii.o(.rodata*);
. = ALIGN(., 0x8);
. = ALIGN(., 0x80);
ascii_RODATA_END = .;
ascii_RODATA_SIZE = ABSOLUTE(ascii_RODATA_END - ascii_RODATA_START);

ascii_SDATA_START = .;
build/us/segments/ascii.o(.sdata*);
. = ALIGN(., 0x8);
ascii_SDATA_END = .;
ascii_SDATA_SIZE = ABSOLUTE(ascii_SDATA_END - ascii_SDATA_START);
}

ascii_alloc_VRAM_END = .;
ascii_alloc_VRAM_SIZE = ABSOLUTE(ascii_alloc_VRAM_END - ascii_alloc_VRAM);

ascii_noload_VRAM = .;

.ascii.noload (NOLOAD) :
{
FILL(0x00000000);
ascii_SBSS_START = .;
build/us/segments/ascii.o(.sbss*);
. = ALIGN(., 0x8);
. = ALIGN(., 0x20);
ascii_SBSS_END = .;
ascii_SBSS_SIZE = ABSOLUTE(ascii_SBSS_END - ascii_SBSS_START);

ascii_SCOMMON_START = .;
build/us/segments/ascii.o(.scommon*);
. = ALIGN(., 0x8);
ascii_SCOMMON_END = .;
ascii_SCOMMON_SIZE = ABSOLUTE(ascii_SCOMMON_END - ascii_SCOMMON_START);

ascii_BSS_START = .;
build/us/segments/ascii.o(.bss*);
. = ALIGN(., 0x8);
ascii_BSS_END = .;
ascii_BSS_SIZE = ABSOLUTE(ascii_BSS_END - ascii_BSS_START);

asciiCOMMON_START = .;
build/us/segments/ascii.o(COMMON*);
. = ALIGN(., 0x8);
asciiCOMMON_END = .;
asciiCOMMON_SIZE = ABSOLUTE(asciiCOMMON_END - asciiCOMMON_START);
}

ascii_noload_VRAM_END = .;
ascii_noload_VRAM_SIZE = ABSOLUTE(ascii_noload_VRAM_END - ascii_noload_VRAM);

__romPos += SIZEOF(.ascii);
__romPos = ALIGN(__romPos, 0x40);
. = ALIGN(., 0x40);
ascii_VRAM_END = .;
ascii_VRAM_SIZE = ABSOLUTE(ascii_VRAM_END - ascii_VRAM);
ascii_ROM_END = __romPos;
ascii_ROM_SIZE = ABSOLUTE(ascii_ROM_END - ascii_ROM_START);

__romPos = ALIGN(__romPos, 0x8);
. = ALIGN(., 0x8);
main_ROM_START = __romPos;
Expand Down
13 changes: 12 additions & 1 deletion tests/partial_linking/follow_segment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,19 @@ segments:
- { path: src/libultra.o } # yes a single file, deal with it

- name: kanji
include_if_any: [[version, us], [version, jp]]
files:
- { path: src/kanji/kanji.o }
- { path: src/alphabets/kanji.o }

- name: ascii
include_if_any: [[version, us], [version, eu]]
files:
- { path: src/alphabets/ascii.o }

- name: latin1
include_if_any: [[version, eu]]
files:
- { path: src/alphabets/latin1.o }

- name: main
follows_segment: boot
Expand Down
4 changes: 4 additions & 0 deletions tests/partial_linking/follow_segment/us/ascii.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
build/us/segments/ascii.o: \
build/us/src/alphabets/ascii.o

build/us/src/alphabets/ascii.o:
66 changes: 66 additions & 0 deletions tests/partial_linking/follow_segment/us/ascii.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
SECTIONS
{
.text :
{
FILL(0x00000000);
build/us/src/alphabets/ascii.o(.text*);
}

.data :
{
FILL(0x00000000);
build/us/src/alphabets/ascii.o(.data*);
}

.rodata :
{
FILL(0x00000000);
build/us/src/alphabets/ascii.o(.rodata*);
}

.sdata :
{
FILL(0x00000000);
build/us/src/alphabets/ascii.o(.sdata*);
}

.sbss (NOLOAD) :
{
FILL(0x00000000);
build/us/src/alphabets/ascii.o(.sbss*);
}

.scommon (NOLOAD) :
{
FILL(0x00000000);
build/us/src/alphabets/ascii.o(.scommon*);
}

.bss (NOLOAD) :
{
FILL(0x00000000);
build/us/src/alphabets/ascii.o(.bss*);
}

COMMON (NOLOAD) :
{
FILL(0x00000000);
build/us/src/alphabets/ascii.o(COMMON*);
}

.shstrtab 0 :
{
*(.shstrtab);
}

/DISCARD/ :
{
*(.reginfo);
*(.MIPS.abiflags);
*(.MIPS.options);
*(.note.gnu.build-id);
*(.interp);
*(.eh_frame);
*(*);
}
}
4 changes: 2 additions & 2 deletions tests/partial_linking/follow_segment/us/kanji.d
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
build/us/segments/kanji.o: \
build/us/src/kanji/kanji.o
build/us/src/alphabets/kanji.o

build/us/src/kanji/kanji.o:
build/us/src/alphabets/kanji.o:
16 changes: 8 additions & 8 deletions tests/partial_linking/follow_segment/us/kanji.ld
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,49 @@ SECTIONS
.text :
{
FILL(0x00000000);
build/us/src/kanji/kanji.o(.text*);
build/us/src/alphabets/kanji.o(.text*);
}

.data :
{
FILL(0x00000000);
build/us/src/kanji/kanji.o(.data*);
build/us/src/alphabets/kanji.o(.data*);
}

.rodata :
{
FILL(0x00000000);
build/us/src/kanji/kanji.o(.rodata*);
build/us/src/alphabets/kanji.o(.rodata*);
}

.sdata :
{
FILL(0x00000000);
build/us/src/kanji/kanji.o(.sdata*);
build/us/src/alphabets/kanji.o(.sdata*);
}

.sbss (NOLOAD) :
{
FILL(0x00000000);
build/us/src/kanji/kanji.o(.sbss*);
build/us/src/alphabets/kanji.o(.sbss*);
}

.scommon (NOLOAD) :
{
FILL(0x00000000);
build/us/src/kanji/kanji.o(.scommon*);
build/us/src/alphabets/kanji.o(.scommon*);
}

.bss (NOLOAD) :
{
FILL(0x00000000);
build/us/src/kanji/kanji.o(.bss*);
build/us/src/alphabets/kanji.o(.bss*);
}

COMMON (NOLOAD) :
{
FILL(0x00000000);
build/us/src/kanji/kanji.o(COMMON*);
build/us/src/alphabets/kanji.o(COMMON*);
}

.shstrtab 0 :
Expand Down

0 comments on commit 38f7239

Please sign in to comment.