From 38f7239d8ef7b5170975756e17ab18daf9175ee0 Mon Sep 17 00:00:00 2001 From: Angie Date: Wed, 17 Jul 2024 16:53:41 -0400 Subject: [PATCH] Avoid generating sub-scripts of conditionally excluded segments during partial linking scripts generation. --- CHANGELOG.md | 2 + slinky/src/partial_linker_writer.rs | 9 +++ tests/partial_linking/follow_segment.d | 2 + tests/partial_linking/follow_segment.h | 36 +++++++++ tests/partial_linking/follow_segment.ld | 80 +++++++++++++++++++ tests/partial_linking/follow_segment.yaml | 13 ++- .../partial_linking/follow_segment/us/ascii.d | 4 + .../follow_segment/us/ascii.ld | 66 +++++++++++++++ .../partial_linking/follow_segment/us/kanji.d | 4 +- .../follow_segment/us/kanji.ld | 16 ++-- 10 files changed, 221 insertions(+), 11 deletions(-) create mode 100644 tests/partial_linking/follow_segment/us/ascii.d create mode 100644 tests/partial_linking/follow_segment/us/ascii.ld diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ab23dd..52d6437 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/slinky/src/partial_linker_writer.rs b/slinky/src/partial_linker_writer.rs index 9dcf49f..2ae714a 100644 --- a/slinky/src/partial_linker_writer.rs +++ b/slinky/src/partial_linker_writer.rs @@ -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); diff --git a/tests/partial_linking/follow_segment.d b/tests/partial_linking/follow_segment.d index b75013e..47feaf4 100644 --- a/tests/partial_linking/follow_segment.d +++ b/tests/partial_linking/follow_segment.d @@ -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: diff --git a/tests/partial_linking/follow_segment.h b/tests/partial_linking/follow_segment.h index bee455f..85e66f8 100644 --- a/tests/partial_linking/follow_segment.h +++ b/tests/partial_linking/follow_segment.h @@ -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[]; diff --git a/tests/partial_linking/follow_segment.ld b/tests/partial_linking/follow_segment.ld index 498e04a..c1d6aba 100644 --- a/tests/partial_linking/follow_segment.ld +++ b/tests/partial_linking/follow_segment.ld @@ -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; diff --git a/tests/partial_linking/follow_segment.yaml b/tests/partial_linking/follow_segment.yaml index 4985566..67dbce0 100644 --- a/tests/partial_linking/follow_segment.yaml +++ b/tests/partial_linking/follow_segment.yaml @@ -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 diff --git a/tests/partial_linking/follow_segment/us/ascii.d b/tests/partial_linking/follow_segment/us/ascii.d new file mode 100644 index 0000000..ed4f8d7 --- /dev/null +++ b/tests/partial_linking/follow_segment/us/ascii.d @@ -0,0 +1,4 @@ +build/us/segments/ascii.o: \ + build/us/src/alphabets/ascii.o + +build/us/src/alphabets/ascii.o: diff --git a/tests/partial_linking/follow_segment/us/ascii.ld b/tests/partial_linking/follow_segment/us/ascii.ld new file mode 100644 index 0000000..4047d21 --- /dev/null +++ b/tests/partial_linking/follow_segment/us/ascii.ld @@ -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); + *(*); + } +} diff --git a/tests/partial_linking/follow_segment/us/kanji.d b/tests/partial_linking/follow_segment/us/kanji.d index 914b488..e45e8f7 100644 --- a/tests/partial_linking/follow_segment/us/kanji.d +++ b/tests/partial_linking/follow_segment/us/kanji.d @@ -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: diff --git a/tests/partial_linking/follow_segment/us/kanji.ld b/tests/partial_linking/follow_segment/us/kanji.ld index 8686438..13f7845 100644 --- a/tests/partial_linking/follow_segment/us/kanji.ld +++ b/tests/partial_linking/follow_segment/us/kanji.ld @@ -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 :