Skip to content

Commit 20ff362

Browse files
authored
Rollup merge of #104001 - Ayush1325:custom-entry, r=bjorn3
Improve generating Custom entry function This commit is aimed at making compiler-generated entry functions (Basically just C `main` right now) more generic so other targets can do similar things for custom entry. This was initially implemented as part of rust-lang/rust#100316. Currently, this moves the entry function name and Call convention to the target spec. Signed-off-by: Ayush Singh <[email protected]>
2 parents ee50714 + 695c76c commit 20ff362

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/context.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,9 @@ impl<'gcc, 'tcx> MiscMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
425425
}
426426

427427
fn declare_c_main(&self, fn_type: Self::Type) -> Option<Self::Function> {
428-
if self.get_declared_value("main").is_none() {
429-
Some(self.declare_cfn("main", fn_type))
428+
let entry_name = self.sess().target.entry_name.as_ref();
429+
if self.get_declared_value(entry_name).is_none() {
430+
Some(self.declare_entry_fn(entry_name, fn_type, ()))
430431
}
431432
else {
432433
// If the symbol already exists, it is an error: for example, the user wrote

src/declare.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
6565
global
6666
}
6767

68-
pub fn declare_cfn(&self, name: &str, _fn_type: Type<'gcc>) -> RValue<'gcc> {
68+
pub fn declare_entry_fn(&self, name: &str, _fn_type: Type<'gcc>, callconv: () /*llvm::CCallConv*/) -> RValue<'gcc> {
6969
// TODO(antoyo): use the fn_type parameter.
7070
let const_string = self.context.new_type::<u8>().make_pointer().make_pointer();
7171
let return_type = self.type_i32();
7272
let variadic = false;
7373
self.linkage.set(FunctionType::Exported);
74-
let func = declare_raw_fn(self, name, () /*llvm::CCallConv*/, return_type, &[self.type_i32(), const_string], variadic);
74+
let func = declare_raw_fn(self, name, callconv, return_type, &[self.type_i32(), const_string], variadic);
7575
// NOTE: it is needed to set the current_func here as well, because get_fn() is not called
7676
// for the main function.
7777
*self.current_func.borrow_mut() = Some(func);

0 commit comments

Comments
 (0)