Opened 6 years ago

Closed 5 years ago

#57152 closed defect (fixed)

clang: asan does not work

Reported by: akimd (Akim Demaille) Owned by: jeremyhu (Jeremy Huddleston Sequoia)
Priority: Normal Milestone:
Component: ports Version: 2.5.3
Keywords: Cc: larryv (Lawrence Velázquez), mouse07410 (Mouse)
Port: clang-devel clang-6.0 clang-7.0 clang-8.0

Description

Hi!

$ cat foo.cc
int main()
{
  return 0;
}
$ clang++-mp-devel foo.cc
$ ./a.out
$ clang++-mp-devel foo.cc -fsanitize=address
$ ./a.out
dyld: Library not loaded: /opt/local/libexec/llvm-devel/lib/libclang_rt.asan_osx_dynamic.dylib
  Referenced from: /private/tmp/./a.out
  Reason: image not found
zsh: abort      ./a.out

I don't remember when asan worked properly in MacPorts, I think I've always had to add symlinks to work around this. Unfortunately, only one compiler can be fixed at a time this way.

Cheers!

Change History (13)

comment:1 Changed 6 years ago by mf2k (Frank Schima)

Cc: jeremyhu removed
Owner: set to jeremyhu
Status: newassigned

comment:2 Changed 6 years ago by kencu (Ken)

We have adjusted the rpaths for an issue like this before. Clearly still needs some tweaking. Thanks.

It's looking here:

/opt/local/libexec/llvm-7.0/lib/libclang_rt.asan_osx_dynamic.dylib

But the library is really here:

/opt/local/libexec/llvm-7.0/lib/clang/7.0.0/lib/darwin/libclang_rt.asan_osx_dynamic.dylib

Here's full output from the build/link line:

$ clang++ -v -Wl,"-v" -fsanitize=address foo.cc
clang version 7.0.0 (tags/RELEASE_700/final)
Target: x86_64-apple-darwin18.0.0
Thread model: posix
InstalledDir: /opt/local/libexec/llvm-7.0/bin
 "/opt/local/libexec/llvm-7.0/bin/clang" -cc1 -triple x86_64-apple-macosx10.14.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name foo.cc -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -target-linker-version 409.12 -v -resource-dir /opt/local/libexec/llvm-7.0/lib/clang/7.0.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -I/usr/local/include -stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir /Users/cunningh -ferror-limit 19 -fmessage-length 185 -fsanitize=address -fsanitize-blacklist=/opt/local/libexec/llvm-7.0/lib/clang/7.0.0/share/asan_blacklist.txt -fsanitize-address-use-after-scope -fsanitize-address-globals-dead-stripping -fno-assume-sane-operator-new -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fobjc-runtime=macosx-10.14.0 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/hp/684rvltd0c127nmt0bh3bpzm0000gn/T/foo-409159.o -x c++ foo.cc
clang -cc1 version 7.0.0 based upon LLVM 7.0.0 default target x86_64-apple-darwin18.0.0
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/c++/v1"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /opt/local/libexec/llvm-7.0/include/c++/v1
 /opt/local/libexec/llvm-7.0/lib/clang/7.0.0/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks (framework directory)
End of search list.
 "/opt/local/libexec/llvm-7.0/bin/ld" -demangle -lto_library /opt/local/libexec/llvm-7.0/lib/libLTO.dylib -no_deduplicate -dynamic -arch x86_64 -macosx_version_min 10.14.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -o a.out -v /var/folders/hp/684rvltd0c127nmt0bh3bpzm0000gn/T/foo-409159.o -L/usr/local/lib -lc++ /opt/local/libexec/llvm-7.0/lib/clang/7.0.0/lib/darwin/libclang_rt.asan_osx_dynamic.dylib -rpath @executable_path -rpath /opt/local/libexec/llvm-7.0/lib/clang/7.0.0/lib/darwin -lSystem /opt/local/libexec/llvm-7.0/lib/clang/7.0.0/lib/darwin/libclang_rt.osx.a
@(#)PROGRAM:ld  PROJECT:ld64-409.12
BUILD 02:04:28 Aug 14 2018
configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em arm64e arm64_32
Library search paths:
	/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/lib
Framework search paths:
	/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/


$ ./a.out
dyld: Library not loaded: /opt/local/libexec/llvm-7.0/lib/libclang_rt.asan_osx_dynamic.dylib
  Referenced from: /Users/cunningh/./a.out
  Reason: image not found
Abort trap: 6

comment:3 Changed 5 years ago by kencu (Ken)

has duplicate 58813

comment:4 Changed 5 years ago by kencu (Ken)

Port: clang-8.0 added

comment:5 Changed 5 years ago by kencu (Ken)

Cc: mouse07410 added

comment:6 Changed 5 years ago by mouse07410 (Mouse)

Yes it is the same problem as in #58813. Either clang does not set rpath properly at linking, or Macports misplaces the libraries during installation.

Since it's been 10 months since this problem was discovered (and it's likely that a simple fix exists), when could we expect any progress?

comment:7 Changed 5 years ago by kencu (Ken)

see also 53299

comment:8 Changed 5 years ago by mouse07410 (Mouse)

Thanks! But, Ken, in that ticket you seemed to have found a solution? Is it applicable to here and now?

comment:9 Changed 5 years ago by kencu (Ken)

yes, I fixed this once before....presumably the re-fix will be similar...

comment:10 Changed 5 years ago by kencu (Ken)

OK. fixed again. just setting up all the different clangs that need the fix...

comment:11 Changed 5 years ago by kencu (Ken)

this commit changed things just enough to break the previous fix. Readjusting...

comment:12 Changed 5 years ago by kencu (Ken)

For anyone impatient to fix this, you can try out this PR which I believe is going to be the final fix for this, in the end.

comment:13 Changed 5 years ago by ken-cunningham-webuse

Resolution: fixed
Status: assignedclosed

In b388e206e96c3a368da19664b4dd5582c769b5ac/macports-ports (master):

llvm/clang/lldb 3.9+ fix rpath handling, revbump

this was originally fixed in
<e75a4491bbaf8e8346068ac6c9f52e082e3634b3/macports-ports>

but once
<https://github.com/macports/macports-ports/pull/103/commits/4cddb7db3a182f366d605e8db97944cd9d1e0e87>
was merged, the configure.args-delete in the portfile no longer deleted the install_name and install_rpath settings

this resulted in llvm/clang/lldb dylibs sometimes being installed with incorrect library names
and caused errors using the sanitizer libs and similar in clang

the PR restores the previous intended behaviour to allow the cmake scripts in llvm* to set the rpaths

see: #53299
closes: #57152
see: #58889

Note: See TracTickets for help on using tickets.