Skip to content

Commit

Permalink
Fix section_order not being applied to files inside of groups
Browse files Browse the repository at this point in the history
Closes #71
  • Loading branch information
AngheloAlf committed Jul 16, 2024
1 parent c20ea9c commit ce115f0
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 46 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ 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.

## [0.2.4] - 2024-07-15

### Fixed

- Fix Crate version not updated.
- Fix crate version not updated.

## [0.2.3] - 2024-07-15 [YANKED]

Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions slinky-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[package]
name = "slinky-cli"
version = "0.2.4"
version = "0.2.5"
edition = "2021"
rust-version = "1.74.1"
authors = ["Anghelo Carvajal <[email protected]>"]
Expand All @@ -17,4 +17,4 @@ categories = ["development-tools::build-utils", "command-line-utilities"]
[dependencies]
clap = { version = "4.5.1", features = ["derive"] }
regex = "1.10.5"
slinky = { path = "../slinky", version = "0.2.4" }
slinky = { path = "../slinky", version = "0.2.5" }
2 changes: 1 addition & 1 deletion slinky/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[package]
name = "slinky"
version = "0.2.4"
version = "0.2.5"
edition = "2021"
rust-version = "1.66.1"
authors = ["Anghelo Carvajal <[email protected]>"]
Expand Down
82 changes: 51 additions & 31 deletions slinky/src/linker_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,7 @@ impl LinkerWriter<'_> {
file: &FileInfo,
segment: &Segment,
section: &str,
sections: &[String],
base_path: &Path,
) -> Result<(), SlinkyError> {
if !self.rs.should_emit_entry(
Expand Down Expand Up @@ -755,9 +756,57 @@ impl LinkerWriter<'_> {
new_base_path.extend(&file.dir);

for file_of_group in &file.files {
self.emit_file(file_of_group, segment, section, &new_base_path)?;
//self.emit_file(file_of_group, segment, section, sections, &new_base_path)?;
self.emit_section_for_file(
file_of_group,
segment,
section,
sections,
&new_base_path,
)?;
}
}
}

Ok(())
}

fn emit_section_for_file(
&mut self,
file: &FileInfo,
segment: &Segment,
section: &str,
sections: &[String],
base_path: &Path,
) -> Result<(), SlinkyError> {
if !file.section_order.is_empty() {
// Keys specify the section and value specify where it will be put.
// For example: `section_order: { .data: .rodata }`, meaning the `.data` of the file should be put within its `.rodata`.
// It was done this way instead of the other way around (ie keys specifying the destination section) because the other way would not allow specifying multiple sections should be put in the same destination section.

let mut sections_to_emit_here = if file.section_order.contains_key(section) {
// This section should be placed somewhere else
vec![]
} else {
vec![section]
};

// Check if any other section should be placed be placed here
for (k, v) in &file.section_order {
if v == section {
sections_to_emit_here.push(k);
}
}

// We need to preserve the order given by alloc_sections or noload_sections
sections_to_emit_here.sort_unstable_by_key(|&k| sections.iter().position(|s| s == k));

for k in sections_to_emit_here {
self.emit_file(file, segment, k, sections, base_path)?;
}
} else {
// No need to mess with section ordering, just emit the file
self.emit_file(file, segment, section, sections, base_path)?;
}

Ok(())
Expand All @@ -777,36 +826,7 @@ impl LinkerWriter<'_> {
}

for file in &segment.files {
if !file.section_order.is_empty() {
// Keys specify the section and value specify where it will be put.
// For example: `section_order: { .data: .rodata }`, meaning the `.data` of the file should be put within its `.rodata`.
// It was done this way instead of the other way around (ie keys specifying the destination section) because the other way would not allow specifying multiple sections should be put in the same destination section.

let mut sections_to_emit_here = if file.section_order.contains_key(section) {
// This section should be placed somewhere else
vec![]
} else {
vec![section]
};

// Check if any other section should be placed be placed here
for (k, v) in &file.section_order {
if v == section {
sections_to_emit_here.push(k);
}
}

// We need to preserve the order given by alloc_sections or noload_sections
sections_to_emit_here
.sort_unstable_by_key(|&k| sections.iter().position(|s| s == k));

for k in sections_to_emit_here {
self.emit_file(file, segment, k, &base_path)?;
}
} else {
// No need to mess with section ordering, just emit the file
self.emit_file(file, segment, section, &base_path)?;
}
self.emit_section_for_file(file, segment, section, sections, &base_path)?;
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion slinky/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

pub static VERSION_MAJOR: u32 = 0;
pub static VERSION_MINOR: u32 = 2;
pub static VERSION_PATCH: u32 = 4;
pub static VERSION_PATCH: u32 = 5;

pub static VERSION_TUPLE: (u32, u32, u32) = (VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH);
8 changes: 4 additions & 4 deletions tests/test_cases/groups.ld
Original file line number Diff line number Diff line change
Expand Up @@ -1576,10 +1576,6 @@ SECTIONS
build/src/libmus/aud_thread.o(.data*);
build/src/libmus/lib_memory.o(.data*);
build/src/libmus/aud_samples.o(.data*);
build/src/rsp/rspboot.o(.data*);
build/src/rsp/aspMain.o(.data*);
build/src/rsp/f3dex2.o(.data*);
build/src/rsp/s2dex.o(.data*);
main_segment_DATA_END = .;
main_segment_DATA_SIZE = ABSOLUTE(main_segment_DATA_END - main_segment_DATA_START);

Expand All @@ -1594,9 +1590,13 @@ SECTIONS
build/src/libmus/aud_thread.o(.rodata*);
build/src/libmus/lib_memory.o(.rodata*);
build/src/libmus/aud_samples.o(.rodata*);
build/src/rsp/rspboot.o(.data*);
build/src/rsp/rspboot.o(.rodata*);
build/src/rsp/aspMain.o(.data*);
build/src/rsp/aspMain.o(.rodata*);
build/src/rsp/f3dex2.o(.data*);
build/src/rsp/f3dex2.o(.rodata*);
build/src/rsp/s2dex.o(.data*);
build/src/rsp/s2dex.o(.rodata*);
main_segment_RODATA_END = .;
main_segment_RODATA_SIZE = ABSOLUTE(main_segment_RODATA_END - main_segment_RODATA_START);
Expand Down
8 changes: 4 additions & 4 deletions tests/test_cases/groups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,10 @@ segments:
- kind: group
dir: src/rsp
files:
- { path: rspboot.o }
- { path: aspMain.o }
- { path: f3dex2.o }
- { path: s2dex.o }
- { path: rspboot.o, section_order: { .data: .rodata } }
- { path: aspMain.o, section_order: { .data: .rodata } }
- { path: f3dex2.o, section_order: { .data: .rodata } }
- { path: s2dex.o, section_order: { .data: .rodata } }

- name: framebuffer
fixed_vram: 0x803B5000 # 0x80400000 - (SCREEN_WIDTH * SCREEN_HEIGHT * 2 * sizeof(u16))
Expand Down

0 comments on commit ce115f0

Please sign in to comment.