summaryrefslogtreecommitdiff
path: root/lib/interception
diff options
context:
space:
mode:
authorEtienne Bergeron <etienneb@google.com>2016-09-28 18:04:07 +0000
committerEtienne Bergeron <etienneb@google.com>2016-09-28 18:04:07 +0000
commite398a5c93266e5fbcdbbc0772cc3f701eb26c58c (patch)
tree0adc94649e8d0fd6fa0592689a766f189ee9bda1 /lib/interception
parent0b95585616bd28fc0b738289bcc5f7887d7c304e (diff)
[compiler-rt] Fix interception of multiple defined symbols.
Summary: The MSVC compiler is generating multiple instance of the exception handler when compiling on win64 with /MD. see: https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx Two tests were failing when running: ``` ninja check-asan-dynamic. ``` The tests were failing because only the first occurence of the function was patched. The function `__C_specific_handler` is defined in `ntdll` and `vcruntime140`. After this patch, there is still two remaining tests failing. ``` ******************** Testing: 0 .. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. Testing Time: 87.81s ******************** Failing Tests (2): AddressSanitizer-x86_64-windows-dynamic :: TestCases/Windows/dll_intercept_memchr.cc AddressSanitizer-x86_64-windows-dynamic :: TestCases/Windows/dll_intercept_memcpy_indirect.cc Expected Passes : 342 Passes With Retry : 2 Expected Failures : 16 Unsupported Tests : 152 Unexpected Failures: 2 ``` Reviewers: rnk, vitalybuka Subscribers: vitalybuka, llvm-commits, chrisha, dberris Differential Revision: https://reviews.llvm.org/D24983 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@282614 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/interception')
-rw-r--r--lib/interception/interception_win.cc23
1 files changed, 11 insertions, 12 deletions
diff --git a/lib/interception/interception_win.cc b/lib/interception/interception_win.cc
index c8d67b976..a967706e1 100644
--- a/lib/interception/interception_win.cc
+++ b/lib/interception/interception_win.cc
@@ -915,19 +915,18 @@ uptr InternalGetProcAddress(void *module, const char *func_name) {
return 0;
}
-static bool GetFunctionAddressInDLLs(const char *func_name, uptr *func_addr) {
- *func_addr = 0;
+bool OverrideFunction(
+ const char *func_name, uptr new_func, uptr *orig_old_func) {
+ bool hooked = false;
void **DLLs = InterestingDLLsAvailable();
- for (size_t i = 0; *func_addr == 0 && DLLs[i]; ++i)
- *func_addr = InternalGetProcAddress(DLLs[i], func_name);
- return (*func_addr != 0);
-}
-
-bool OverrideFunction(const char *name, uptr new_func, uptr *orig_old_func) {
- uptr orig_func;
- if (!GetFunctionAddressInDLLs(name, &orig_func))
- return false;
- return OverrideFunction(orig_func, new_func, orig_old_func);
+ for (size_t i = 0; DLLs[i]; ++i) {
+ uptr func_addr = InternalGetProcAddress(DLLs[i], func_name);
+ if (func_addr &&
+ OverrideFunction(func_addr, new_func, orig_old_func)) {
+ hooked = true;
+ }
+ }
+ return hooked;
}
bool OverrideImportedFunction(const char *module_to_patch,