Re: Make GCC initialize global variables generating instructions in crti.S _init

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

 



On Mon, Jan 6, 2020 at 11:52 AM Florian Weimer <fw@xxxxxxxxxxxxx> wrote:
>
> * William Tambe:
>
> > I would like for GCC to automatically generate instructions to
> > initialize global variables without having to manually create a
> > function with attribute((constructor)) to initialize those global
> > variables. In the example below from my previous email, GCC should
> > automatically generate instructions to initialize myglobal just like
> > it generates instructions to initialize mylocal; except those
> > instructions to initialize myglobal are to be generated within the
> > crti.S _init function:
> >
> >     void myfunc (void) {}
> >     void *myglobal = myfunc;
> >     void main (void) {
> >             void *mylocal = myfunc;
> >     }
>
> I believe this would be best implemented in the link editor.  It sees
> the relocations and can generate the appropriate code.  However, for

Assembly generated to initialize myglobal is as follow:

            .globl  myglobal
            .section        .data.rel.local,"aw",@progbits
            .align 8
            .type   myglobal, @object
            .size   myglobal, 8
    myglobal:
            .quad   myfunc

Is it actually possible to create a link editor script that convert
the above assembly into instructions in the function _init ?

> position-indepedent code, usually a table-based approach with a
> minimal loader is typically used.

Could I have a pointer into the source code showing how it is implemented ?



[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