8

In our build system we have recently integrated ASAN tool (adding -fsanitize=address) to CFLAGS & also while linking , creating library .so files. Note:- We are using GCC 6.3 compiler.

We are able to successfully build our code. But while running it fails with following issue:

==52215==ASan runtime does not come first in initial library list; you should either link runtime to your application or manually preload it with LD_PRELOAD.

Here is my gcc command:-

/local/common/pkgs/gcc/v6.3.0/bin/gcc -m32 -shared -o /local/testing/build/new_tool/asan_build/syn/verilog/libspd.so  -Wl,-rpath=\$ORIGIN/lib -Wl,-rpath=\$ORIGIN/../lib -W1,-rpath=/local/common/gcc/v6.3.0/lib  -fsanitize=address -L/local/testing/build/new_tool/asan_build/modules /local/testing/build/new_tool/asan_build/modules/silvpi.o /local/testing/build/new_tool/asan_build/modules/sypsv.o /local/testing/build/new_tool/asan_build/modules/cdnsv_tfs.o /local/testing/build/new_tool/asan_build/modules/libcore.o /local/testing/build/new_tool/asan_build/modules/vpi_user.o /local/testing/build/new_tool/asan_build/modules/libdenbase.a /local/testing/build/new_tool/asan_build/modules/libbdd.a  -L/local/testing/build/new_tool/asan_build/syn/lib -L/local/testing/build/new_tool/asan_build/modules -L/home/local/outer/Linux/lib /local/testing/build/new_tool/asan_build/modules/vhpimodelfunc.o /local/testing/build/new_tool/asan_build/modules/vipcommonlib.a  -lm -lc -ldenbase -lbdd -ldenbase -lviputil -llocalCommonMT_sh

I am able to build library libspd.so successfully. But when we try to run it fails with above error i mentioned.

i can see the dependent library list of libspd.so

ldd /local/testing/build/new_tool/asan_build/syn/verilog/libspd.so
    linux-gate.so.1 =>  (0x00279000)
    libasan.so.3 => /local/pkgs/gcc/v6.3.0/lib/libasan.so.3 (0xf7175000)
    libm.so.6 => /lib/libm.so.6 (0x0014e000)
    libc.so.6 => /lib/libc.so.6 (0xf6f83000)
    libcdsCommonMT_sh.so => /local/testing/build/new_tool/asan_build/verilog/../lib/liblocalCommonMT_sh.so (0x00178000)
    libdl.so.2 => /lib/libdl.so.2 (0x00197000)

We are trying to run our application with 'xrun' where it runs simulation on top of my build which was build with asan. As error says : you should either link runtime to your application i was trying to add my complete asan library path to LD_LIBRARY_PATH, Still facing the same issue.

Not sure whats going wrong here. How can i resolve this issue?

Any idea? Thanks and regards!

santosh
  • 421
  • 1
  • 6
  • 14
  • Is main executable sanitized as well or only the shared library? – yugr Jan 22 '20 at 07:56
  • @yugr,executable which i am running and hitting issue not a sanitized. Based on error i setup the LD_PRELOAD pointing to libasan.so path in one of my environment file where LD_LIBRARY_PATH is also set. – santosh Jan 22 '20 at 08:07
  • Please provide [MVCE](https://stackoverflow.com/help/minimal-reproducible-example). – yugr Jan 23 '20 at 10:20
  • based on the info in doc : https://github.com/google/sanitizers/issues/679 it was mentioned that : FWIW non-empty /etc/ld.so.preload was an exact reason why GCC 6 didn't work (ASan runtime indeed wasn't first in initial library list). GCC 4.9 works just because it's too old and doesn't have this sanity check. I am using gcc 6.3, i cant see the file file /etc/ld.so.preload – santosh Jan 23 '20 at 15:56

1 Answers1

11

You have several ways to work around this:

  • build main executable with -fsanitize=address
  • get rid of /etc/ld.so.preload on your test machine
  • disable the check (need recent GCC) with export ASAN_OPTIONS=verify_asan_link_order=0; but you have to be sure that libraries from /etc/ld.so.preload do not intercept symbols important for Asan e.g. malloc, free, etc., otherwise things will start breaking
yugr
  • 19,769
  • 3
  • 51
  • 96
  • Main executable in the sense 'xrun' executable which we try to run some tests on my build (with asan) ? And second one. I cat see ld.so.preload on my machine. i cant do 'ls' . The file is not available. – santosh Jan 24 '20 at 10:40
  • @santosh Main executable is the file which is linked to sanitized library (`libspd.so`). "I cat see ld.so.preload on my machine" - this contradicts your comment "non-empty /etc/ld.so.preload was an exact reason why GCC 6 didn't work". – yugr Jan 24 '20 at 10:48
  • @santosh I really suggest you provide MVCE or at least complete description of your steps in question text. Otherwise it's hard to help because too much guesswork is needed. – yugr Jan 24 '20 at 10:50
  • File '/etc/ld.so.preload' it self is not there in my host where i run the build. – santosh Jan 24 '20 at 11:19
  • @santosh So why did you refer to `/etc/ld.so.preload` in question, saying that it "was an exact reason why GCC 6 didn't work"? Note that all these endless discussions are due to insufficient details provided in original question. – yugr Jan 24 '20 at 13:05