Skip to content
Open
Changes from all commits
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
24 changes: 22 additions & 2 deletions crates/synth-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ enum Commands {
/// Path to kiln-builtins object file (.o) for linking (used with --link)
#[arg(long, value_name = "BUILTINS")]
builtins: Option<PathBuf>,

/// Force relocatable object (.o, ET_REL) output even when wasm has no imports
/// — for linking into a host build system.
#[arg(long)]
relocatable: bool,
},

/// Disassemble an ARM ELF file (e.g., synth disasm output.elf)
Expand Down Expand Up @@ -248,6 +253,7 @@ fn main() -> Result<()> {
verify,
link,
builtins,
relocatable,
} => {
// Resolve target spec: --target overrides, --cortex-m is backwards compat
let target_spec = resolve_target_spec(target.as_deref(), cortex_m)?;
Expand All @@ -272,6 +278,7 @@ fn main() -> Result<()> {
&backend,
verify,
&target_spec,
relocatable,
)?;

// If --link requested, invoke the cross-linker
Expand Down Expand Up @@ -553,6 +560,7 @@ fn compile_command(
backend_name: &str,
verify: bool,
target_spec: &TargetSpec,
relocatable: bool,
) -> Result<()> {
// Validate backend exists
let registry = build_backend_registry();
Expand Down Expand Up @@ -595,6 +603,7 @@ fn compile_command(
backend,
verify,
target_spec,
relocatable,
);
}

Expand Down Expand Up @@ -1222,6 +1231,7 @@ fn compile_all_exports(
backend: &dyn Backend,
verify: bool,
target_spec: &TargetSpec,
relocatable: bool,
) -> Result<()> {
let path = input.context("--all-exports requires an input file")?;

Expand Down Expand Up @@ -1428,8 +1438,18 @@ fn compile_all_exports(
// When there are relocations, produce a relocatable object (.o) instead of
// an executable. This lets the output be linked with the Kiln bridge crate
// (which provides __meld_dispatch_import and __meld_get_memory_base).
let elf_data = if has_relocations {
info!("Module has import calls — producing relocatable object (ET_REL)");
// The --relocatable flag forces ET_REL output even when the wasm has no
// imports, for linking into a host build system (e.g. Zephyr).
let elf_data = if has_relocations || relocatable {
let total_relocs: usize = compiled_funcs.iter().map(|f| f.relocations.len()).sum();
if has_relocations {
info!(
"Producing relocatable object (ET_REL): {} import call relocations",
total_relocs
);
} else {
info!("Producing relocatable object (ET_REL): forced by --relocatable");
}
build_relocatable_elf(&compiled_funcs, &all_imports)?
} else if cortex_m {
build_multi_func_cortex_m_elf(&compiled_funcs, &all_memories, target_spec)?
Expand Down
Loading