diff --git a/CHANGELOG.md b/CHANGELOG.md index 0bc7785..6ab23dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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] diff --git a/Cargo.lock b/Cargo.lock index 42d2b85..285a6bb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -424,7 +424,7 @@ dependencies = [ [[package]] name = "slinky" -version = "0.2.4" +version = "0.2.5" dependencies = [ "indexmap", "rstest", @@ -435,7 +435,7 @@ dependencies = [ [[package]] name = "slinky-cli" -version = "0.2.4" +version = "0.2.5" dependencies = [ "clap", "regex", diff --git a/slinky-cli/Cargo.toml b/slinky-cli/Cargo.toml index 7480a86..659811e 100644 --- a/slinky-cli/Cargo.toml +++ b/slinky-cli/Cargo.toml @@ -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 "] @@ -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" } diff --git a/slinky/Cargo.toml b/slinky/Cargo.toml index c8856af..88f2a9c 100644 --- a/slinky/Cargo.toml +++ b/slinky/Cargo.toml @@ -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 "] diff --git a/slinky/src/linker_writer.rs b/slinky/src/linker_writer.rs index 5fd707d..3234923 100644 --- a/slinky/src/linker_writer.rs +++ b/slinky/src/linker_writer.rs @@ -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( @@ -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(()) @@ -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(()) diff --git a/slinky/src/version.rs b/slinky/src/version.rs index 7663be8..d42e94d 100644 --- a/slinky/src/version.rs +++ b/slinky/src/version.rs @@ -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); diff --git a/tests/test_cases/groups.ld b/tests/test_cases/groups.ld index d614849..2299a81 100644 --- a/tests/test_cases/groups.ld +++ b/tests/test_cases/groups.ld @@ -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); @@ -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); diff --git a/tests/test_cases/groups.yaml b/tests/test_cases/groups.yaml index ea71ba6..87ab8ee 100644 --- a/tests/test_cases/groups.yaml +++ b/tests/test_cases/groups.yaml @@ -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))