From 41d6b75aa999cf7d49be9bb030919a72d5a4ec7d Mon Sep 17 00:00:00 2001 From: Kostya Kortchinsky Date: Mon, 27 Nov 2017 21:34:43 +0000 Subject: [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 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319099 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/scudo/scudo_utils.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/scudo/scudo_utils.cpp b/lib/scudo/scudo_utils.cpp index 75be2fc73..2f936bf9e 100644 --- a/lib/scudo/scudo_utils.cpp +++ b/lib/scudo/scudo_utils.cpp @@ -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(); } -- cgit v1.2.3