From: Bastien Roucariès Date: Sat, 23 Jan 2021 13:31:44 +0000 (+0100) Subject: explicit_bzero: Add fallback for other compilers. X-Git-Tag: v1.0~3129 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=cd1b752fa6c5e0aa677f44843ebbe896c10d58ca;p=gnulib.git explicit_bzero: Add fallback for other compilers. * lib/explicit_bzero.c (explicit_bzero): For other compilers, invoke memset through a volatile function pointer. --- 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 }