Page 1 of 1

Accuracy of "Calling Global Constructors"

Posted: Mon Sep 21, 2020 7:42 pm
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...

Re: Accuracy of "Calling Global Constructors"

Posted: Mon Sep 21, 2020 9:39 pm
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.

Re: Accuracy of "Calling Global Constructors"

Posted: Tue Sep 22, 2020 4:41 am
by zhiayang
hmm, okay. i must've been doing something wrong then.