Skip to content

Commit ec92c3e

Browse files
committed
Fix ICE on incompatible declarations of entry symbol
Fixes rust-lang#1313
1 parent b5ac64b commit ec92c3e

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/main_shim.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,13 @@ pub(crate) fn maybe_create_entry_wrapper(
7070
};
7171

7272
let entry_name = tcx.sess.target.options.entry_name.as_ref();
73-
let cmain_func_id = m.declare_function(entry_name, Linkage::Export, &cmain_sig).unwrap();
73+
let cmain_func_id = match m.declare_function(entry_name, Linkage::Export, &cmain_sig) {
74+
Ok(func_id) => func_id,
75+
Err(err) => {
76+
tcx.sess
77+
.fatal(&format!("entry symbol `{entry_name}` declared multiple times: {err}"));
78+
}
79+
};
7480

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

@@ -162,7 +168,11 @@ pub(crate) fn maybe_create_entry_wrapper(
162168
bcx.seal_all_blocks();
163169
bcx.finalize();
164170
}
165-
m.define_function(cmain_func_id, &mut ctx).unwrap();
171+
172+
if let Err(err) = m.define_function(cmain_func_id, &mut ctx) {
173+
tcx.sess.fatal(&format!("entry symbol `{entry_name}` defined multiple times: {err}"));
174+
}
175+
166176
unwind_context.add_function(cmain_func_id, &ctx, m.isa());
167177
}
168178
}

0 commit comments

Comments
 (0)