diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cae2b1..d183ea9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Add option to control emission of `noload` segment. + ### Changed - Include `.symtab` and `.strtab` in default value of `sections_allowlist_extra` diff --git a/slinky/src/keep_sections.rs b/slinky/src/keep_sections.rs index 9d3261f..b1813c3 100644 --- a/slinky/src/keep_sections.rs +++ b/slinky/src/keep_sections.rs @@ -1,4 +1,4 @@ -/* SPDX-FileCopyrightText: © 2024 decompals */ +/* SPDX-FileCopyrightText: © 2025 decompals */ /* SPDX-License-Identifier: MIT */ use std::collections::HashSet; @@ -10,15 +10,11 @@ use serde::Deserialize; #[derive(Clone, Debug, Eq, PartialEq, Deserialize)] #[serde(deny_unknown_fields)] #[serde(untagged)] +#[derive(Default)] pub enum KeepSections { #[serde(skip)] + #[default] Absent, All(bool), WhichOnes(HashSet), } - -impl Default for KeepSections { - fn default() -> Self { - Self::Absent - } -} diff --git a/slinky/src/linker_writer.rs b/slinky/src/linker_writer.rs index 1d84b3c..1d1642c 100644 --- a/slinky/src/linker_writer.rs +++ b/slinky/src/linker_writer.rs @@ -1,4 +1,4 @@ -/* SPDX-FileCopyrightText: © 2024 decompals */ +/* SPDX-FileCopyrightText: © 2025 decompals */ /* SPDX-License-Identifier: MIT */ use std::borrow::Cow; @@ -559,7 +559,9 @@ impl LinkerWriter<'_> { self.buffer.write_empty_line(); // Emit noload segment - self.write_segment(segment, &segment.noload_sections, true)?; + if segment.emit_noload_segment { + self.write_segment(segment, &segment.noload_sections, true)?; + } self.buffer.write_empty_line(); @@ -617,7 +619,9 @@ impl LinkerWriter<'_> { self.buffer.write_empty_line(); // Emit noload segment - self.write_single_segment(segment, &segment.noload_sections, true)?; + if segment.emit_noload_segment { + self.write_single_segment(segment, &segment.noload_sections, true)?; + } self.buffer.write_empty_line(); diff --git a/slinky/src/partial_linker_writer.rs b/slinky/src/partial_linker_writer.rs index 6a42536..147c090 100644 --- a/slinky/src/partial_linker_writer.rs +++ b/slinky/src/partial_linker_writer.rs @@ -1,4 +1,4 @@ -/* SPDX-FileCopyrightText: © 2024 decompals */ +/* SPDX-FileCopyrightText: © 2025 decompals */ /* SPDX-License-Identifier: MIT */ use crate::{ @@ -64,7 +64,7 @@ impl ScriptImporter for PartialLinkerWriter<'_> { let mut p = partial_build_segments_folder.clone(); - p.push(&format!("{}.o", segment.name)); + p.push(format!("{}.o", segment.name)); self.main_writer .add_segment(&segment.clone_with_new_files(vec![FileInfo::new_object(p)]))?; @@ -186,12 +186,12 @@ impl ScriptGenerator for PartialLinkerWriter<'_> {} // Getters / Setters impl PartialLinkerWriter<'_> { #[must_use] - pub fn get_main_writer(&self) -> &LinkerWriter { + pub fn get_main_writer(&self) -> &LinkerWriter<'_> { &self.main_writer } #[must_use] - pub fn get_partial_writers(&self) -> &Vec<(LinkerWriter, String)> { + pub fn get_partial_writers(&self) -> &Vec<(LinkerWriter<'_>, String)> { &self.partial_writers } } diff --git a/slinky/src/segment.rs b/slinky/src/segment.rs index 08e5760..354273d 100644 --- a/slinky/src/segment.rs +++ b/slinky/src/segment.rs @@ -1,4 +1,4 @@ -/* SPDX-FileCopyrightText: © 2024 decompals */ +/* SPDX-FileCopyrightText: © 2025 decompals */ /* SPDX-License-Identifier: MIT */ use std::{borrow::Cow, collections::HashMap, path::PathBuf}; @@ -50,6 +50,7 @@ pub struct Segment { // The default value of the following members come from Settings pub alloc_sections: Vec, pub noload_sections: Vec, + pub emit_noload_segment: bool, pub subalign: Option, pub segment_start_align: Option, @@ -86,6 +87,7 @@ impl Segment { exclude_if_all: self.exclude_if_all.clone(), alloc_sections: self.alloc_sections.clone(), noload_sections: self.noload_sections.clone(), + emit_noload_segment: self.emit_noload_segment, subalign: self.subalign, segment_start_align: self.segment_start_align, segment_end_align: self.segment_end_align, @@ -159,6 +161,8 @@ pub(crate) struct SegmentSerial { pub alloc_sections: AbsentNullable>, #[serde(default)] pub noload_sections: AbsentNullable>, + #[serde(default)] + pub emit_noload_segment: AbsentNullable, #[serde(default)] pub subalign: AbsentNullable, @@ -297,6 +301,9 @@ impl Serial for SegmentSerial { let noload_sections = self .noload_sections .get_non_null("noload_sections", || settings.noload_sections.clone())?; + let emit_noload_segment = self + .emit_noload_segment + .get_non_null("emit_noload_segment", || settings.emit_noload_segment)?; if let Some(gp) = &gp_info { if !alloc_sections.contains(&gp.section) && !noload_sections.contains(&gp.section) { @@ -376,6 +383,7 @@ impl Serial for SegmentSerial { exclude_if_all, alloc_sections, noload_sections, + emit_noload_segment, subalign, segment_start_align, segment_end_align, diff --git a/slinky/src/settings.rs b/slinky/src/settings.rs index b3e5fd3..1187158 100644 --- a/slinky/src/settings.rs +++ b/slinky/src/settings.rs @@ -1,4 +1,4 @@ -/* SPDX-FileCopyrightText: © 2024 decompals */ +/* SPDX-FileCopyrightText: © 2025 decompals */ /* SPDX-License-Identifier: MIT */ use serde::Deserialize; @@ -36,6 +36,7 @@ pub struct Settings { // Options passed down to each segment pub alloc_sections: Vec, pub noload_sections: Vec, + pub emit_noload_segment: bool, pub subalign: Option, pub segment_start_align: Option, @@ -138,6 +139,10 @@ fn settings_default_noload_sections() -> Vec { ] } +const fn settings_default_emit_noload_segment() -> bool { + true +} + const fn settings_default_subalign() -> Option { None } @@ -205,6 +210,7 @@ impl Default for Settings { alloc_sections: settings_default_alloc_sections(), noload_sections: settings_default_noload_sections(), + emit_noload_segment: settings_default_emit_noload_segment(), subalign: settings_default_subalign(), segment_start_align: settings_default_segment_start_align(), @@ -321,6 +327,8 @@ pub(crate) struct SettingsSerial { pub alloc_sections: AbsentNullable>, #[serde(default)] pub noload_sections: AbsentNullable>, + #[serde(default)] + pub emit_noload_segment: AbsentNullable, #[serde(default)] pub subalign: AbsentNullable, @@ -421,6 +429,9 @@ impl SettingsSerial { let noload_sections = self .noload_sections .get_non_null("noload_sections", settings_default_noload_sections)?; + let emit_noload_segment = self + .emit_noload_segment + .get_non_null("emit_noload_segment", settings_default_emit_noload_segment)?; let subalign = self .subalign @@ -488,6 +499,8 @@ impl SettingsSerial { alloc_sections, noload_sections, + emit_noload_segment, + subalign, segment_start_align, segment_end_align,