4

I am trying to use AddressSanitizer on Raspbian.

I use the following to compile my program:

gcc -fsanitize=address -fno-omit-frame-pointer -g prog.c -o prog

Even for the simplest program (just a Hello World), I get the following when trying to run it:

==1966==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.

While I can work around this using the -static-libasan compilation flag, I would like to understand why this happens on Raspbian, but not on other platforms. I do not see the same on x86_64 Ubuntu 16.04 or 19.04.

What exactly is different in Raspbian that causes this?

I was hoping to be able to compile and run programs in a uniform way on multiple platforms (including x86_64 Linux and macOS, even in debug mode with AddressSanitizer). Some platforms may require special flags, but I would like to understand how to correctly detect that.

  • You could just take care of that by using a makefile with rules for each platform. – user96931 May 16 at 15:14
  • @user96931 It's not nearly as simple as a single makefile. But the issue is to understand how to detect the need for this switch. Is it just Raspbian? All RPi Linux distros? All ARM Linux? Or it has nothing to do with ARM vs x86 and it's due to some other peculiarity of Raspbian? I hope this makes the question clearer. Currently I only experience this with Raspbian, which is why I am asking here. – Szabolcs May 16 at 15:17
  • Are both systems running the same version of gcc? – user96931 May 16 at 15:22
  • I found this on Github Basically libasan can not guarantee correct work if it's not the first loaded library (which is e.g. the case when /etc/ld.so.preload is not empty). We saw several cases when preloaded libraries caused Asan misbehaviors and decided to add this check to prevent them in future. Maybe we should add a flag for users who are willing to take the risk. – user96931 May 16 at 15:26
  • @user96931 No, not the same version of gcc. On Raspbian I use the default 6.3. I was able to test on x86_64 with gcc 5, 7 and 8, but unfortunately not yet 6. There is a small chance that it's the gcc version difference, but it seems unlikely ... – Szabolcs May 16 at 15:27
2

Basically libasan can not guarantee correct work if it's not the first loaded library (which is e.g. the case when /etc/ld.so.preload is not empty). There were several cases when preloaded libraries caused Asan misbehaviors and this check -- ==1966==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. was added to prevent them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.