[compiler-rt] r264013 - [asan] Intercept strdup on Windows
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 21 17:52:47 PDT 2016
Author: rnk
Date: Mon Mar 21 19:52:47 2016
New Revision: 264013
URL: http://llvm.org/viewvc/llvm-project?rev=264013&view=rev
Log:
[asan] Intercept strdup on Windows
Some unit tests were failing because we didn't intercept strdup. It
turns out it works just fine on 2013 and 2015 with a small patch to the
interception logic.
Modified:
compiler-rt/trunk/lib/asan/asan_interceptors.cc
compiler-rt/trunk/lib/asan/asan_interceptors.h
compiler-rt/trunk/lib/asan/asan_win_dll_thunk.cc
compiler-rt/trunk/lib/interception/interception_win.cc
compiler-rt/trunk/test/asan/TestCases/Windows/intercept_strdup.cc
Modified: compiler-rt/trunk/lib/asan/asan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_interceptors.cc?rev=264013&r1=264012&r2=264013&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_interceptors.cc Mon Mar 21 19:52:47 2016
@@ -544,7 +544,6 @@ INTERCEPTOR(char*, strcpy, char *to, con
return REAL(strcpy)(to, from); // NOLINT
}
-#if ASAN_INTERCEPT_STRDUP
INTERCEPTOR(char*, strdup, const char *s) {
void *ctx;
ASAN_INTERCEPTOR_ENTER(ctx, strdup);
@@ -559,7 +558,6 @@ INTERCEPTOR(char*, strdup, const char *s
REAL(memcpy)(new_mem, s, length + 1);
return reinterpret_cast<char*>(new_mem);
}
-#endif
INTERCEPTOR(SIZE_T, wcslen, const wchar_t *s) {
void *ctx;
@@ -729,9 +727,7 @@ void InitializeAsanInterceptors() {
ASAN_INTERCEPT_FUNC(wcslen);
ASAN_INTERCEPT_FUNC(strncat);
ASAN_INTERCEPT_FUNC(strncpy);
-#if ASAN_INTERCEPT_STRDUP
ASAN_INTERCEPT_FUNC(strdup);
-#endif
#if ASAN_INTERCEPT_STRNLEN
ASAN_INTERCEPT_FUNC(strnlen);
#endif
Modified: compiler-rt/trunk/lib/asan/asan_interceptors.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_interceptors.h?rev=264013&r1=264012&r2=264013&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_interceptors.h (original)
+++ compiler-rt/trunk/lib/asan/asan_interceptors.h Mon Mar 21 19:52:47 2016
@@ -23,14 +23,12 @@
#if !SANITIZER_WINDOWS
# define ASAN_INTERCEPT_ATOLL_AND_STRTOLL 1
# define ASAN_INTERCEPT__LONGJMP 1
-# define ASAN_INTERCEPT_STRDUP 1
# define ASAN_INTERCEPT_INDEX 1
# define ASAN_INTERCEPT_PTHREAD_CREATE 1
# define ASAN_INTERCEPT_FORK 1
#else
# define ASAN_INTERCEPT_ATOLL_AND_STRTOLL 0
# define ASAN_INTERCEPT__LONGJMP 0
-# define ASAN_INTERCEPT_STRDUP 0
# define ASAN_INTERCEPT_INDEX 0
# define ASAN_INTERCEPT_PTHREAD_CREATE 0
# define ASAN_INTERCEPT_FORK 0
Modified: compiler-rt/trunk/lib/asan/asan_win_dll_thunk.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_win_dll_thunk.cc?rev=264013&r1=264012&r2=264013&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_win_dll_thunk.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_win_dll_thunk.cc Mon Mar 21 19:52:47 2016
@@ -396,6 +396,7 @@ INTERCEPT_LIBRARY_FUNCTION(strchr);
INTERCEPT_LIBRARY_FUNCTION(strcmp);
INTERCEPT_LIBRARY_FUNCTION(strcpy); // NOLINT
INTERCEPT_LIBRARY_FUNCTION(strcspn);
+INTERCEPT_LIBRARY_FUNCTION(strdup);
INTERCEPT_LIBRARY_FUNCTION(strlen);
INTERCEPT_LIBRARY_FUNCTION(strncat);
INTERCEPT_LIBRARY_FUNCTION(strncmp);
Modified: compiler-rt/trunk/lib/interception/interception_win.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/interception/interception_win.cc?rev=264013&r1=264012&r2=264013&view=diff
==============================================================================
--- compiler-rt/trunk/lib/interception/interception_win.cc (original)
+++ compiler-rt/trunk/lib/interception/interception_win.cc Mon Mar 21 19:52:47 2016
@@ -108,6 +108,9 @@ static size_t RoundUpToInstrBoundary(siz
case 0x3D83: // 83 3D XX YY ZZ WW TT = cmp TT, WWZZYYXX
cursor += 7;
continue;
+ case 0x7D83: // 83 7D XX YY = cmp dword ptr [ebp+XXh], YY
+ cursor += 4;
+ continue;
}
switch (0x00FFFFFF & *(unsigned int*)(code + cursor)) {
case 0x24448A: // 8A 44 24 XX = mov eal, dword ptr [esp+XXh]
@@ -120,7 +123,7 @@ static size_t RoundUpToInstrBoundary(siz
continue;
}
switch (*(unsigned int *)(code + cursor)) {
- case 0X2444B60F: // 0F B6 44 24 XX = movzx eax, byte ptr [esp+XXh]
+ case 0x2444B60F: // 0F B6 44 24 XX = movzx eax, byte ptr [esp+XXh]
cursor += 5;
continue;
}
Modified: compiler-rt/trunk/test/asan/TestCases/Windows/intercept_strdup.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/intercept_strdup.cc?rev=264013&r1=264012&r2=264013&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/intercept_strdup.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/intercept_strdup.cc Mon Mar 21 19:52:47 2016
@@ -20,9 +20,7 @@ int main() {
// CHECK: {{#0 .* main .*}}intercept_strdup.cc:[[@LINE-3]]
// CHECK: [[ADDR]] is located 1 bytes to the left of 6-byte region
// CHECK: allocated by thread T0 here:
-// CHECK: {{#0 .* malloc }}
-// FIXME: llvm-symbolizer can't find strdup in the CRT.
-// CHECKX: {{#1 .*strdup}}
-// CHECK: {{#2 .* main .*}}intercept_strdup.cc:[[@LINE-17]]
+// CHECK: {{#0 .*strdup}}
+// CHECK: {{#1 .* main .*}}intercept_strdup.cc:[[@LINE-15]]
free(ptr);
}
More information about the llvm-commits
mailing list