[ASan] Deduplicate interception-in-shared-lib-test.cc by introducing platform-specific substitutions for rpath linker flags

Also make suppressions-library.cc use the same flags to avoid warnings about unused -rpath flags.
The same substitutions will be used to make coverage tests work on both Linux and Darwin without duplicating the code.

llvm-svn: 233802
This commit is contained in:
Alexander Potapenko 2015-04-01 12:13:03 +00:00
parent c063c47cc2
commit 8db9e77ba7
4 changed files with 17 additions and 43 deletions

View File

@ -1,32 +0,0 @@
// Check that memset() call from a shared library gets intercepted.
// Please always keep this file in sync with
// ../Linux/interception-in-shared-lib-test.cc.
// RUN: %clangxx_asan -O0 %s -DSHARED_LIB \
// RUN: -shared -o %t-so.so \
// RUN: -fPIC -install_name @rpath/interception-in-shared-lib-test.cc.tmp-so.so
// TODO(glider): figure out how to set rpath in a more portable way and unite
// this test with ../Linux/interception-in-shared-lib-test.cc.
// RUN: %clangxx_asan -O0 %s -o %t -Wl,-rpath,@executable_path %t-so.so && \
// RUN: not %run %t 2>&1 | FileCheck %s
#include <stdio.h>
#include <string.h>
#if defined(SHARED_LIB)
extern "C"
void my_memset(void *p, size_t sz) {
memset(p, 0, sz);
}
#else
extern "C" void my_memset(void *p, size_t sz);
int main(int argc, char *argv[]) {
char buf[10];
my_memset(buf, 11);
// CHECK: {{.*ERROR: AddressSanitizer: stack-buffer-overflow}}
// CHECK: {{WRITE of size 11 at 0x.* thread T0}}
// CHECK: {{0x.* in my_memset .*interception-in-shared-lib-test.cc:19}}
return 0;
}
#endif

View File

@ -1,13 +1,8 @@
// Check that memset() call from a shared library gets intercepted.
// Please always keep this file in sync with
// ../Darwin/interception-in-shared-lib-test.cc.
// RUN: %clangxx_asan -O0 %s -DSHARED_LIB \
// RUN: -shared -o %T/libinterception-in-shared-lib-test.so \
// RUN: -fPIC
// TODO(glider): figure out how to set rpath in a more portable way and unite
// this test with ../Darwin/interception-in-shared-lib-test.cc.
// RUN: %clangxx_asan -O0 %s -o %t -Wl,-R,\$ORIGIN -L%T -linterception-in-shared-lib-test && \
// RUN: -shared -o %dynamiclib -fPIC %ld_flags_rpath_so
// RUN: %clangxx_asan -O0 %s -o %t %ld_flags_rpath_exe && \
// RUN: not %run %t 2>&1 | FileCheck %s
#include <stdio.h>
@ -26,7 +21,7 @@ int main(int argc, char *argv[]) {
my_memset(buf, 11);
// CHECK: {{.*ERROR: AddressSanitizer: stack-buffer-overflow}}
// CHECK: {{WRITE of size 11 at 0x.* thread T0}}
// CHECK: {{0x.* in my_memset .*interception-in-shared-lib-test.cc:19}}
// CHECK: {{0x.* in my_memset .*interception-in-shared-lib-test.cc:}}[[@LINE-10]]
return 0;
}
#endif

View File

@ -1,10 +1,10 @@
// RUN: %clangxx_asan -O0 -DSHARED_LIB %s -fPIC -shared -o %t-so.so -install_name @rpath/suppressions-library.cc.tmp-so.so
// RUN: %clangxx_asan -O0 %s %t-so.so -o %t -rpath @executable_path
// RUN: %clangxx_asan -O0 -DSHARED_LIB %s -fPIC -shared -o %dynamiclib %ld_flags_rpath_so
// RUN: %clangxx_asan -O0 %s -o %t %ld_flags_rpath_exe
// Check that without suppressions, we catch the issue.
// RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s
// RUN: echo "interceptor_via_lib:suppressions-library.cc.tmp-so.so" > %t.supp
// RUN: echo "interceptor_via_lib:"`basename %dynamiclib` > %t.supp
// RUN: ASAN_OPTIONS="suppressions='%t.supp'" %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
// XFAIL: android

View File

@ -135,6 +135,17 @@ config.substitutions.append( ("%libdl", libdl_flag) )
config.available_features.add("asan-" + config.bits + "-bits")
if config.host_os == 'Darwin':
config.substitutions.append( ("%ld_flags_rpath_exe", '-Wl,-rpath,@executable_path/ %dynamiclib') )
config.substitutions.append( ("%ld_flags_rpath_so", '-install_name @rpath/`basename %dynamiclib`') )
elif config.host_os == 'Linux':
config.substitutions.append( ("%ld_flags_rpath_exe", "-Wl,-rpath,\$ORIGIN -L%T -l%xdynamiclib_namespec") )
config.substitutions.append( ("%ld_flags_rpath_so", '') )
# Must be defined after the substitutions that use %dynamiclib.
config.substitutions.append( ("%dynamiclib", '%T/lib%xdynamiclib_namespec.so') )
config.substitutions.append( ("%xdynamiclib_namespec", '$(basename %t).dynamic') )
# Allow tests to use REQUIRES=stable-runtime. For use when you cannot use XFAIL
# because the test hangs.
if config.target_arch != 'arm':