linking with __CTOR_LIST__

Ravishankar S
Tue Sep 12 14:28:00 GMT 2006


It may be possible to do this with the linker. The constructors are
allocatted to the .ctors section in the final ELF file.

Just add this in your linker script:


__CTOR_LIST__ = ADDR(.ctors)

Caveat: I have not tried this !


-----Original Message-----
From: [] On
Behalf Of Abby
Sent: Tuesday, September 12, 2006 3:48 PM
Subject: Re: linking with __CTOR_LIST__

Hi Grig,

thanks for reply. there must be some way to walk and call those
pointers? want to do something like as follows on linux appllication. 

To use gcov for a application which runs all the time, i wanted to
change the behavior.

This is the code extract from

extern long __CTOR_LIST__;
typedef void (*func_ptr)(void) ;
func_ptr *p = (func_ptr*) &__CTOR_LIST__;

if ( p == NULL) {
printk("No CTORS\n");
for ( ; *p != (func_ptr) 0; p++) {
(*p) ();

I wanted to do similar stuff for the application.
Any other idea or right alias (if it is not the one).

thanks and regards,

Grigory Zagorodnev wrote:
> Abby wrote:
>> i am writing an application (linux) where i am trying to reference 
>> __CTOR_LIST__ ?
>> /tmp/cc2rTvyB.o(.data+0x0): undefined reference to `__CTOR_LIST__'
>> any idea?
>> abby.
> __CTOR_LIST__ is a local symbol, it can't be referenced from outside
> crtbegin*.o startup object file.
> - Grigory

View this message in context:
Sent from the gcc - Help forum at

__________ NOD32 1.1454 (20060321) Information __________

This message was checked by NOD32 antivirus system.

More information about the Gcc-help mailing list