This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [4.7][google]Support for getting CPU type and feature information at run-time. (issue4893046)


Is there a standard way to force this init function to be called
before all ctors?  Adding a ctor in one crtx.o ?

David

On Fri, Aug 26, 2011 at 10:45 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Fri, Aug 26, 2011 at 10:37 AM, Sriraman Tallam <tmsriram@google.com> wrote:
>> On Fri, Aug 26, 2011 at 10:24 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>> On Fri, Aug 26, 2011 at 10:17 AM, Sriraman Tallam <tmsriram@google.com> wrote:
>>>> On Fri, Aug 26, 2011 at 10:10 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>>> On Fri, Aug 26, 2011 at 10:06 AM, Sriraman Tallam <tmsriram@google.com> wrote:
>>>>>> On Thu, Aug 25, 2011 at 6:02 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>>>>> On Thu, Aug 25, 2011 at 5:37 PM, Sriraman Tallam <tmsriram@google.com> wrote:
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> ?Thanks for all the comments. I am attaching a new patch
>>>>>>>> incorporating all of the changes mentioned, mainly :
>>>>>>>>
>>>>>>>> 1) Make __cpu_indicator_init a constructor in libgcc and guard to call
>>>>>>>> it only once.
>>>>>>>
>>>>>>> This is unreliable and you don't need 3 symbols from libgcc. You can use
>>>>>>
>>>>>> Do you mean it is unreliable because of the constructor ordering problem?
>>>>>>
>>>>>
>>>>> You do not have total control when __cpu_indicator_init is called.
>>>>
>>>> Like ?discussed before, for non-ctor functions, which in my opinion is
>>>> the common use case, it works out great because __cpu_indicator_init
>>>> is guaranteed to be called and I save doing an extra check. It is only
>>>>> for other ctors where this is a problem. So other ctors call this
>>>> explicitly. ?What did I miss?
>>>>
>>>
>>> I have
>>>
>>> static void foo ( void ) __attribute__((constructor));
>>>
>>> static void foo ( void )
>>> {
>>> ? ...
>>> ? call bar ();
>>> ? ...
>>> }
>>>
>>> in my application. bar () uses those cpu specific functions.
>>> foo () is called before __cpu_indicator_init. ?Since IFUNC
>>> returns the cpu specific function address only for the
>>> first call, the proper cpu specific functions will never be used.
>>
>> Please correct me if I am wrong since I did not follow the IFUNC part
>> you mentioned. ?However, it looks like this could be solved with
>> adding an explicit call to __cpu_indicator_init from within the ctor
>> foo. To me, it seems like the pain of adding this call explicitly in
>> other ctors is worth it because it works cleanly for non-ctors.
>>
>> static void foo ( void ) __attribute__((constructor));
>>
>> static void foo ( void )
>> {
>> ?...
>> ?__cpu_indicator_init ();
>> ?call bar ();
>> ?...
>> }
>>
>> Will this work?
>>
>>
>
> Do I have to do that in every constructor, including
> C++ global constructors? ?It is ridiculous.
>
> --
> H.J.
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]