diff options
author | Dean Michael Berris <dberris@google.com> | 2017-11-29 22:06:12 +0000 |
---|---|---|
committer | Dean Michael Berris <dberris@google.com> | 2017-11-29 22:06:12 +0000 |
commit | 1e639b28dc8d4379c397e14fdf5e9268975f8d65 (patch) | |
tree | 9877d5ffc5d9da308402a285ae91b0949460aa1f /lib/xray/xray_init.cc | |
parent | 82ff537a07bdee654821abb4a2b7212de54301f4 (diff) |
[XRay][compiler-rt][Darwin] Use dynamic initialisation as an alternative
Summary:
In cases where we can't use the .preinit_array section (as in Darwin for
example) we instead use dynamic initialisation. We know that this
alternative approach will race with the initializers of other objects at
global scope, but this is strictly better than nothing.
Reviewers: kubamracek, nglevin
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D40599
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319366 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/xray/xray_init.cc')
-rw-r--r-- | lib/xray/xray_init.cc | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/xray/xray_init.cc b/lib/xray/xray_init.cc index 864e77944..11892cb8b 100644 --- a/lib/xray/xray_init.cc +++ b/lib/xray/xray_init.cc @@ -88,8 +88,15 @@ void __xray_init() XRAY_NEVER_INSTRUMENT { #endif } -// Only add the preinit array initialization if the sanitizers can. #if !defined(XRAY_NO_PREINIT) && SANITIZER_CAN_USE_PREINIT_ARRAY +// Only add the preinit array initialization if the sanitizers can. __attribute__((section(".preinit_array"), used)) void (*__local_xray_preinit)(void) = __xray_init; +#else +// If we cannot use the .preinit_array section, we should instead use dynamic +// initialisation. +static bool UNUSED __local_xray_dyninit = [] { + __xray_init(); + return true; +}(); #endif |