Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: lib/curve25519 - work around Clang stack spilling issue

Arnd reports that the 32-bit generic library code for Curve25119 ends
up using an excessive amount of stack space when built with Clang:

lib/crypto/curve25519-fiat32.c:756:6: error: stack frame size
of 1384 bytes in function 'curve25519_generic'
[-Werror,-Wframe-larger-than=]

Let's give some hints to the compiler regarding which routines should
not be inlined, to prevent it from running out of registers and spilling
to the stack. The resulting code performs identically under both GCC
and Clang, and makes the warning go away.

Suggested-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Ard Biesheuvel and committed by
Herbert Xu
660bb8e1 ee772cb6

+5 -5
+5 -5
lib/crypto/curve25519-fiat32.c
··· 223 223 h->v[0] = 1; 224 224 } 225 225 226 - static void fe_add_impl(u32 out[10], const u32 in1[10], const u32 in2[10]) 226 + static noinline void fe_add_impl(u32 out[10], const u32 in1[10], const u32 in2[10]) 227 227 { 228 228 { const u32 x20 = in1[9]; 229 229 { const u32 x21 = in1[8]; ··· 266 266 fe_add_impl(h->v, f->v, g->v); 267 267 } 268 268 269 - static void fe_sub_impl(u32 out[10], const u32 in1[10], const u32 in2[10]) 269 + static noinline void fe_sub_impl(u32 out[10], const u32 in1[10], const u32 in2[10]) 270 270 { 271 271 { const u32 x20 = in1[9]; 272 272 { const u32 x21 = in1[8]; ··· 309 309 fe_sub_impl(h->v, f->v, g->v); 310 310 } 311 311 312 - static void fe_mul_impl(u32 out[10], const u32 in1[10], const u32 in2[10]) 312 + static noinline void fe_mul_impl(u32 out[10], const u32 in1[10], const u32 in2[10]) 313 313 { 314 314 { const u32 x20 = in1[9]; 315 315 { const u32 x21 = in1[8]; ··· 441 441 fe_mul_impl(h->v, f->v, g->v); 442 442 } 443 443 444 - static void fe_sqr_impl(u32 out[10], const u32 in1[10]) 444 + static noinline void fe_sqr_impl(u32 out[10], const u32 in1[10]) 445 445 { 446 446 { const u32 x17 = in1[9]; 447 447 { const u32 x18 = in1[8]; ··· 619 619 * 620 620 * Preconditions: b in {0,1} 621 621 */ 622 - static __always_inline void fe_cswap(fe *f, fe *g, unsigned int b) 622 + static noinline void fe_cswap(fe *f, fe *g, unsigned int b) 623 623 { 624 624 unsigned i; 625 625 b = 0 - b;