[PATCH] D43669: [cfi] Lazy CFI initialization
Vitaly Buka via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 23 23:01:16 PST 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL326025: [cfi] Lazy initialization of CFI interceptors (authored by vitalybuka, committed by ).
Herald added a subscriber: delcypher.
Changed prior to commit:
https://reviews.llvm.org/D43669?vs=135763&id=135786#toc
Repository:
rL LLVM
https://reviews.llvm.org/D43669
Files:
compiler-rt/trunk/lib/cfi/cfi.cc
Index: compiler-rt/trunk/lib/cfi/cfi.cc
===================================================================
--- compiler-rt/trunk/lib/cfi/cfi.cc
+++ compiler-rt/trunk/lib/cfi/cfi.cc
@@ -379,6 +379,8 @@
}
#endif
+static void EnsureInterceptorsInitialized();
+
// Setup shadow for dlopen()ed libraries.
// The actual shadow setup happens after dlopen() returns, which means that
// a library can not be a target of any CFI checks while its constructors are
@@ -388,19 +390,35 @@
// We could insert a high-priority constructor into the library, but that would
// not help with the uninstrumented libraries.
INTERCEPTOR(void*, dlopen, const char *filename, int flag) {
+ EnsureInterceptorsInitialized();
EnterLoader();
void *handle = REAL(dlopen)(filename, flag);
ExitLoader();
return handle;
}
INTERCEPTOR(int, dlclose, void *handle) {
+ EnsureInterceptorsInitialized();
EnterLoader();
int res = REAL(dlclose)(handle);
ExitLoader();
return res;
}
+static BlockingMutex interceptor_init_lock(LINKER_INITIALIZED);
+static bool interceptors_inited = false;
+
+static void EnsureInterceptorsInitialized() {
+ BlockingMutexLock lock(&interceptor_init_lock);
+ if (interceptors_inited)
+ return;
+
+ INTERCEPT_FUNCTION(dlopen);
+ INTERCEPT_FUNCTION(dlclose);
+
+ interceptors_inited = true;
+}
+
extern "C" SANITIZER_INTERFACE_ATTRIBUTE
#if !SANITIZER_CAN_USE_PREINIT_ARRAY
// On ELF platforms, the constructor is invoked using .preinit_array (see below)
@@ -411,9 +429,6 @@
InitializeFlags();
InitShadow();
- INTERCEPT_FUNCTION(dlopen);
- INTERCEPT_FUNCTION(dlclose);
-
#ifdef CFI_ENABLE_DIAG
__ubsan::InitAsPlugin();
#endif
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43669.135786.patch
Type: text/x-patch
Size: 1686 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180224/0f49cd7d/attachment.bin>
More information about the llvm-commits
mailing list