Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 4 Jun 2017 23:08:42 -0500
From:      Pedro Giffuni <pfg@FreeBSD.org>
To:        Eric van Gyzen <vangyzen@FreeBSD.org>
Cc:        FreeBSD Hackers <freebsd-hackers@freebsd.org>
Subject:   Re: Function attribute for optimization level
Message-ID:  <ec177111-2dae-f1c3-034f-df9f65c30da2@FreeBSD.org>

next in thread | raw e-mail | index | archive | help
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.




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?ec177111-2dae-f1c3-034f-df9f65c30da2>