Skip to content

Commit

Permalink
Fix ICE on incompatible declarations of entry symbol
Browse files Browse the repository at this point in the history
Fixes #1313
  • Loading branch information
bjorn3 committed Dec 16, 2022
1 parent b5ac64b commit 1f7be90
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/main_shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ pub(crate) fn maybe_create_entry_wrapper(
};

let entry_name = tcx.sess.target.options.entry_name.as_ref();
let cmain_func_id = m.declare_function(entry_name, Linkage::Export, &cmain_sig).unwrap();
let cmain_func_id = match m.declare_function(entry_name, Linkage::Export, &cmain_sig) {
Ok(func_id) => func_id,
Err(err) => {
tcx.sess.fatal(&format!("entry symbol `{entry_name}` declared multiple times: {err}"));
}
};

let instance = Instance::mono(tcx, rust_main_def_id).polymorphize(tcx);

Expand Down Expand Up @@ -162,7 +167,11 @@ pub(crate) fn maybe_create_entry_wrapper(
bcx.seal_all_blocks();
bcx.finalize();
}
m.define_function(cmain_func_id, &mut ctx).unwrap();

if let Err(err) = m.define_function(cmain_func_id, &mut ctx) {
tcx.sess.fatal(&format!("entry symbol `{entry_name}` defined multiple times: {err}"));
}

unwind_context.add_function(cmain_func_id, &ctx, m.isa());
}
}

0 comments on commit 1f7be90

Please sign in to comment.