From cd1b752fa6c5e0aa677f44843ebbe896c10d58ca Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bastien=20Roucari=C3=A8s?= Date: Sat, 23 Jan 2021 14:31:44 +0100 Subject: [PATCH] explicit_bzero: Add fallback for other compilers. * lib/explicit_bzero.c (explicit_bzero): For other compilers, invoke memset through a volatile function pointer. --- ChangeLog | 4 ++++ lib/explicit_bzero.c | 12 ++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index e7101e1bf1..b1b81353e6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2021-01-23 Bastien Roucariès + explicit_bzero: Add fallback for other compilers. + * lib/explicit_bzero.c (explicit_bzero): For other compilers, invoke + memset through a volatile function pointer. + explicit_bzero: Add support for clang. * lib/explicit_bzero.c (explicit_bzero): Add a compiler barrier for clang. diff --git a/lib/explicit_bzero.c b/lib/explicit_bzero.c index 4eb057462b..2906c04d0f 100644 --- a/lib/explicit_bzero.c +++ b/lib/explicit_bzero.c @@ -54,17 +54,21 @@ explicit_bzero (void *s, size_t len) explicit_memset (s, '\0', len); #elif HAVE_MEMSET_S (void) memset_s (s, len, '\0', len); -#else +#elif defined __GNUC__ && !defined __clang__ memset (s, '\0', len); -# if defined __GNUC__ && !defined __clang__ /* Compiler barrier. */ asm volatile ("" ::: "memory"); -# elif defined __clang__ +#elif defined __clang__ + memset (s, '\0', len); /* Compiler barrier. */ /* With asm ("" ::: "memory") LLVM analyzes uses of 's' and finds that the whole thing is dead and eliminates it. Use 'g' to work around this problem. See . */ __asm__ volatile ("" : : "g"(s) : "memory"); -# endif +#else + /* Invoke memset through a volatile function pointer. This defeats compiler + optimizations. */ + void * (* const volatile volatile_memset) (void *, int, size_t) = memset; + (void) volatile_memset (s, '\0', len); #endif } -- 2.39.5