Function attribute for optimization level

Pedro Giffuni pfg at FreeBSD.org
Mon Jun 5 17:02:38 UTC 2017



On 04/06/2017 23:08, Pedro Giffuni wrote:
>
> Hi Eric;
>
> It is a good idea : the nonopt attribute is useful in parts of the 
> boot loader and probably in security-related functions.
>
>
>> diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h
>> index 9cdc03c861cb..e370f6d6459e 100644
>> --- a/sys/sys/cdefs.h
>> +++ b/sys/sys/cdefs.h
>> @@ -396,6 +396,14 @@
>>   #define        __unreachable() ((void)0)
>>   #endif
>>
>> +#if __has_attribute(optnone)
>> +#define        __no_optimization       __attribute__((optnone))
>> +#elif __has_attribute(optimize)
>> +#define        __no_optimization       __attribute__((optimize(0)))
>> +#else
>> +#define        __no_optimization
>> +#endif
>
> I think the second one is wrong though: 'optimize' doesn't appear to 
> be a valid clang attribute. GCC uses an optimize("O0") pragma, but it 
> is not an attribute and __has_attribute doesn't work for GCC anyways.
>

Bah, I found it in the GCC 4.4 Release Notes.

Fopr GCC you have to check __GNUC_PREREQ__(4, 4) instead __has_attribute().

Cheers,

Pedro.



More information about the freebsd-hackers mailing list