How to verify init_priorty for C++ static object initialization order?

Jeffrey Walton noloader@gmail.com
Sun Sep 13 10:29:00 GMT 2015


On Sun, Sep 13, 2015 at 6:08 AM, Alan Modra <amodra@gmail.com> wrote:
> On Sun, Sep 13, 2015 at 04:11:25AM -0400, Jeffrey Walton wrote:
>> I have an object file and an archive. How can I verify the priority is
>> embedded in both the object file and archive?
>
> The priority is encoded in section names, so use readelf -S or
> objdump -h to display the section headers.
>
> For this:
> #include <stdio.h>
>
> class A
> {
> public:
>   A() {
>     printf ("A\n");
>   }
> public:
>   ~A() {
>     printf ("~A\n");
>   }
> };
>
> A a __attribute__ ((init_priority (1000)));
>
> You'll see sections like .init_array.01000 for reasonably recent gcc.
>
Perfect, thanks.

I think I stumbles across it with either -i or -s (but was not sure
because it was names init_array rather than init_priority).

Thanks again.



More information about the Binutils mailing list