From e1c80655b7470e62e03d4160448837dfcf4c27e1 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Sun, 19 May 2024 22:28:14 -0600 Subject: [PATCH] Fix lcf generation for empty RELs Also, handle alignment of 0 in rel make --- src/util/lcf.rs | 8 +++++++- src/util/rel.rs | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/util/lcf.rs b/src/util/lcf.rs index b61c6f2..00c18f5 100644 --- a/src/util/lcf.rs +++ b/src/util/lcf.rs @@ -64,7 +64,7 @@ pub fn generate_ldscript_partial( template: Option<&str>, force_active: &[String], ) -> Result { - let section_defs = obj + let mut section_defs = obj .sections .iter() .map(|(_, s)| { @@ -73,6 +73,12 @@ pub fn generate_ldscript_partial( }) .join("\n "); + // Some RELs have no entry point (`.text` was stripped) so mwld requires at least an empty + // `.init` section to be present in the linker script, for some reason. + if obj.entry.is_none() { + section_defs = format!(".init :{{}}\n {}", section_defs); + } + let mut force_files = Vec::with_capacity(obj.link_order.len()); for unit in &obj.link_order { let obj_path = obj_path_for_unit(&unit.name); diff --git a/src/util/rel.rs b/src/util/rel.rs index 09ff650..cfe4501 100644 --- a/src/util/rel.rs +++ b/src/util/rel.rs @@ -774,6 +774,7 @@ where .and_then(|v| v.get(permitted_section_idx)) .cloned() .unwrap_or(section.align() as u32) + .max(1) } let mut align = file