[PATCH] D40504: [scudo] Workaround for uninitialized Bionic globals
Kostya Kortchinsky via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 27 09:32:51 PST 2017
cryptoad created this revision.
Herald added a subscriber: srhines.
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.
https://reviews.llvm.org/D40504
Files:
lib/scudo/scudo_utils.cpp
Index: lib/scudo/scudo_utils.cpp
===================================================================
--- lib/scudo/scudo_utils.cpp
+++ lib/scudo/scudo_utils.cpp
@@ -96,8 +96,18 @@
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();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40504.124405.patch
Type: text/x-patch
Size: 954 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171127/b90e2121/attachment.bin>
More information about the llvm-commits
mailing list