Skip to content

Commit

Permalink
Simplify the formatting used for extra sections.
Browse files Browse the repository at this point in the history
  • Loading branch information
AngheloAlf committed Aug 31, 2024
1 parent 1161f29 commit 4d59b78
Show file tree
Hide file tree
Showing 48 changed files with 211 additions and 829 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `lld` can segfault in certain conditions if those sections are not listed
explicitly on the linker script.
- Add `.got` to the default list of discarded sections.
- Simplify the formatting used for extra sections.

## [0.3.0] - 2024-08-17

Expand Down
18 changes: 2 additions & 16 deletions slinky/src/linker_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,15 +435,8 @@ impl LinkerWriter<'_> {
self.buffer.write_empty_line();
}

let address = " 0";

for sect in &self.d.settings.sections_allowlist {
self.buffer.writeln(&format!("{}{} :", sect, address));
self.buffer.begin_block();

self.buffer.writeln(&format!("*({});", sect));

self.buffer.end_block();
self.buffer.write_single_entry_section(sect, "0");
}

need_ln = true;
Expand All @@ -454,15 +447,8 @@ impl LinkerWriter<'_> {
self.buffer.write_empty_line();
}

let address = " 0";

for sect in &self.d.settings.sections_allowlist_extra {
self.buffer.writeln(&format!("{}{} :", sect, address));
self.buffer.begin_block();

self.buffer.writeln(&format!("*({});", sect));

self.buffer.end_block();
self.buffer.write_single_entry_section(sect, "0");
}

need_ln = true;
Expand Down
4 changes: 4 additions & 0 deletions slinky/src/script_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ impl ScriptBuffer {
self.writeln("}");
}

pub fn write_single_entry_section(&mut self, section: &str, address: &str) {
self.writeln(&format!("{} {} : {{ *({}); }}", section, address, section));
}

pub fn write_linker_symbol(&mut self, symbol: &str, value: &str) {
// TODO: check `symbol` is a valid C identifier

Expand Down
15 changes: 3 additions & 12 deletions tests/partial_linking/follow_segment.ld
Original file line number Diff line number Diff line change
Expand Up @@ -330,18 +330,9 @@ SECTIONS
main_ROM_END = __romPos;
main_ROM_SIZE = ABSOLUTE(main_ROM_END - main_ROM_START);

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

/DISCARD/ :
{
Expand Down
15 changes: 3 additions & 12 deletions tests/partial_linking/follow_segment/us/ascii.ld
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,9 @@ SECTIONS
build/us/src/alphabets/ascii.o(COMMON*);
}

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

/DISCARD/ :
{
Expand Down
15 changes: 3 additions & 12 deletions tests/partial_linking/follow_segment/us/boot.ld
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,9 @@ SECTIONS
build/us/src/libultra.o(COMMON*);
}

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

/DISCARD/ :
{
Expand Down
15 changes: 3 additions & 12 deletions tests/partial_linking/follow_segment/us/kanji.ld
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,9 @@ SECTIONS
build/us/src/alphabets/kanji.o(COMMON*);
}

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

/DISCARD/ :
{
Expand Down
15 changes: 3 additions & 12 deletions tests/partial_linking/follow_segment/us/main.ld
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,9 @@ SECTIONS
KEEP(build/us/asm/main/util.o(COMMON*));
}

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

/DISCARD/ :
{
Expand Down
15 changes: 3 additions & 12 deletions tests/partial_linking/required_syms.ld
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,9 @@ SECTIONS
boot_ROM_END = __romPos;
boot_ROM_SIZE = ABSOLUTE(boot_ROM_END - boot_ROM_START);

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

/DISCARD/ :
{
Expand Down
15 changes: 3 additions & 12 deletions tests/partial_linking/required_syms/boot.ld
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,9 @@ SECTIONS
build/src/boot/boot_main.o(COMMON*);
}

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

/DISCARD/ :
{
Expand Down
15 changes: 3 additions & 12 deletions tests/partial_linking/undefined_syms.ld
Original file line number Diff line number Diff line change
Expand Up @@ -266,18 +266,9 @@ SECTIONS
boot_ROM_END = __romPos;
boot_ROM_SIZE = ABSOLUTE(boot_ROM_END - boot_ROM_START);

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

/DISCARD/ :
{
Expand Down
15 changes: 3 additions & 12 deletions tests/partial_linking/undefined_syms/us/boot.ld
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,9 @@ SECTIONS
build/asm/util.o(COMMON*);
}

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

/DISCARD/ :
{
Expand Down
15 changes: 3 additions & 12 deletions tests/partial_linking/undefined_syms/us/entry.ld
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,9 @@ SECTIONS
build/asm/entry.o(COMMON*);
}

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

/DISCARD/ :
{
Expand Down
15 changes: 3 additions & 12 deletions tests/partial_linking/undefined_syms/us/header.ld
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,9 @@ SECTIONS
build/asm/data/rom_header.o(COMMON*);
}

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

/DISCARD/ :
{
Expand Down
15 changes: 3 additions & 12 deletions tests/partial_linking/undefined_syms/us/ipl3.ld
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,9 @@ SECTIONS
build/asm/data/ipl3.o(COMMON*);
}

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

/DISCARD/ :
{
Expand Down
15 changes: 3 additions & 12 deletions tests/partial_linking/vram_classes.ld
Original file line number Diff line number Diff line change
Expand Up @@ -1058,18 +1058,9 @@ SECTIONS
segment_05_VRAM_CLASS_SIZE = segment_05_VRAM_CLASS_END - segment_05_VRAM_CLASS_START;
segment_06_VRAM_CLASS_SIZE = segment_06_VRAM_CLASS_END - segment_06_VRAM_CLASS_START;

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

/DISCARD/ :
{
Expand Down
15 changes: 3 additions & 12 deletions tests/partial_linking/vram_classes/assets1.ld
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,9 @@ SECTIONS
build/src/assets/assets1/dlist.o(COMMON*);
}

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

/DISCARD/ :
{
Expand Down
15 changes: 3 additions & 12 deletions tests/partial_linking/vram_classes/assets2.ld
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,9 @@ SECTIONS
build/src/assets/assets2/dlist.o(COMMON*);
}

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

/DISCARD/ :
{
Expand Down
Loading

0 comments on commit 4d59b78

Please sign in to comment.