From 957315035a5729ee089404fbdb2710fa78dca188 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Fri, 20 Jun 2014 21:09:18 -0700 Subject: [PATCH] Use weak symbols to prevent LTO if this is an option. Idea from Matthew Dempsky. --- configure.ac | 10 ++++++++++ src/libsodium/sodium/utils.c | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/configure.ac b/configure.ac index 6dd1346f..5bb01b87 100644 --- a/configure.ac +++ b/configure.ac @@ -375,6 +375,16 @@ __asm__ __volatile__ ("xchgl %%ebx, %k1; cpuid; xchgl %%ebx, %k1" : ]) AC_SUBST(HAVE_CPUID_V) +AC_MSG_CHECKING(if weak symbols are supported) +AC_LINK_IFELSE([AC_LANG_PROGRAM([[ +__attribute__((weak)) void __dummy(void *x) { } +void f(void *x) { __dummy(x); } +]], [[ ]] +)], +[AC_MSG_RESULT(yes) + AC_DEFINE([HAVE_WEAK_SYMBOLS], [1], [weak symbols are supported])], +[AC_MSG_RESULT(no)]) + AS_CASE([$host_cpu], [i*86 | x86_64 | powerpc* | s390*], [AC_MSG_NOTICE([data alignment is not required on this target])], diff --git a/src/libsodium/sodium/utils.c b/src/libsodium/sodium/utils.c index e60bcd80..fbccfbb5 100644 --- a/src/libsodium/sodium/utils.c +++ b/src/libsodium/sodium/utils.c @@ -19,6 +19,11 @@ # include #endif +#ifdef HAVE_WEAK_SYMBOLS +__attribute__((weak)) void +__sodium_dummy_symbol_to_prevent_lto(void * const pnt, const size_t len) { } +#endif + void sodium_memzero(void * const pnt, const size_t len) { @@ -30,6 +35,9 @@ sodium_memzero(void * const pnt, const size_t len) } #elif defined(HAVE_EXPLICIT_BZERO) explicit_bzero(pnt, len); +#elif HAVE_WEAK_SYMBOLS + memset(pnt, 0, len); + __sodium_dummy_symbol_to_prevent_lto(pnt, len); #else volatile unsigned char *pnt_ = (volatile unsigned char *) pnt; size_t i = (size_t) 0U;