Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 21af0df

Browse files
Ayush1325antoyo
authored andcommitted
Use custom entry name in gcc
This is a continuation of 9f0a862 for gcc. Signed-off-by: Ayush Singh <[email protected]>
1 parent bf4e1e4 commit 21af0df

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/context.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,9 @@ impl<'gcc, 'tcx> MiscMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
440440
}
441441

442442
fn declare_c_main(&self, fn_type: Self::Type) -> Option<Self::Function> {
443-
if self.get_declared_value("main").is_none() {
444-
Some(self.declare_cfn("main", fn_type))
443+
let entry_name = self.sess().target.entry_name.as_ref();
444+
if self.get_declared_value(entry_name).is_none() {
445+
Some(self.declare_entry_fn(entry_name, fn_type, ()))
445446
}
446447
else {
447448
// If the symbol already exists, it is an error: for example, the user wrote

src/declare.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
6363
global
6464
}
6565

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

0 commit comments

Comments
 (0)