Skip to content

Commit 42cdfbc

Browse files
committed
[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 llvm-svn: 282614
1 parent fea5c7a commit 42cdfbc

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

compiler-rt/lib/interception/interception_win.cc

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -915,19 +915,18 @@ uptr InternalGetProcAddress(void *module, const char *func_name) {
915915
return 0;
916916
}
917917

918-
static bool GetFunctionAddressInDLLs(const char *func_name, uptr *func_addr) {
919-
*func_addr = 0;
918+
bool OverrideFunction(
919+
const char *func_name, uptr new_func, uptr *orig_old_func) {
920+
bool hooked = false;
920921
void **DLLs = InterestingDLLsAvailable();
921-
for (size_t i = 0; *func_addr == 0 && DLLs[i]; ++i)
922-
*func_addr = InternalGetProcAddress(DLLs[i], func_name);
923-
return (*func_addr != 0);
924-
}
925-
926-
bool OverrideFunction(const char *name, uptr new_func, uptr *orig_old_func) {
927-
uptr orig_func;
928-
if (!GetFunctionAddressInDLLs(name, &orig_func))
929-
return false;
930-
return OverrideFunction(orig_func, new_func, orig_old_func);
922+
for (size_t i = 0; DLLs[i]; ++i) {
923+
uptr func_addr = InternalGetProcAddress(DLLs[i], func_name);
924+
if (func_addr &&
925+
OverrideFunction(func_addr, new_func, orig_old_func)) {
926+
hooked = true;
927+
}
928+
}
929+
return hooked;
931930
}
932931

933932
bool OverrideImportedFunction(const char *module_to_patch,

0 commit comments

Comments
 (0)