Skip to content

C++ global object initialization order reversed #6870

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

Closed
earlephilhower opened this issue Dec 2, 2019 · 3 comments
Closed

C++ global object initialization order reversed #6870

earlephilhower opened this issue Dec 2, 2019 · 3 comments

Comments

@earlephilhower
Copy link
Collaborator

@mikee47 and @slaff noted in the Sming repo that the core is calling the c++ ctors in reverse order:
SmingHub/Sming#1825 (comment)

static void do_global_ctors(void) {
static struct object ob;
__register_frame_info( __eh_frame, &ob );
void (**p)(void) = &__init_array_end;
while (p != &__init_array_start)
(*--p)();
}

I believe w/in a single file/TU, they should be called in the order in which they appear. So calling them backwards may break something if there are inter-object dependencies in global objects.

@igrr
Copy link
Member

igrr commented Dec 2, 2019

#2074 had a link to MCVE, not sure if it still is an issue with recent GCC.

@mikee47
Copy link

mikee47 commented Dec 2, 2019

I've added the test case from #2074 and yes, it's still reversed. Thank you.

@earlephilhower
Copy link
Collaborator Author

Closing as the reverse order is still required.

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

3 participants