Accuracy of "Calling Global Constructors"

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
zhiayang
Member
Member
Posts: 368
Joined: Tue Dec 27, 2011 7:57 am
Libera.chat IRC: zhiayang

Accuracy of "Calling Global Constructors"

Post by zhiayang »

I realised that the article "Calling Global Constructors" on the wiki directs us to use the .init and .fini section methods to call constructors -- particularly the "gcc will nicely put the contents of ..." implementation. Unfortunately, with my GCC 9.2 OS-spec compiler, it's not populating those sections as advertised. (they're there, but empty).

What I did find to work was the .init_array and .fini_array method that is supposedly only for ARM, but from what I could find online it's the "new" method of doing things. So my question is: are there existing kernels on a recent(-ish) version of GCC that have had success with the .init .fini method? Maybe i'm just doing things wrong...
nullplan
Member
Member
Posts: 1790
Joined: Wed Aug 30, 2017 8:24 am

Re: Accuracy of "Calling Global Constructors"

Post by nullplan »

No, everything is fine. The .init and .fini approach was extremely brittle, and precluded some linker options from being used (--sort-sections=alignment being the best known problematic one). So instead the newer .init_array and .fini_array mechanism is now used everywhere. .init and .fini are only there for legacy support.
Carpe diem!
User avatar
zhiayang
Member
Member
Posts: 368
Joined: Tue Dec 27, 2011 7:57 am
Libera.chat IRC: zhiayang

Re: Accuracy of "Calling Global Constructors"

Post by zhiayang »

hmm, okay. i must've been doing something wrong then.
Post Reply