Function attribute for optimization level
Pedro Giffuni
pfg at FreeBSD.org
Mon Jun 5 04:08:49 UTC 2017
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.
AFAICT there is no equivalent declaration in either Darwin or bionic:
the rest of the BSDs are still GCC-centric.
The location of the declaration is fine, although being a clang-only
attribute you could place it later in the header, perhaps just before
the nullability attributes.
Regards,
Pedro.
More information about the freebsd-hackers
mailing list