[llvm] r277778 - [LIT][Darwin] Preload libclang_rt.asan_osx_dynamic.dylib when necessary

Bruno Cardoso Lopes via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 4 15:01:38 PDT 2016


Author: bruno
Date: Thu Aug  4 17:01:38 2016
New Revision: 277778

URL: http://llvm.org/viewvc/llvm-project?rev=277778&view=rev
Log:
[LIT][Darwin] Preload libclang_rt.asan_osx_dynamic.dylib when necessary

Green Dragon's darwin stage2 asan bot fails on some checks:
http://lab.llvm.org:8080/green/job/clang-stage2-cmake-RgSan_check

  test/tools/lto/hide-linkonce-odr.ll
  test/tools/lto/opt-level.ll

ERROR: Interceptors are not working. This may be because
AddressSanitizer is loaded too late (e.g. via dlopen)

To fix this, %ld64 needs to load 'libclang_rt.asan_osx_dynamic.dylib'
before libLTO.dylib, via DYLD_INSERT_LIBRARIES. This won't work by
updating config.environment, since some shim binary in the way scrubs
the env vars. Instead, provide the path to this lib through %asanrtlib,
which can then be used by tests directly with DYLD_INSERT_LIBRARIES.

rdar://problem/24300926

Modified:
    llvm/trunk/test/lit.cfg
    llvm/trunk/test/tools/lto/hide-linkonce-odr.ll
    llvm/trunk/test/tools/lto/opt-level.ll

Modified: llvm/trunk/test/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/lit.cfg?rev=277778&r1=277777&r2=277778&view=diff
==============================================================================
--- llvm/trunk/test/lit.cfg (original)
+++ llvm/trunk/test/lit.cfg Thu Aug  4 17:01:38 2016
@@ -170,6 +170,28 @@ if config.test_exec_root is None:
 
 ###
 
+# Provide the path to asan runtime lib 'libclang_rt.asan_osx_dynamic.dylib' if
+# available. This is darwin specific since it's currently only needed on darwin.
+def get_asan_rtlib():
+    if not "Address" in config.llvm_use_sanitizer or \
+       not "Darwin" in config.host_os or \
+       not "x86" in config.host_triple:
+        return ""
+    try:
+        import glob
+    except:
+        print("glob module not found, skipping get_asan_rtlib() lookup")
+        return ""
+    # The libclang_rt.asan_osx_dynamic.dylib path is obtained using the relative
+    # path from the host cc.
+    host_lib_dir = os.path.join(os.path.dirname(config.host_cc), "../lib")
+    asan_dylib_dir_pattern = host_lib_dir + \
+        "/clang/*/lib/darwin/libclang_rt.asan_osx_dynamic.dylib"
+    found_dylibs = glob.glob(asan_dylib_dir_pattern)
+    if len(found_dylibs) != 1:
+        return ""
+    return found_dylibs[0]
+
 lli = 'lli'
 # The target triple used by default by lli is the process target triple (some
 # triple appropriate for generating code for the current process) but because
@@ -196,6 +218,11 @@ config.substitutions.append( ('%exeext',
 config.substitutions.append( ('%python', config.python_executable) )
 config.substitutions.append( ('%host_cc', config.host_cc) )
 
+# Provide the path to asan runtime lib if available. On darwin, this lib needs
+# to be loaded via DYLD_INSERT_LIBRARIES before libLTO.dylib in case the files
+# to be linked contain instrumented sanitizer code.
+config.substitutions.append( ('%asanrtlib', get_asan_rtlib()) )
+
 # OCaml substitutions.
 # Support tests for both native and bytecode builds.
 config.substitutions.append( ('%ocamlc',

Modified: llvm/trunk/test/tools/lto/hide-linkonce-odr.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/lto/hide-linkonce-odr.ll?rev=277778&r1=277777&r2=277778&view=diff
==============================================================================
--- llvm/trunk/test/tools/lto/hide-linkonce-odr.ll (original)
+++ llvm/trunk/test/tools/lto/hide-linkonce-odr.ll Thu Aug  4 17:01:38 2016
@@ -1,5 +1,5 @@
 ; RUN: llvm-as %s -o %t.o
-; RUN: %ld64 -lto_library %llvmshlibdir/libLTO.dylib -dylib -arch x86_64 -macosx_version_min 10.10.0 -lSystem -o %t.dylib %t.o -save-temps  -undefined dynamic_lookup -exported_symbol _c -exported_symbol _b  -exported_symbol _GlobLinkonce
+; RUN: DYLD_INSERT_LIBRARIES=%asanrtlib %ld64 -lto_library %llvmshlibdir/libLTO.dylib -dylib -arch x86_64 -macosx_version_min 10.10.0 -lSystem -o %t.dylib %t.o -save-temps  -undefined dynamic_lookup -exported_symbol _c -exported_symbol _b  -exported_symbol _GlobLinkonce
 
 ; RUN: llvm-dis %t.dylib.lto.opt.bc -o - | FileCheck --check-prefix=IR %s
 ; check that @a is no longer a linkonce_odr definition

Modified: llvm/trunk/test/tools/lto/opt-level.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/lto/opt-level.ll?rev=277778&r1=277777&r2=277778&view=diff
==============================================================================
--- llvm/trunk/test/tools/lto/opt-level.ll (original)
+++ llvm/trunk/test/tools/lto/opt-level.ll Thu Aug  4 17:01:38 2016
@@ -1,7 +1,7 @@
 ; RUN: llvm-as %s -o %t.o
-; RUN: %ld64 -lto_library %llvmshlibdir/libLTO.dylib -arch x86_64 -dylib -mllvm -O0 -o %t.dylib %t.o
+; RUN: DYLD_INSERT_LIBRARIES=%asanrtlib %ld64 -lto_library %llvmshlibdir/libLTO.dylib -arch x86_64 -dylib -mllvm -O0 -o %t.dylib %t.o
 ; RUN: llvm-nm -no-llvm-bc %t.dylib | FileCheck --check-prefix=CHECK-O0 %s
-; RUN: %ld64 -lto_library %llvmshlibdir/libLTO.dylib -arch x86_64 -dylib -mllvm -O2 -o %t.dylib %t.o
+; RUN: DYLD_INSERT_LIBRARIES=%asanrtlib %ld64 -lto_library %llvmshlibdir/libLTO.dylib -arch x86_64 -dylib -mllvm -O2 -o %t.dylib %t.o
 ; RUN: llvm-nm -no-llvm-bc %t.dylib | FileCheck --check-prefix=CHECK-O2 %s
 
 target triple = "x86_64-apple-macosx10.8.0"




More information about the llvm-commits mailing list