Skip to content

Commit

Permalink
Add .a file support
Browse files Browse the repository at this point in the history
Fixes #28
  • Loading branch information
AngheloAlf committed Feb 27, 2024
1 parent ad8bf9b commit 024cc3d
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 8 deletions.
7 changes: 5 additions & 2 deletions docs/file_format/file.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ segments:

- `object`: The path points to a relocatable object file. The [`path`](#path) is
required.
- `kind`: The path points to an `.a` archive file. The [`path`](#path) is
required.
- `pad`: Do not link any file but increment the position of the
[`section`](#section) in the linker script by [`pad_amount`](#pad_amount)
bytes. Both [`section`](#section) and [`pad_amount`](#pad_amount) are required.
Expand All @@ -59,8 +61,9 @@ segments:

Guessed from `path` using the following file extensions:

- `.o`: `Object`.
- Anything else: `Object`.
- `.o`: `object`.
- `.a`: `archive`.
- Anything else: `object`.

## `pad_amount`

Expand Down
8 changes: 4 additions & 4 deletions slinky/src/file_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl FileInfoSerial {
// Since a `kind` can be deduced from a `path` (which requires a `path`) then we need to do both simultaneously
let (path, kind) = match self.kind.get_non_null_no_default("kind")? {
Some(k) => match k {
FileKind::Object => {
FileKind::Object | FileKind::Archive => {
let p = self.path.get("path")?;

if p == Path::new("") {
Expand Down Expand Up @@ -79,7 +79,7 @@ impl FileInfoSerial {
};

let pad_amount = match kind {
FileKind::Object | FileKind::LinkerOffset => {
FileKind::Object | FileKind::LinkerOffset | FileKind::Archive => {
if self.pad_amount.has_value() {
return Err(SlinkyError::InvalidFieldCombo {
field1: "pad_amount".into(),
Expand All @@ -92,7 +92,7 @@ impl FileInfoSerial {
};

let section = match kind {
FileKind::Object => {
FileKind::Object | FileKind::Archive => {
if self.section.has_value() {
return Err(SlinkyError::InvalidFieldCombo {
field1: "section".into(),
Expand All @@ -105,7 +105,7 @@ impl FileInfoSerial {
};

let linker_offset_name = match kind {
FileKind::Object | FileKind::Pad => {
FileKind::Object | FileKind::Pad | FileKind::Archive => {
if self.linker_offset_name.has_value() {
return Err(SlinkyError::InvalidFieldCombo {
field1: "linker_offset_name".into(),
Expand Down
3 changes: 2 additions & 1 deletion slinky/src/file_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use serde::Deserialize;
#[serde(rename_all = "snake_case")]
pub enum FileKind {
Object,
// Archive,
Archive,
Pad,
LinkerOffset,
}
Expand All @@ -21,6 +21,7 @@ impl FileKind {
Some(ext) => match ext.to_str() {
None => Self::Object,
Some("o") => Self::Object,
Some("a") => Self::Archive,
Some(&_) => Self::Object,
},
}
Expand Down
4 changes: 3 additions & 1 deletion slinky/src/linker_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,9 @@ impl LinkerWriter<'_> {
FileKind::Object => {
self.writeln(&format!("{}({}{});", path.display(), section, wildcard));
}
//FileKind::Archive => todo!(),
FileKind::Archive => {
self.writeln(&format!("{}:*({}{});", path.display(), section, wildcard));
}
FileKind::Pad => {
if file.section == section {
self.writeln(&format!(". += 0x{:X};", file.pad_amount));
Expand Down
13 changes: 13 additions & 0 deletions tests/input_files/archives.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
settings:
base_path: build
subalign: 32

segments:
- name: boot
subalign: null
files:
- { path: src/boot/boot_main.o }
- { path: src/boot/dmadata.o }
- { path: asm/util.o }
- { path: lib/libgultra_rom.a }
- { path: lib/libmus.a, kind: archive }
113 changes: 113 additions & 0 deletions tests/linker_scripts/archives.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
SECTIONS
{
__romPos = 0x0;

boot_ROM_START = __romPos;
boot_VRAM = ADDR(.boot);
boot_alloc_VRAM = .;
.boot : AT(boot_ROM_START)
{
FILL(0x00000000);
boot_TEXT_START = .;
build/src/boot/boot_main.o(.text*);
build/src/boot/dmadata.o(.text*);
build/asm/util.o(.text*);
build/lib/libgultra_rom.a:*(.text*);
build/lib/libmus.a:*(.text*);
boot_TEXT_END = .;
boot_TEXT_SIZE = ABSOLUTE(boot_TEXT_END - boot_TEXT_START);

boot_DATA_START = .;
build/src/boot/boot_main.o(.data*);
build/src/boot/dmadata.o(.data*);
build/asm/util.o(.data*);
build/lib/libgultra_rom.a:*(.data*);
build/lib/libmus.a:*(.data*);
boot_DATA_END = .;
boot_DATA_SIZE = ABSOLUTE(boot_DATA_END - boot_DATA_START);

boot_RODATA_START = .;
build/src/boot/boot_main.o(.rodata*);
build/src/boot/dmadata.o(.rodata*);
build/asm/util.o(.rodata*);
build/lib/libgultra_rom.a:*(.rodata*);
build/lib/libmus.a:*(.rodata*);
boot_RODATA_END = .;
boot_RODATA_SIZE = ABSOLUTE(boot_RODATA_END - boot_RODATA_START);

boot_SDATA_START = .;
build/src/boot/boot_main.o(.sdata*);
build/src/boot/dmadata.o(.sdata*);
build/asm/util.o(.sdata*);
build/lib/libgultra_rom.a:*(.sdata*);
build/lib/libmus.a:*(.sdata*);
boot_SDATA_END = .;
boot_SDATA_SIZE = ABSOLUTE(boot_SDATA_END - boot_SDATA_START);
}
boot_alloc_VRAM_END = .;
boot_alloc_VRAM_SIZE = ABSOLUTE(boot_alloc_VRAM_END - boot_alloc_VRAM);

boot_noload_VRAM = .;
.boot.noload (NOLOAD) :
{
FILL(0x00000000);
boot_SBSS_START = .;
build/src/boot/boot_main.o(.sbss*);
build/src/boot/dmadata.o(.sbss*);
build/asm/util.o(.sbss*);
build/lib/libgultra_rom.a:*(.sbss*);
build/lib/libmus.a:*(.sbss*);
boot_SBSS_END = .;
boot_SBSS_SIZE = ABSOLUTE(boot_SBSS_END - boot_SBSS_START);

boot_SCOMMON_START = .;
build/src/boot/boot_main.o(.scommon*);
build/src/boot/dmadata.o(.scommon*);
build/asm/util.o(.scommon*);
build/lib/libgultra_rom.a:*(.scommon*);
build/lib/libmus.a:*(.scommon*);
boot_SCOMMON_END = .;
boot_SCOMMON_SIZE = ABSOLUTE(boot_SCOMMON_END - boot_SCOMMON_START);

boot_BSS_START = .;
build/src/boot/boot_main.o(.bss*);
build/src/boot/dmadata.o(.bss*);
build/asm/util.o(.bss*);
build/lib/libgultra_rom.a:*(.bss*);
build/lib/libmus.a:*(.bss*);
boot_BSS_END = .;
boot_BSS_SIZE = ABSOLUTE(boot_BSS_END - boot_BSS_START);

bootCOMMON_START = .;
build/src/boot/boot_main.o(COMMON*);
build/src/boot/dmadata.o(COMMON*);
build/asm/util.o(COMMON*);
build/lib/libgultra_rom.a:*(COMMON*);
build/lib/libmus.a:*(COMMON*);
bootCOMMON_END = .;
bootCOMMON_SIZE = ABSOLUTE(bootCOMMON_END - bootCOMMON_START);
}
boot_noload_VRAM_END = .;
boot_noload_VRAM_SIZE = ABSOLUTE(boot_noload_VRAM_END - boot_noload_VRAM);
boot_VRAM_END = .;
boot_VRAM_SIZE = ABSOLUTE(boot_VRAM_END - boot_VRAM);
__romPos += SIZEOF(.boot);
boot_ROM_END = __romPos;
boot_ROM_SIZE = ABSOLUTE(boot_ROM_END - boot_ROM_START);

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

/DISCARD/ :
{
*(.reginfo);
*(.MIPS.abiflags);
*(.MIPS.options);
*(.note.gnu.build-id);
*(.interp);
*(.eh_frame);
*(*);
}
}

0 comments on commit 024cc3d

Please sign in to comment.