* [PATCH 1/3] compiler-gcc.h: Introduce __optimize function attribute
@ 2018-02-01 10:21 Geert Uytterhoeven
2018-02-01 10:21 ` [PATCH 2/3] compiler-gcc.h: __nostackprotector needs gcc-4.4 and up Geert Uytterhoeven
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Geert Uytterhoeven @ 2018-02-01 10:21 UTC (permalink / raw)
To: Herbert Xu, David S . Miller, Christopher Li, Ard Biesheuvel,
Tom Lendacky
Cc: Arnd Bergmann, Andrew Morton, linux-crypto, linux-sparse,
linux-kernel, Geert Uytterhoeven
Create a new function attribute __optimize, which allows to specify an
optimization level on a per-function basis.
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
I assume this is supported as of gcc-4.4:
- gcc version 4.3.3 (GCC): warning: ‘__optimize__’ attribute directive
ignored
- gcc version 4.4.7 (Ubuntu/Linaro 4.4.7-1ubuntu2): OK
---
include/linux/compiler-gcc.h | 4 ++++
include/linux/compiler.h | 4 ++++
2 files changed, 8 insertions(+)
diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index 631354acfa720475..0a278a527944ad2f 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -196,6 +196,10 @@
#endif /* __CHECKER__ */
#endif /* GCC_VERSION >= 40300 */
+#if GCC_VERSION >= 40400
+#define __optimize(level) __attribute__((__optimize__(level)))
+#endif /* GCC_VERSION >= 40400 */
+
#if GCC_VERSION >= 40500
#ifndef __CHECKER__
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 52e611ab9a6cf6fd..5ff818e9a836e898 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -271,6 +271,10 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
#endif /* __ASSEMBLY__ */
+#ifndef __optimize
+# define __optimize(level)
+#endif
+
/* Compile time object size, -1 for unknown */
#ifndef __compiletime_object_size
# define __compiletime_object_size(obj) -1
--
2.7.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/3] compiler-gcc.h: __nostackprotector needs gcc-4.4 and up
2018-02-01 10:21 [PATCH 1/3] compiler-gcc.h: Introduce __optimize function attribute Geert Uytterhoeven
@ 2018-02-01 10:21 ` Geert Uytterhoeven
2018-02-01 11:46 ` Arnd Bergmann
2018-02-01 10:22 ` [PATCH 3/3] crypto: sha3-generic - Use __optimize to support old compilers Geert Uytterhoeven
2018-02-01 17:30 ` [PATCH 1/3] compiler-gcc.h: Introduce __optimize function attribute Ard Biesheuvel
2 siblings, 1 reply; 8+ messages in thread
From: Geert Uytterhoeven @ 2018-02-01 10:21 UTC (permalink / raw)
To: Herbert Xu, David S . Miller, Christopher Li, Ard Biesheuvel,
Tom Lendacky
Cc: Arnd Bergmann, Andrew Morton, linux-crypto, linux-sparse,
linux-kernel, Geert Uytterhoeven
Gcc versions before 4.4 do not recognize the __optimize__ compiler
attribute:
warning: ‘__optimize__’ attribute directive ignored
Fixes: 7375ae3a0b79ea07 ("compiler-gcc.h: Introduce __nostackprotector function attribute")
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
Can anyone please verify this?
Apparently __nostackprotector is used on x86 only, which is usually
served by modern compilers.
---
include/linux/compiler-gcc.h | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index 0a278a527944ad2f..73bc63e0a1c4b664 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -167,8 +167,6 @@
#if GCC_VERSION >= 40100
# define __compiletime_object_size(obj) __builtin_object_size(obj, 0)
-
-#define __nostackprotector __attribute__((__optimize__("no-stack-protector")))
#endif
#if GCC_VERSION >= 40300
@@ -198,6 +196,7 @@
#if GCC_VERSION >= 40400
#define __optimize(level) __attribute__((__optimize__(level)))
+#define __nostackprotector __optimize("no-stack-protector")
#endif /* GCC_VERSION >= 40400 */
#if GCC_VERSION >= 40500
--
2.7.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 2/3] compiler-gcc.h: __nostackprotector needs gcc-4.4 and up
2018-02-01 10:21 ` [PATCH 2/3] compiler-gcc.h: __nostackprotector needs gcc-4.4 and up Geert Uytterhoeven
@ 2018-02-01 11:46 ` Arnd Bergmann
2018-02-01 11:55 ` Geert Uytterhoeven
0 siblings, 1 reply; 8+ messages in thread
From: Arnd Bergmann @ 2018-02-01 11:46 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Herbert Xu, David S . Miller, Christopher Li, Ard Biesheuvel,
Tom Lendacky, Andrew Morton,
open list:HARDWARE RANDOM NUMBER GENERATOR CORE, linux-sparse,
Linux Kernel Mailing List
On Thu, Feb 1, 2018 at 11:21 AM, Geert Uytterhoeven
<geert@linux-m68k.org> wrote:
> Gcc versions before 4.4 do not recognize the __optimize__ compiler
> attribute:
>
> warning: ‘__optimize__’ attribute directive ignored
>
> Fixes: 7375ae3a0b79ea07 ("compiler-gcc.h: Introduce __nostackprotector function attribute")
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
> ---
> Can anyone please verify this?
> Apparently __nostackprotector is used on x86 only, which is usually
> served by modern compilers.
I've checked that __optimize("no-stack-protector") is accepted by exactly those
compilers that your 40400 version check tests for, across all architectures, so
that's fine.
However, looking at commit 91cfc88c66bf ("x86: Use __nostackprotect for
sme_encrypt_kernel"), I suspect that gcc-4.1 through 4.3 will now cause
a runtime failure in sme_encrypt_kernel() without a compile-time warning.
I would leave __nostackprotector unchanged here, so we at least get
a warning for functions that need to disable the stack protector to work
correctly.
We might want to add an #ifdef CONFIG_CC_STACKPROTECTOR around
the __nostackprotector definition, so that we only warn if stackprotector
is globally enabled.
Arnd
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/3] compiler-gcc.h: __nostackprotector needs gcc-4.4 and up
2018-02-01 11:46 ` Arnd Bergmann
@ 2018-02-01 11:55 ` Geert Uytterhoeven
2018-02-01 15:29 ` Arnd Bergmann
0 siblings, 1 reply; 8+ messages in thread
From: Geert Uytterhoeven @ 2018-02-01 11:55 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Herbert Xu, David S . Miller, Christopher Li, Ard Biesheuvel,
Tom Lendacky, Andrew Morton,
open list:HARDWARE RANDOM NUMBER GENERATOR CORE, linux-sparse,
Linux Kernel Mailing List
Hi Arnd,
On Thu, Feb 1, 2018 at 12:46 PM, Arnd Bergmann <arnd@arndb.de> wrote:
> On Thu, Feb 1, 2018 at 11:21 AM, Geert Uytterhoeven
> <geert@linux-m68k.org> wrote:
>> Gcc versions before 4.4 do not recognize the __optimize__ compiler
>> attribute:
>>
>> warning: ‘__optimize__’ attribute directive ignored
>>
>> Fixes: 7375ae3a0b79ea07 ("compiler-gcc.h: Introduce __nostackprotector function attribute")
>> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
>> ---
>> Can anyone please verify this?
>> Apparently __nostackprotector is used on x86 only, which is usually
>> served by modern compilers.
>
> I've checked that __optimize("no-stack-protector") is accepted by exactly those
> compilers that your 40400 version check tests for, across all architectures, so
> that's fine.
Thanks!
> However, looking at commit 91cfc88c66bf ("x86: Use __nostackprotect for
> sme_encrypt_kernel"), I suspect that gcc-4.1 through 4.3 will now cause
> a runtime failure in sme_encrypt_kernel() without a compile-time warning.
So having this functionality is a hard requirement. Oops...
> I would leave __nostackprotector unchanged here, so we at least get
> a warning for functions that need to disable the stack protector to work
> correctly.
Agreed.
> We might want to add an #ifdef CONFIG_CC_STACKPROTECTOR around
> the __nostackprotector definition, so that we only warn if stackprotector
> is globally enabled.
And we might want to remove the dummy in include/linux/compiler_types.h:
#ifndef __nostackprotector
# define __nostackprotector
#endif
BTW, how does this work with non-gcc compilers?
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/3] compiler-gcc.h: __nostackprotector needs gcc-4.4 and up
2018-02-01 11:55 ` Geert Uytterhoeven
@ 2018-02-01 15:29 ` Arnd Bergmann
0 siblings, 0 replies; 8+ messages in thread
From: Arnd Bergmann @ 2018-02-01 15:29 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Herbert Xu, David S . Miller, Christopher Li, Ard Biesheuvel,
Tom Lendacky, Andrew Morton,
open list:HARDWARE RANDOM NUMBER GENERATOR CORE, linux-sparse,
Linux Kernel Mailing List
On Thu, Feb 1, 2018 at 12:55 PM, Geert Uytterhoeven
<geert@linux-m68k.org> wrote:
> Hi Arnd,
>
> On Thu, Feb 1, 2018 at 12:46 PM, Arnd Bergmann <arnd@arndb.de> wrote:
>> On Thu, Feb 1, 2018 at 11:21 AM, Geert Uytterhoeven
>> <geert@linux-m68k.org> wrote:
>>> Gcc versions before 4.4 do not recognize the __optimize__ compiler
>>> attribute:
>
> And we might want to remove the dummy in include/linux/compiler_types.h:
>
> #ifndef __nostackprotector
> # define __nostackprotector
> #endif
>
> BTW, how does this work with non-gcc compilers?
clang should in theory accept the same flags, and it pretends to be an older
version of gcc.
I don't think anyone cares about ICC or any other compiler.
Arnd
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 3/3] crypto: sha3-generic - Use __optimize to support old compilers
2018-02-01 10:21 [PATCH 1/3] compiler-gcc.h: Introduce __optimize function attribute Geert Uytterhoeven
2018-02-01 10:21 ` [PATCH 2/3] compiler-gcc.h: __nostackprotector needs gcc-4.4 and up Geert Uytterhoeven
@ 2018-02-01 10:22 ` Geert Uytterhoeven
2018-02-01 17:30 ` Ard Biesheuvel
2018-02-01 17:30 ` [PATCH 1/3] compiler-gcc.h: Introduce __optimize function attribute Ard Biesheuvel
2 siblings, 1 reply; 8+ messages in thread
From: Geert Uytterhoeven @ 2018-02-01 10:22 UTC (permalink / raw)
To: Herbert Xu, David S . Miller, Christopher Li, Ard Biesheuvel,
Tom Lendacky
Cc: Arnd Bergmann, Andrew Morton, linux-crypto, linux-sparse,
linux-kernel, Geert Uytterhoeven
With gcc-4.1.2:
crypto/sha3_generic.c:39: warning: ‘__optimize__’ attribute directive ignored
Use the newly introduced __optimize macro to fix this.
Fixes: 83dee2ce1ae791c3 ("crypto: sha3-generic - rewrite KECCAK transform to help the compiler optimize")
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
crypto/sha3_generic.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/crypto/sha3_generic.c b/crypto/sha3_generic.c
index a965b9d8055983af..c409cd87fea5decd 100644
--- a/crypto/sha3_generic.c
+++ b/crypto/sha3_generic.c
@@ -35,7 +35,7 @@ static const u64 keccakf_rndc[24] = {
/* update the state with given number of rounds */
-static void __attribute__((__optimize__("O3"))) keccakf(u64 st[25])
+static void __optimize("O3") keccakf(u64 st[25])
{
u64 t[5], tt, bc[5];
int round;
--
2.7.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 3/3] crypto: sha3-generic - Use __optimize to support old compilers
2018-02-01 10:22 ` [PATCH 3/3] crypto: sha3-generic - Use __optimize to support old compilers Geert Uytterhoeven
@ 2018-02-01 17:30 ` Ard Biesheuvel
0 siblings, 0 replies; 8+ messages in thread
From: Ard Biesheuvel @ 2018-02-01 17:30 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Herbert Xu, David S . Miller, Christopher Li, Tom Lendacky,
Arnd Bergmann, Andrew Morton,
open list:HARDWARE RANDOM NUMBER GENERATOR CORE, Linux-Sparse,
Linux Kernel Mailing List
On 1 February 2018 at 10:22, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> With gcc-4.1.2:
>
> crypto/sha3_generic.c:39: warning: ‘__optimize__’ attribute directive ignored
>
> Use the newly introduced __optimize macro to fix this.
>
> Fixes: 83dee2ce1ae791c3 ("crypto: sha3-generic - rewrite KECCAK transform to help the compiler optimize")
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
> crypto/sha3_generic.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/crypto/sha3_generic.c b/crypto/sha3_generic.c
> index a965b9d8055983af..c409cd87fea5decd 100644
> --- a/crypto/sha3_generic.c
> +++ b/crypto/sha3_generic.c
> @@ -35,7 +35,7 @@ static const u64 keccakf_rndc[24] = {
>
> /* update the state with given number of rounds */
>
> -static void __attribute__((__optimize__("O3"))) keccakf(u64 st[25])
> +static void __optimize("O3") keccakf(u64 st[25])
> {
> u64 t[5], tt, bc[5];
> int round;
> --
> 2.7.4
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3] compiler-gcc.h: Introduce __optimize function attribute
2018-02-01 10:21 [PATCH 1/3] compiler-gcc.h: Introduce __optimize function attribute Geert Uytterhoeven
2018-02-01 10:21 ` [PATCH 2/3] compiler-gcc.h: __nostackprotector needs gcc-4.4 and up Geert Uytterhoeven
2018-02-01 10:22 ` [PATCH 3/3] crypto: sha3-generic - Use __optimize to support old compilers Geert Uytterhoeven
@ 2018-02-01 17:30 ` Ard Biesheuvel
2 siblings, 0 replies; 8+ messages in thread
From: Ard Biesheuvel @ 2018-02-01 17:30 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Herbert Xu, David S . Miller, Christopher Li, Tom Lendacky,
Arnd Bergmann, Andrew Morton,
open list:HARDWARE RANDOM NUMBER GENERATOR CORE, Linux-Sparse,
Linux Kernel Mailing List
On 1 February 2018 at 10:21, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> Create a new function attribute __optimize, which allows to specify an
> optimization level on a per-function basis.
>
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
> I assume this is supported as of gcc-4.4:
> - gcc version 4.3.3 (GCC): warning: ‘__optimize__’ attribute directive
> ignored
> - gcc version 4.4.7 (Ubuntu/Linaro 4.4.7-1ubuntu2): OK
> ---
> include/linux/compiler-gcc.h | 4 ++++
> include/linux/compiler.h | 4 ++++
> 2 files changed, 8 insertions(+)
>
> diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
> index 631354acfa720475..0a278a527944ad2f 100644
> --- a/include/linux/compiler-gcc.h
> +++ b/include/linux/compiler-gcc.h
> @@ -196,6 +196,10 @@
> #endif /* __CHECKER__ */
> #endif /* GCC_VERSION >= 40300 */
>
> +#if GCC_VERSION >= 40400
> +#define __optimize(level) __attribute__((__optimize__(level)))
> +#endif /* GCC_VERSION >= 40400 */
> +
> #if GCC_VERSION >= 40500
>
> #ifndef __CHECKER__
> diff --git a/include/linux/compiler.h b/include/linux/compiler.h
> index 52e611ab9a6cf6fd..5ff818e9a836e898 100644
> --- a/include/linux/compiler.h
> +++ b/include/linux/compiler.h
> @@ -271,6 +271,10 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
>
> #endif /* __ASSEMBLY__ */
>
> +#ifndef __optimize
> +# define __optimize(level)
> +#endif
> +
> /* Compile time object size, -1 for unknown */
> #ifndef __compiletime_object_size
> # define __compiletime_object_size(obj) -1
> --
> 2.7.4
>
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2018-02-01 17:30 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-01 10:21 [PATCH 1/3] compiler-gcc.h: Introduce __optimize function attribute Geert Uytterhoeven
2018-02-01 10:21 ` [PATCH 2/3] compiler-gcc.h: __nostackprotector needs gcc-4.4 and up Geert Uytterhoeven
2018-02-01 11:46 ` Arnd Bergmann
2018-02-01 11:55 ` Geert Uytterhoeven
2018-02-01 15:29 ` Arnd Bergmann
2018-02-01 10:22 ` [PATCH 3/3] crypto: sha3-generic - Use __optimize to support old compilers Geert Uytterhoeven
2018-02-01 17:30 ` Ard Biesheuvel
2018-02-01 17:30 ` [PATCH 1/3] compiler-gcc.h: Introduce __optimize function attribute Ard Biesheuvel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).