summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2017-11-10 22:09:37 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2017-11-10 22:09:37 +0000
commit55dee3e7a884bf78e0f8932ff7eaac6f614866fa (patch)
tree33edd0726c17688d572fed22cd2bfabd4076743f /lib
parent206e78aa8cafe99214e591d19a8c4a7254f1a2ed (diff)
sanitizer_common: Try looking up symbols with RTLD_DEFAULT if RTLD_NEXT does not work.
If the lookup using RTLD_NEXT failed, the sanitizer runtime library is later in the library search order than the DSO that we are trying to intercept, which means that we cannot intercept this function. We still want the address of the real definition, though, so look it up using RTLD_DEFAULT. Differential Revision: https://reviews.llvm.org/D39779 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317930 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/interception/interception_linux.cc8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/interception/interception_linux.cc b/lib/interception/interception_linux.cc
index 23780429d..5299c42d6 100644
--- a/lib/interception/interception_linux.cc
+++ b/lib/interception/interception_linux.cc
@@ -29,6 +29,14 @@ bool GetRealFunctionAddress(const char *func_name, uptr *func_addr,
if (internal_strcmp(func_name, "sigaction") == 0) func_name = "__sigaction14";
#endif
*func_addr = (uptr)dlsym(RTLD_NEXT, func_name);
+ if (!*func_addr) {
+ // If the lookup using RTLD_NEXT failed, the sanitizer runtime library is
+ // later in the library search order than the DSO that we are trying to
+ // intercept, which means that we cannot intercept this function. We still
+ // want the address of the real definition, though, so look it up using
+ // RTLD_DEFAULT.
+ *func_addr = (uptr)dlsym(RTLD_DEFAULT, func_name);
+ }
return real == wrapper;
}