[compiler-rt] r319099 - [scudo] Workaround for uninitialized Bionic globals

Kostya Kortchinsky via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 27 13:34:43 PST 2017


Author: cryptoad
Date: Mon Nov 27 13:34:43 2017
New Revision: 319099

URL: http://llvm.org/viewvc/llvm-project?rev=319099&view=rev
Log:
[scudo] Workaround for uninitialized Bionic globals

Summary:
Bionic doesn't initialize its globals early enough. This causes issues when
trying to access them from a preinit_array (b/25751302) or from another
constructor called before the libc one (b/68046352). __progname is initialized
after the other globals, so we can check its value to know if calling
`getauxval` is safe.

Reviewers: alekseyshl

Reviewed By: alekseyshl

Subscribers: srhines, llvm-commits

Differential Revision: https://reviews.llvm.org/D40504

Modified:
    compiler-rt/trunk/lib/scudo/scudo_utils.cpp

Modified: compiler-rt/trunk/lib/scudo/scudo_utils.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/scudo_utils.cpp?rev=319099&r1=319098&r2=319099&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/scudo_utils.cpp (original)
+++ compiler-rt/trunk/lib/scudo/scudo_utils.cpp Mon Nov 27 13:34:43 2017
@@ -96,8 +96,18 @@ bool hasHardwareCRC32ARMPosix() {
 bool hasHardwareCRC32ARMPosix() { return false; }
 # endif  // SANITIZER_POSIX
 
+// Bionic doesn't initialize its globals early enough. This causes issues when
+// trying to access them from a preinit_array (b/25751302) or from another
+// constructor called before the libc one (b/68046352). __progname is
+// initialized after the other globals, so we can check its value to know if
+// calling getauxval is safe.
+extern "C" SANITIZER_WEAK_ATTRIBUTE char *__progname;
+INLINE bool areBionicGlobalsInitialized() {
+  return !SANITIZER_ANDROID || (&__progname && __progname);
+}
+
 bool hasHardwareCRC32() {
-  if (&getauxval)
+  if (&getauxval && areBionicGlobalsInitialized())
     return !!(getauxval(AT_HWCAP) & HWCAP_CRC32);
   return hasHardwareCRC32ARMPosix();
 }




More information about the llvm-commits mailing list