RE: linking with __CTOR_LIST__

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

It should work. I have seen several examples of this. Verify if the
symbol has the correct address, by checking the linker map file (check
linker documentation on how to do this : info ld, its probably --map). 

Regards,
Ravishankar


-----Original Message-----
From: gcc-help-owner@xxxxxxxxxxx [mailto:gcc-help-owner@xxxxxxxxxxx] On
Behalf Of Abby
Sent: Tuesday, September 12, 2006 10:21 PM
To: gcc-help@xxxxxxxxxxx
Subject: RE: linking with __CTOR_LIST__



Hi,

Thanks Ravi,
I am using default linker script. ld -verbose.
which already has folloing section..

  .ctors          :
  {
    /* gcc uses crtbegin.o to find the start of
       the constructors, so we make sure it is
       first.  Because this is a wildcard, it
       doesn't matter if the user does not
       actually link against crtbegin.o; the
       linker won't look for a file to match a
       wildcard.  The wildcard also means that it
       doesn't matter which directory crtbegin.o
       is in.  */
    KEEP (*crtbegin*.o(.ctors))
    /* We don't want to include the .ctor section from
       from the crtend.o file until after the sorted ctors.
       The .ctor section from the crtend file contains the
       end of ctors marker and it must be last */
    KEEP (*(EXCLUDE_FILE (*crtend*.o ) .ctors))
    KEEP (*(SORT(.ctors.*)))
    KEEP (*(.ctors))
  }

you mean i can just append following line to the above lines (sorry for
asking all from you guys - still learning).

__CTOR_LIST__ = ADDR(.ctors)


Regards,
Abby.


Ravishankar S-2 wrote:
> 
> Hi,
> 
> 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:
> 
> .ctors
> {
>   *(.ctors);
> }
> 
> __CTOR_LIST__ = ADDR(.ctors)
> 
> Caveat: I have not tried this !
> 
> Regards,
> Ravishankar
> 
> 
> 
> -----Original Message-----
> From: gcc-help-owner@xxxxxxxxxxx [mailto:gcc-help-owner@xxxxxxxxxxx] 
> On Behalf Of Abby
> Sent: Tuesday, September 12, 2006 3:48 PM
> To: gcc-help@xxxxxxxxxxx
> 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 
> http://lwn.net/2002/0207/a/gcov-kernel.php3
> 
> extern long __CTOR_LIST__;
> typedef void (*func_ptr)(void) ;
> func_ptr *p = (func_ptr*) &__CTOR_LIST__;
> 
> if ( p == NULL) {
> printk("No CTORS\n");
> return;
> }
> 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,
> abby.
> 
> 
> 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:
>
http://www.nabble.com/linking-with-__CTOR_LIST__-tf2253354.html#a6263258
> Sent from the gcc - Help forum at Nabble.com.
> 
> 
> __________ NOD32 1.1454 (20060321) Information __________
> 
> This message was checked by NOD32 antivirus system. 
> http://www.eset.com
> 
> 
> 
> 

-- 
View this message in context:
http://www.nabble.com/linking-with-__CTOR_LIST__-tf2253354.html#a6270096
Sent from the gcc - Help forum at Nabble.com.


__________ NOD32 1.1454 (20060321) Information __________

This message was checked by NOD32 antivirus system. http://www.eset.com



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux