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

Alexander Potapenko glider at google.com
Wed Apr 1 05:13:04 PDT 2015


Author: glider
Date: Wed Apr  1 07:13:03 2015
New Revision: 233802

URL: http://llvm.org/viewvc/llvm-project?rev=233802&view=rev
Log:
[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.

Added:
    compiler-rt/trunk/test/asan/TestCases/Posix/interception-in-shared-lib-test.cc
      - copied, changed from r233794, compiler-rt/trunk/test/asan/TestCases/Darwin/interception-in-shared-lib-test.cc
Removed:
    compiler-rt/trunk/test/asan/TestCases/Darwin/interception-in-shared-lib-test.cc
    compiler-rt/trunk/test/asan/TestCases/Linux/interception-in-shared-lib-test.cc
Modified:
    compiler-rt/trunk/test/asan/TestCases/suppressions-library.cc
    compiler-rt/trunk/test/asan/lit.cfg

Removed: compiler-rt/trunk/test/asan/TestCases/Darwin/interception-in-shared-lib-test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Darwin/interception-in-shared-lib-test.cc?rev=233801&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Darwin/interception-in-shared-lib-test.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/Darwin/interception-in-shared-lib-test.cc (removed)
@@ -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, at 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

Removed: compiler-rt/trunk/test/asan/TestCases/Linux/interception-in-shared-lib-test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Linux/interception-in-shared-lib-test.cc?rev=233801&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Linux/interception-in-shared-lib-test.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/Linux/interception-in-shared-lib-test.cc (removed)
@@ -1,32 +0,0 @@
-// 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:     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

Copied: compiler-rt/trunk/test/asan/TestCases/Posix/interception-in-shared-lib-test.cc (from r233794, compiler-rt/trunk/test/asan/TestCases/Darwin/interception-in-shared-lib-test.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Posix/interception-in-shared-lib-test.cc?p2=compiler-rt/trunk/test/asan/TestCases/Posix/interception-in-shared-lib-test.cc&p1=compiler-rt/trunk/test/asan/TestCases/Darwin/interception-in-shared-lib-test.cc&r1=233794&r2=233802&rev=233802&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Darwin/interception-in-shared-lib-test.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/Posix/interception-in-shared-lib-test.cc Wed Apr  1 07:13:03 2015
@@ -1,13 +1,8 @@
 // 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, at executable_path %t-so.so && \
+// 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

Modified: compiler-rt/trunk/test/asan/TestCases/suppressions-library.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/suppressions-library.cc?rev=233802&r1=233801&r2=233802&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/suppressions-library.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/suppressions-library.cc Wed Apr  1 07:13:03 2015
@@ -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

Modified: compiler-rt/trunk/test/asan/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/lit.cfg?rev=233802&r1=233801&r2=233802&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/lit.cfg (original)
+++ compiler-rt/trunk/test/asan/lit.cfg Wed Apr  1 07:13:03 2015
@@ -135,6 +135,17 @@ config.substitutions.append( ("%libdl",
 
 config.available_features.add("asan-" + config.bits + "-bits")
 
+if config.host_os == 'Darwin':
+  config.substitutions.append( ("%ld_flags_rpath_exe", '-Wl,-rpath, at 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':





More information about the llvm-commits mailing list