This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: when will __attribute__((constructor)) NOT called
- From: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>
- To: Szabolcs Nagy <szabolcs dot nagy at arm dot com>, libc-help at sourceware dot org
- Cc: nd at arm dot com
- Date: Wed, 6 Sep 2017 10:20:04 -0300
- Subject: Re: when will __attribute__((constructor)) NOT called
- Authentication-results: sourceware.org; auth=none
- References: <CAJYFCiNBRzwzuNcaFjuswT+PCx61bygwa=Q9+jtShG3nzNu1uw@mail.gmail.com> <c77ecd79-ad5b-29d3-e073-865291757bd0@linaro.org> <59AFF20C.4030101@arm.com>
On 06/09/2017 10:03, Szabolcs Nagy wrote:
> On 06/09/17 13:46, Adhemerval Zanella wrote:
>> '.ctor' section was the 'old' way, afaik GCC will now create and emit
>> entries on 'init_array' section, as for C++ initialization code.
>>
>> It won't run either by a bug on the loader or if it does not support
>> it (not the case on glibc).
>>
>
> or if an earlier ctor does not return (e.g. _exit).
>
> or if the dso is already loaded, then a new dlopen wont make the ctor run again.
You can still trigger constructors in this case with dlmopen (LM_ID_NEWLM, ...)
>
>> On 06/09/2017 07:37, Yubin Ruan wrote:
>>> I saw somewhere that "__attribute__((constructor)) will make GCC
>>> create a '.ctor' section in the generated .so file, which is run when
>>> a shared library is loaded, typically at program startup".
>>>
>>> A question:
>>> Are there any case where "__attribute__((constructor))" will not be run?
>>>
>>> Thanks,
>>> Yubin
>>>
>