<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">You can just move the executable and shared library to a different directory and see if it still works:</div><div class=""><br class=""></div><div class=""><div class="">$ ./bin/llvm-lit -v ./projects/compiler-rt/test/asan/I386DarwinConfig/TestCases/<a href="http://suppressions-library.cc" class="">suppressions-library.cc</a></div><div class="">PASS: AddressSanitizer-i386-darwin :: TestCases/<a href="http://suppressions-library.cc" class="">suppressions-library.cc</a> (1 of 1)</div><div class="">$ mv ./projects/compiler-rt/test/asan/I386DarwinConfig/TestCases/Output/suppressions-library.cc.tmp /tmp</div><div class="">$ mv ./projects/compiler-rt/test/asan/I386DarwinConfig/TestCases/Output/suppressions-library.cc.tmp-so.so /tmp</div><div class="">$ /tmp/suppressions-library.cc.tmp</div><div class="">=================================================================</div><div class="">==23066==ERROR: AddressSanitizer: heap-use-after-free on address 0x01c00710 at pc 0x00131c37 bp 0xbff60a18 sp 0xbff60154</div><div class="">...</div><div class=""><br class=""></div></div><div class="">If I remove the “-install_name” and “-rpath” pieces from the <a href="http://suppressions-library.cc" class="">suppressions-library.cc</a> test case, the lit test will still pass, but after moving the binaries, the executable won’t be able to find the dylib anymore:</div><div class=""><br class=""></div><div class=""><div class="">$ ./bin/llvm-lit -v ./projects/compiler-rt/test/asan/I386DarwinConfig/TestCases/<a href="http://suppressions-library.cc" class="">suppressions-library.cc</a></div><div class="">PASS: AddressSanitizer-i386-darwin :: TestCases/<a href="http://suppressions-library.cc" class="">suppressions-library.cc</a> (1 of 1)</div><div class="">$ mv ./projects/compiler-rt/test/asan/I386DarwinConfig/TestCases/Output/suppressions-library.cc.tmp /tmp</div><div class="">$ mv ./projects/compiler-rt/test/asan/I386DarwinConfig/TestCases/Output/suppressions-library.cc.tmp-so.so /tmp</div><div class="">$ /tmp/suppressions-library.cc.tmp</div><div class="">dyld: Library not loaded: /.../I386DarwinConfig/TestCases/Output/suppressions-library.cc.tmp-so.so</div><div class="">  Referenced from: /tmp/suppressions-library.cc.tmp</div><div class="">  Reason: image not found</div><div class="">Trace/BPT trap: 5</div></div><div class=""><br class=""></div><div class="">Kuba</div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On Mar 27, 2015, at 1:30 PM, Alexander Potapenko <<a href="mailto:glider@google.com" class="">glider@google.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">By the way, is there an easy way to reproduce this aspect of remote<br class="">testing locally.<br class="">Right now I'm considering adding substitutions for linker flags that<br class="">assume the dynamic library corresponding to %t is called %t-so.so.<br class=""><br class="">On Thu, Mar 26, 2015 at 9:22 PM, Alexander Potapenko <<a href="mailto:glider@google.com" class="">glider@google.com</a>> wrote:<br class=""><blockquote type="cite" class="">I've been trying those, but couldn't come up with a solution that is elegant<br class="">enough.<br class="">Because those linker flag substitutions must depend on the shared library<br class="">names, we must either parameterize them somehow (which lit doesn't support<br class="">yet) or make fragile assumptions about the shared library names depending on<br class="">%t value.<br class=""><br class="">sent from phone<br class=""><br class="">On Mar 26, 2015 6:20 PM, "Kuba Brecka" <<a href="mailto:kuba.brecka@gmail.com" class="">kuba.brecka@gmail.com</a>> wrote:<br class=""><blockquote type="cite" class=""><br class="">Hi Alexander,<br class=""><br class="">the reason is that in one of our internal test setups, we’re doing remote<br class="">testing, and we move/copy the shared libraries.  If we don’t use “-rpath”<br class="">and “-install_name”, the executable has a hardcoded full path to the library<br class="">and doesn’t work when moved elsewhere.<br class=""><br class="">Could this instead be solved by some extra lit substitutions that would<br class="">resolve differently on Linux and Darwin?<br class=""><br class="">Kuba<br class=""><br class=""><blockquote type="cite" class="">On Mar 26, 2015, at 2:15 PM, Alexander Potapenko <<a href="mailto:glider@google.com" class="">glider@google.com</a>><br class="">wrote:<br class=""><br class="">Overall, what's the reason behind this patch?<br class="">I've been trying to merge the Linux and Darwin versions of<br class="">interception-in-shared-lib-test today making the RUN lines look as<br class="">follows:<br class=""><br class="">// RUN: %clangxx_asan -O0 %s -DSHARED_LIB \<br class="">// RUN:     -shared -o %t-so.so -fPIC<br class="">// RUN: %clangxx_asan -O0 %s -o %t %t-so.so && \<br class="">// RUN:     not %run %t 2>&1 | FileCheck %s<br class=""><br class="">, but the additional linker flags complicate that. Are they really<br class="">necessary?<br class=""><br class="">On Tue, Mar 24, 2015 at 5:35 PM, Alexander Potapenko <<a href="mailto:glider@google.com" class="">glider@google.com</a>><br class="">wrote:<br class=""><blockquote type="cite" class="">There are two problems with this patch:<br class="">1. (minor) Clang doesn't use the -rpath argument on Linux in<br class="">TestCases/<a href="http://suppressions-library.cc" class="">suppressions-library.cc</a>.<br class="">2. In their current state, these two tests don't work on my machine (OS<br class="">X 10.9):<br class=""><br class="">$ DYLD_PRINT_RPATHS=1 <cut>/Output/suppressions-library.cc.tmp<br class="">RPATH failed to expanding     @rpath/suppressions-library.cc.tmp-so.so<br class="">to: @executable_path/suppressions-library.cc.tmp-so.so<br class="">RPATH failed to expanding     @rpath/suppressions-library.cc.tmp-so.so<br class="">to: @executable_path/suppressions-library.cc.tmp-so.so<br class="">RPATH failed to expanding     @rpath/suppressions-library.cc.tmp-so.so<br class="">to:<br class=""><cut>/../lib/clang/3.7.0/lib/darwin/suppressions-library.cc.tmp-so.so<br class="">dyld: Library not loaded: @rpath/suppressions-library.cc.tmp-so.so<br class=""> Referenced from: <cut>/Output/suppressions-library.cc.tmp<br class=""> Reason: image not found<br class="">Trace/BPT trap: 5<br class=""><br class="">For some reason dyld fails to find the dynamic library next to the<br class="">executable, if that executable was linked with<br class="">-Wl,-rpath,@executable_path.<br class="">The solution is to link with "-Wl,-rpath,@executable_path/" (note the<br class="">trailing slash), but I don't fully understand why this happens for me<br class="">and not for Kuba.<br class=""><br class="">On Tue, Jan 27, 2015 at 4:29 AM, Kuba Brecka <<a href="mailto:kuba.brecka@gmail.com" class="">kuba.brecka@gmail.com</a>><br class="">wrote:<br class=""><blockquote type="cite" class="">Author: kuba.brecka<br class="">Date: Mon Jan 26 19:29:18 2015<br class="">New Revision: 227161<br class=""><br class="">URL: <a href="http://llvm.org/viewvc/llvm-project?rev=227161&view=rev" class="">http://llvm.org/viewvc/llvm-project?rev=227161&view=rev</a><br class="">Log:<br class="">[ASan] Use rpath in tests that produce a shared library<br class=""><br class="">Modifying Darwin/<a href="http://interception-in-shared-lib-test.cc" class="">interception-in-shared-lib-test.cc</a> and<br class=""><a href="http://suppressions-library.cc" class="">suppressions-library.cc</a><br class="">to use rpath instead of linking against the full path to the temporary<br class="">file.<br class="">NFC.<br class=""><br class=""><br class=""><br class="">Modified:<br class=""><br class="">compiler-rt/trunk/test/asan/TestCases/Darwin/interception-in-shared-lib-test.cc<br class="">   compiler-rt/trunk/test/asan/TestCases/suppressions-library.cc<br class=""><br class="">Modified:<br class="">compiler-rt/trunk/test/asan/TestCases/Darwin/interception-in-shared-lib-test.cc<br class="">URL:<br class="">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Darwin/interception-in-shared-lib-test.cc?rev=227161&r1=227160&r2=227161&view=diff<br class=""><br class="">==============================================================================<br class="">---<br class="">compiler-rt/trunk/test/asan/TestCases/Darwin/interception-in-shared-lib-test.cc<br class="">(original)<br class="">+++<br class="">compiler-rt/trunk/test/asan/TestCases/Darwin/interception-in-shared-lib-test.cc<br class="">Mon Jan 26 19:29:18 2015<br class="">@@ -3,11 +3,11 @@<br class="">// ../Linux/interception-in-shared-lib-test.cc.<br class=""><br class="">// RUN: %clangxx_asan -O0 %s -DSHARED_LIB \<br class="">-// RUN:     -shared -o %T/libinterception-in-shared-lib-test.so \<br class="">-// RUN:     -fPIC<br class="">+// RUN:     -shared -o %t-so.so \<br class="">+// RUN:     -fPIC -install_name<br class="">@rpath/interception-in-shared-lib-test.cc.tmp-so.so<br class="">// TODO(glider): figure out how to set rpath in a more portable way<br class="">and unite<br class="">// this test with ../Linux/interception-in-shared-lib-test.cc.<br class="">-// RUN: %clangxx_asan -O0 %s -o %t -Wl,-rpath,@executable-path -L%T<br class="">-linterception-in-shared-lib-test && \<br class="">+// RUN: %clangxx_asan -O0 %s -o %t -Wl,-rpath,@executable_path<br class="">%t-so.so && \<br class="">// RUN:     not %run %t 2>&1 | FileCheck %s<br class=""><br class="">#include <stdio.h><br class=""><br class="">Modified:<br class="">compiler-rt/trunk/test/asan/TestCases/suppressions-library.cc<br class="">URL:<br class="">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/suppressions-library.cc?rev=227161&r1=227160&r2=227161&view=diff<br class=""><br class="">==============================================================================<br class="">--- compiler-rt/trunk/test/asan/TestCases/suppressions-library.cc<br class="">(original)<br class="">+++ compiler-rt/trunk/test/asan/TestCases/suppressions-library.cc Mon<br class="">Jan 26 19:29:18 2015<br class="">@@ -1,10 +1,10 @@<br class="">-// RUN: %clangxx_asan -O0 -DSHARED_LIB %s -fPIC -shared -o %t-so.so<br class="">-// RUN: %clangxx_asan -O0 %s %t-so.so -o %t<br class="">+// RUN: %clangxx_asan -O0 -DSHARED_LIB %s -fPIC -shared -o %t-so.so<br class="">-install_name @rpath/suppressions-library.cc.tmp-so.so<br class="">+// RUN: %clangxx_asan -O0 %s %t-so.so -o %t -rpath @executable_path<br class=""><br class="">// Check that without suppressions, we catch the issue.<br class="">// RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s<br class=""><br class="">-// RUN: echo "interceptor_via_lib:%t-so.so" > %t.supp<br class="">+// RUN: echo "interceptor_via_lib:suppressions-library.cc.tmp-so.so"<br class=""><blockquote type="cite" class="">%t.supp<br class=""></blockquote>// RUN: ASAN_OPTIONS="suppressions='%t.supp'" %run %t 2>&1 | FileCheck<br class="">--check-prefix=CHECK-IGNORE %s<br class=""><br class="">// XFAIL: android<br class=""><br class=""><br class="">_______________________________________________<br class="">llvm-commits mailing list<br class="">llvm-commits@cs.uiuc.edu<br class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits<br class=""></blockquote><br class=""><br class=""><br class="">--<br class="">Alexander Potapenko<br class="">Software Engineer<br class="">Google Moscow<br class=""></blockquote><br class=""><br class=""><br class="">--<br class="">Alexander Potapenko<br class="">Software Engineer<br class="">Google Moscow<br class=""></blockquote><br class=""></blockquote><br class=""></blockquote><br class=""><br class=""><br class="">-- <br class="">Alexander Potapenko<br class="">Software Engineer<br class="">Google Moscow<br class=""></div></blockquote></div><br class=""></body></html>