init_priority ... would this work?
Kean Johnston
jkj@sco.com
Sun Apr 13 14:46:00 GMT 2003
Hi,
I am having trouble getting constructors to work correctly
on OSR5, but I think this problem has broader scope. It seems,
from the code I have read so far, as if init_priority really
only works if you have the GNU link editor, and that's because
it helpfully sorts the ctors sections for you. If someone wants
to help me get GNU ld working on OSR5 that would be great too,
but I think there has to be an easier and more portable way to
do this.
As I understand things, global contructors are emitted into a
.ctors section. If they have a priority, then the section is
.ctors.priority. GNU ld then coalesces these into a sorted
list, such that the lowest priority is executed first. That
seems pretty cool, but how about this. Instead of emitting
just a function pointer into the __CTOR_LIST__, how about
emitting a {ptr,priority} pair. Then, __do_global_ctors_aux
could sort that list based on priority before it calls any
of the functions. This would work for targets (such as OSR5)
where you cannot rely on link editor help, yet still give you
the same functionality.
I guess the alternate approach is to use collect2, but that
has a whole different set of problems, not least of which it
asumes that if you have ELF you don't need any of its funky
sorting stuff for just this purpose. Actually the problem is
with libgcc2 as well, which assumes if you have ELF you don't
need __main, which collect2 requires. It's a bit of a mess
and I will try clean it up soon if I can't figure out some
other way of solving this constructors problem.
Kean
More information about the Gcc
mailing list