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: [PATCH] Fix unsafe function attributes for special functions (PR 71876)


On 07/20/16 13:53, Richard Biener wrote:
> On Wed, 20 Jul 2016, Bernd Edlinger wrote:
>
>> On 07/20/16 12:46, Richard Biener wrote:
>>> On Wed, 20 Jul 2016, Richard Biener wrote:
>>>
>>>> On Tue, 19 Jul 2016, Bernd Edlinger wrote:
>>>>
>>>>> Hi!
>>>>>
>>>>> As discussed at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71876,
>>>>> we have a _very_ old hack in gcc, that recognizes certain functions by
>>>>> name, and inserts in some cases unsafe attributes, that don't work for
>>>>> a freestanding environment.
>>>>>
>>>>> It is unsafe to return ECF_MAY_BE_ALLOCA, ECF_LEAF and ECF_NORETURN
>>>>> from special_function_p, just by the name of the function, especially
>>>>> for less well known functions, like "getcontext" or "savectx", which
>>>>> could easily used for something completely different.
>>>>
>>>> Returning ECF_MAY_BE_ALLOCA is safe.  Just wanted to mention this,
>>>> regardless of the followups you already received.
>>>
>>> Oh, and maybe you can factor out the less controversical parts,
>>> namely ignoring the __builtin_ prefix.  I don't think that
>>> calling __builtin_setjmp in an environment where setjmp is not a
>>> builtin should beave like setjmp (it will call a function named
>>> '__builtin_setjmp').
>>
>>
>> I wonder how I manage to dig out such contriversical things ;)
>>
>> But you are right, that would at least be a start.
>>
>> So this patch is what you requested:
>>
>> Remove the handling of the __builtin_ prefix from special_function_p
>> and add the returns_twice attribute to the __builtin_setjmp declaration
>> instead.
>>
>> Is it OK after boot-strap and regression-testing?
>
> I think the __builtin_setjmp change is wrong - __builtin_setjmp is
> _not_ 'setjmp' it is part of the GCC internal machinery (using setjmp
> and longjmp in the end) for SJLJ exception handing.
>

I do think that part is correct.

DEF_GCC_BUILTIN  adds the __builtin_ prefix, but does not overload the
standard setjmp function.

/* A GCC builtin (like __builtin_saveregs) is provided by the
    compiler, but does not correspond to a function in the standard
    library.  */
#undef DEF_GCC_BUILTIN
#define DEF_GCC_BUILTIN(ENUM, NAME, TYPE, ATTRS)                \
   DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, BT_LAST, \
                false, false, false, ATTRS, true, true)

And to define a builtin without __builtin_, there is a DEF_SYNC_BUILTIN
macro.  And DEF_LIB_BUILTIN defines both ways.

However, there is no simple way to define setjmp and __builtin_setjmp
to different builtin functions.


Thanks
Bernd.


> Am I correct Eric?
>
> Thanks,
> Richard.
>
>>
>> Thanks
>> Bernd.
>>
>


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