Search code examples
c++linuxgccldaddress-sanitizer

Running program with asan does not use rpath


I am compiling my application which consist of a binary and some dynamic libraries. My makefile uses

LDFLAGS=-Wl,-rpath='$$ORIGIN/../lib',-rpath=/opt/suse/lib64,--disable-new-dtags

For my normal build without asan this works so that all libraries (directly linked and dynamically loaded) are first searched in ../lib during runtime.

When I use asan with -fsanitize=address for both CXXFLAGS and LDFLAGS, ld does not use rpath anymore for searching the dynamically loaded (dlopen) libraries.

echo $LD_LIBRARY_PATH
:/EDI_TOOLS/ORACLE/client:/home1/conic/Trafo/program/UmsetzerV19

strace output:

open("tls/x86_64/Consumer_EndTransaction.so", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/Consumer_EndTransaction.so", O_RDONLY) = -1 ENOENT (No such file or directory)
open("x86_64/Consumer_EndTransaction.so", O_RDONLY) = -1 ENOENT (No such file or directory)
open("Consumer_EndTransaction.so", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/EDI_TOOLS/ORACLE/client/Consumer_EndTransaction.so", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/home1/conic/Trafo/program/UmsetzerV19/Consumer_EndTransaction.so", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib64/gcc/x86_64-suse-linux/5/Consumer_EndTransaction.so", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY)      = 4
fstat(4, {st_mode=S_IFREG|0644, st_size=83482, ...}) = 0

objdump -x gives this output (amongst much more, but rpath is set correctly). All libs in NEEDED are found correctly.

Dynamic Section:
  NEEDED               libasan.so.2
  NEEDED               libKernel.so
  NEEDED               libCUtil.so
  NEEDED               libApi.so
  NEEDED               libactivemq-cpp.so.19
  NEEDED               libnorm.so
  NEEDED               libcurl.so.4
  NEEDED               libcurlpp.so.0
  NEEDED               libutilspp.so.0
  NEEDED               libtdsodbc.so.0
  NEEDED               libicuuc.so.58
  NEEDED               libicui18n.so.58
  NEEDED               libxerces-c-3.1.so
  NEEDED               libxalan-c.so.111
  NEEDED               libldap60.so
  NEEDED               libclntsh.so.12.1
  NEEDED               libuuid.so.1
  NEEDED               libz.so.1
  NEEDED               libdl.so.2
  NEEDED               libstdc++.so.6
  NEEDED               libm.so.6
  NEEDED               libgcc_s.so.1
  NEEDED               libpthread.so.0
  NEEDED               libc.so.6
  RPATH                $ORIGIN/../lib:/opt/suse/lib64

I am using SLES 11 with

g++-5 (SUSE Linux) 5.3.1 20160301 [gcc-5-branch revision 233849]
GNU ld (GNU Binutils; SUSE Linux Enterprise 11) 2.25.0
ld.so-1.7.0

Am I missing something?


Solution

  • It seems that the ASAN wrapper around dlopen() changes its behaviour. Looks like the following bug: https://bugzilla.redhat.com/show_bug.cgi?id=1449604