Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ordering using .init_array.N #230

Open
maxwase opened this issue Aug 19, 2022 · 0 comments
Open

Ordering using .init_array.N #230

maxwase opened this issue Aug 19, 2022 · 0 comments

Comments

@maxwase
Copy link

maxwase commented Aug 19, 2022

It would be nice if user could override execution order without changing code location.

The following code will panic because DATA is not initialized yet

#[ctor]
static ACTUAL_DATA: u8 = *DATA;

#[ctor]
static DATA: u8 = 1;

fn main() {
    println!("{}", *ACTUAL_DATA);
}
fatal runtime error: failed to initiate panic, error 5
IOT instruction (core dumped)

If we swap two statics, it works normally.

My suggestion is to have ordering argument, so we can write

#[ctor(ordering = 2)]
static ACTUAL_DATA: u8 = *DATA;

#[ctor(ordering = 1)]
static DATA: u8 = 1;

And as a result generate something like this:

#[link_section = ".init_array.1"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant