Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
10 changes: 3 additions & 7 deletions slinky/src/keep_sections.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* SPDX-FileCopyrightText: © 2024 decompals */
/* SPDX-FileCopyrightText: © 2025 decompals */
/* SPDX-License-Identifier: MIT */

use std::collections::HashSet;
Expand All @@ -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<String>),
}

impl Default for KeepSections {
fn default() -> Self {
Self::Absent
}
}
10 changes: 7 additions & 3 deletions slinky/src/linker_writer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* SPDX-FileCopyrightText: © 2024 decompals */
/* SPDX-FileCopyrightText: © 2025 decompals */
/* SPDX-License-Identifier: MIT */

use std::borrow::Cow;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down
8 changes: 4 additions & 4 deletions slinky/src/partial_linker_writer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* SPDX-FileCopyrightText: © 2024 decompals */
/* SPDX-FileCopyrightText: © 2025 decompals */
/* SPDX-License-Identifier: MIT */

use crate::{
Expand Down Expand Up @@ -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)]))?;
Expand Down Expand Up @@ -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
}
}
10 changes: 9 additions & 1 deletion slinky/src/segment.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* SPDX-FileCopyrightText: © 2024 decompals */
/* SPDX-FileCopyrightText: © 2025 decompals */
/* SPDX-License-Identifier: MIT */

use std::{borrow::Cow, collections::HashMap, path::PathBuf};
Expand Down Expand Up @@ -50,6 +50,7 @@ pub struct Segment {
// The default value of the following members come from Settings
pub alloc_sections: Vec<String>,
pub noload_sections: Vec<String>,
pub emit_noload_segment: bool,

pub subalign: Option<u32>,
pub segment_start_align: Option<u32>,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -159,6 +161,8 @@ pub(crate) struct SegmentSerial {
pub alloc_sections: AbsentNullable<Vec<String>>,
#[serde(default)]
pub noload_sections: AbsentNullable<Vec<String>>,
#[serde(default)]
pub emit_noload_segment: AbsentNullable<bool>,

#[serde(default)]
pub subalign: AbsentNullable<u32>,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down
15 changes: 14 additions & 1 deletion slinky/src/settings.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* SPDX-FileCopyrightText: © 2024 decompals */
/* SPDX-FileCopyrightText: © 2025 decompals */
/* SPDX-License-Identifier: MIT */

use serde::Deserialize;
Expand Down Expand Up @@ -36,6 +36,7 @@ pub struct Settings {
// Options passed down to each segment
pub alloc_sections: Vec<String>,
pub noload_sections: Vec<String>,
pub emit_noload_segment: bool,

pub subalign: Option<u32>,
pub segment_start_align: Option<u32>,
Expand Down Expand Up @@ -138,6 +139,10 @@ fn settings_default_noload_sections() -> Vec<String> {
]
}

const fn settings_default_emit_noload_segment() -> bool {
true
}

const fn settings_default_subalign() -> Option<u32> {
None
}
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -321,6 +327,8 @@ pub(crate) struct SettingsSerial {
pub alloc_sections: AbsentNullable<Vec<String>>,
#[serde(default)]
pub noload_sections: AbsentNullable<Vec<String>>,
#[serde(default)]
pub emit_noload_segment: AbsentNullable<bool>,

#[serde(default)]
pub subalign: AbsentNullable<u32>,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -488,6 +499,8 @@ impl SettingsSerial {

alloc_sections,
noload_sections,
emit_noload_segment,

subalign,
segment_start_align,
segment_end_align,
Expand Down
Loading