Skip to content
This repository was archived by the owner on Jan 24, 2022. It is now read-only.
This repository was archived by the owner on Jan 24, 2022. It is now read-only.

main() calling convention discrepancy #277

@mciantyre

Description

@mciantyre

The documentation notes that main()'s signature is expected to be extern "C" fn () -> !. The docs say that users could define main() by using the #[entry] macro on a function, or by manually defining a function with that name and calling convention.

cortex-m-rt/src/lib.rs

Lines 256 to 257 in ef6c6e6

//! The unmangled `main` symbol must have signature `extern "C" fn() -> !` or its invocation from
//! `Reset` will result in undefined behavior.

The documentation conforms with the #[entry] macro implementation, which creates a symbol main() as using C calling conventions:

quote!(
#(#cfgs)*
#(#attrs)*
#[doc(hidden)]
#[export_name = "main"]
pub unsafe extern "C" fn #tramp_ident() {
#ident(
#(#resource_args),*
)
}
#f
)

However, in Reset(), we qualify main() as using Rust calling conventions:

cortex-m-rt/src/lib.rs

Lines 902 to 908 in ef6c6e6

extern "Rust" {
// This symbol will be provided by the user via `#[entry]`
fn main() -> !;
// This symbol will be provided by the user via `#[pre_init]`
fn __pre_init();
}

Should we qualify main() as extern "C" in Reset()?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions