[compiler-rt] r227161 - [ASan] Use rpath in tests that produce a shared library

Kuba Brecka kuba.brecka at gmail.com
Fri Mar 27 05:41:59 PDT 2015


You can just move the executable and shared library to a different directory and see if it still works:

$ ./bin/llvm-lit -v ./projects/compiler-rt/test/asan/I386DarwinConfig/TestCases/suppressions-library.cc
PASS: AddressSanitizer-i386-darwin :: TestCases/suppressions-library.cc (1 of 1)
$ mv ./projects/compiler-rt/test/asan/I386DarwinConfig/TestCases/Output/suppressions-library.cc.tmp /tmp
$ mv ./projects/compiler-rt/test/asan/I386DarwinConfig/TestCases/Output/suppressions-library.cc.tmp-so.so /tmp
$ /tmp/suppressions-library.cc.tmp
=================================================================
==23066==ERROR: AddressSanitizer: heap-use-after-free on address 0x01c00710 at pc 0x00131c37 bp 0xbff60a18 sp 0xbff60154
...

If I remove the “-install_name” and “-rpath” pieces from the suppressions-library.cc <http://suppressions-library.cc/> test case, the lit test will still pass, but after moving the binaries, the executable won’t be able to find the dylib anymore:

$ ./bin/llvm-lit -v ./projects/compiler-rt/test/asan/I386DarwinConfig/TestCases/suppressions-library.cc
PASS: AddressSanitizer-i386-darwin :: TestCases/suppressions-library.cc (1 of 1)
$ mv ./projects/compiler-rt/test/asan/I386DarwinConfig/TestCases/Output/suppressions-library.cc.tmp /tmp
$ mv ./projects/compiler-rt/test/asan/I386DarwinConfig/TestCases/Output/suppressions-library.cc.tmp-so.so /tmp
$ /tmp/suppressions-library.cc.tmp
dyld: Library not loaded: /.../I386DarwinConfig/TestCases/Output/suppressions-library.cc.tmp-so.so
  Referenced from: /tmp/suppressions-library.cc.tmp
  Reason: image not found
Trace/BPT trap: 5

Kuba


> On Mar 27, 2015, at 1:30 PM, Alexander Potapenko <glider at google.com> wrote:
> 
> By the way, is there an easy way to reproduce this aspect of remote
> testing locally.
> Right now I'm considering adding substitutions for linker flags that
> assume the dynamic library corresponding to %t is called %t-so.so.
> 
> On Thu, Mar 26, 2015 at 9:22 PM, Alexander Potapenko <glider at google.com> wrote:
>> I've been trying those, but couldn't come up with a solution that is elegant
>> enough.
>> Because those linker flag substitutions must depend on the shared library
>> names, we must either parameterize them somehow (which lit doesn't support
>> yet) or make fragile assumptions about the shared library names depending on
>> %t value.
>> 
>> sent from phone
>> 
>> On Mar 26, 2015 6:20 PM, "Kuba Brecka" <kuba.brecka at gmail.com> wrote:
>>> 
>>> Hi Alexander,
>>> 
>>> the reason is that in one of our internal test setups, we’re doing remote
>>> testing, and we move/copy the shared libraries.  If we don’t use “-rpath”
>>> and “-install_name”, the executable has a hardcoded full path to the library
>>> and doesn’t work when moved elsewhere.
>>> 
>>> Could this instead be solved by some extra lit substitutions that would
>>> resolve differently on Linux and Darwin?
>>> 
>>> Kuba
>>> 
>>>> On Mar 26, 2015, at 2:15 PM, Alexander Potapenko <glider at google.com>
>>>> wrote:
>>>> 
>>>> Overall, what's the reason behind this patch?
>>>> I've been trying to merge the Linux and Darwin versions of
>>>> interception-in-shared-lib-test today making the RUN lines look as
>>>> follows:
>>>> 
>>>> // RUN: %clangxx_asan -O0 %s -DSHARED_LIB \
>>>> // RUN:     -shared -o %t-so.so -fPIC
>>>> // RUN: %clangxx_asan -O0 %s -o %t %t-so.so && \
>>>> // RUN:     not %run %t 2>&1 | FileCheck %s
>>>> 
>>>> , but the additional linker flags complicate that. Are they really
>>>> necessary?
>>>> 
>>>> On Tue, Mar 24, 2015 at 5:35 PM, Alexander Potapenko <glider at google.com>
>>>> wrote:
>>>>> There are two problems with this patch:
>>>>> 1. (minor) Clang doesn't use the -rpath argument on Linux in
>>>>> TestCases/suppressions-library.cc.
>>>>> 2. In their current state, these two tests don't work on my machine (OS
>>>>> X 10.9):
>>>>> 
>>>>> $ DYLD_PRINT_RPATHS=1 <cut>/Output/suppressions-library.cc.tmp
>>>>> RPATH failed to expanding     @rpath/suppressions-library.cc.tmp-so.so
>>>>> to: @executable_path/suppressions-library.cc.tmp-so.so
>>>>> RPATH failed to expanding     @rpath/suppressions-library.cc.tmp-so.so
>>>>> to: @executable_path/suppressions-library.cc.tmp-so.so
>>>>> RPATH failed to expanding     @rpath/suppressions-library.cc.tmp-so.so
>>>>> to:
>>>>> <cut>/../lib/clang/3.7.0/lib/darwin/suppressions-library.cc.tmp-so.so
>>>>> dyld: Library not loaded: @rpath/suppressions-library.cc.tmp-so.so
>>>>> Referenced from: <cut>/Output/suppressions-library.cc.tmp
>>>>> Reason: image not found
>>>>> Trace/BPT trap: 5
>>>>> 
>>>>> For some reason dyld fails to find the dynamic library next to the
>>>>> executable, if that executable was linked with
>>>>> -Wl,-rpath, at executable_path.
>>>>> The solution is to link with "-Wl,-rpath, at executable_path/" (note the
>>>>> trailing slash), but I don't fully understand why this happens for me
>>>>> and not for Kuba.
>>>>> 
>>>>> On Tue, Jan 27, 2015 at 4:29 AM, Kuba Brecka <kuba.brecka at gmail.com>
>>>>> wrote:
>>>>>> Author: kuba.brecka
>>>>>> Date: Mon Jan 26 19:29:18 2015
>>>>>> New Revision: 227161
>>>>>> 
>>>>>> URL: http://llvm.org/viewvc/llvm-project?rev=227161&view=rev
>>>>>> Log:
>>>>>> [ASan] Use rpath in tests that produce a shared library
>>>>>> 
>>>>>> Modifying Darwin/interception-in-shared-lib-test.cc and
>>>>>> suppressions-library.cc
>>>>>> to use rpath instead of linking against the full path to the temporary
>>>>>> file.
>>>>>> NFC.
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> Modified:
>>>>>> 
>>>>>> compiler-rt/trunk/test/asan/TestCases/Darwin/interception-in-shared-lib-test.cc
>>>>>>   compiler-rt/trunk/test/asan/TestCases/suppressions-library.cc
>>>>>> 
>>>>>> Modified:
>>>>>> 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=227161&r1=227160&r2=227161&view=diff
>>>>>> 
>>>>>> ==============================================================================
>>>>>> ---
>>>>>> 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
>>>>>> Mon Jan 26 19:29:18 2015
>>>>>> @@ -3,11 +3,11 @@
>>>>>> // ../Linux/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
>>>>>> +// 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 -L%T
>>>>>> -linterception-in-shared-lib-test && \
>>>>>> +// 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>
>>>>>> 
>>>>>> 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=227161&r1=227160&r2=227161&view=diff
>>>>>> 
>>>>>> ==============================================================================
>>>>>> --- compiler-rt/trunk/test/asan/TestCases/suppressions-library.cc
>>>>>> (original)
>>>>>> +++ compiler-rt/trunk/test/asan/TestCases/suppressions-library.cc Mon
>>>>>> Jan 26 19:29:18 2015
>>>>>> @@ -1,10 +1,10 @@
>>>>>> -// RUN: %clangxx_asan -O0 -DSHARED_LIB %s -fPIC -shared -o %t-so.so
>>>>>> -// RUN: %clangxx_asan -O0 %s %t-so.so -o %t
>>>>>> +// 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
>>>>>> 
>>>>>> // 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:%t-so.so" > %t.supp
>>>>>> +// RUN: echo "interceptor_via_lib:suppressions-library.cc.tmp-so.so"
>>>>>>> %t.supp
>>>>>> // RUN: ASAN_OPTIONS="suppressions='%t.supp'" %run %t 2>&1 | FileCheck
>>>>>> --check-prefix=CHECK-IGNORE %s
>>>>>> 
>>>>>> // XFAIL: android
>>>>>> 
>>>>>> 
>>>>>> _______________________________________________
>>>>>> llvm-commits mailing list
>>>>>> llvm-commits at cs.uiuc.edu
>>>>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>>>> 
>>>>> 
>>>>> 
>>>>> --
>>>>> Alexander Potapenko
>>>>> Software Engineer
>>>>> Google Moscow
>>>> 
>>>> 
>>>> 
>>>> --
>>>> Alexander Potapenko
>>>> Software Engineer
>>>> Google Moscow
>>> 
>> 
> 
> 
> 
> -- 
> Alexander Potapenko
> Software Engineer
> Google Moscow

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150327/51862e6d/attachment.html>


More information about the llvm-commits mailing list