scons clang ASan undefined reference...

2,336 views
Skip to first unread message

leandro moreno

unread,
Aug 8, 2013, 4:42:55 PM8/8/13
to address-...@googlegroups.com
Hello guys. I have a problem when I try to compile a project using scons  (a builder like Cmake).
I try to use clang-3.4 instead of gcc. The project compiles all right, but when is in the link step, the program terminate with error. This is the log:

install/libs/libbiopp.so: undefined reference to `__asan_report_store4'
install/libs/libbiopp.so: undefined reference to `__asan_register_globals'
install/libs/libbiopp.so: undefined reference to `__asan_report_load_n'
install/libs/libbiopp.so: undefined reference to `__asan_report_load4'
install/libs/libbiopp.so: undefined reference to `__asan_report_store8'
install/libs/libbiopp.so: undefined reference to `__asan_unregister_globals'
install/libs/libbiopp.so: undefined reference to `__asan_handle_no_return'
install/libs/libbiopp.so: undefined reference to `__asan_init_v3'
install/libs/libbiopp.so: undefined reference to `__asan_report_load1'
install/libs/libbiopp.so: undefined reference to `__asan_report_store1'
install/libs/libbiopp.so: undefined reference to `__asan_after_dynamic_init'
install/libs/libbiopp.so: undefined reference to `__asan_report_load8'
install/libs/libbiopp.so: undefined reference to `__asan_report_store_n'
install/libs/libbiopp.so: undefined reference to `__asan_before_dynamic_init'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
scons: *** [build/biopp/tests/biopp_test] Error 1
scons: building terminated because of errors.


I tried a lot of things, add flags, remove flags, everything with flags and nothing work. I read that I can fix this adding -libclang_rt.asan-x86_64.a to the linker, but clang can not find the lib. Do you have any suggest? 

I have ubuntu 12.04, clang-3.4.

I hope your answer soon. Thank you.

Dmitry Vyukov

unread,
Aug 8, 2013, 4:46:33 PM8/8/13
to address-sanitizer
Hi,

You need to pass -fsanitize=address flag to the compiler during linking.



--
You received this message because you are subscribed to the Google Groups "address-sanitizer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to address-saniti...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

leandro moreno

unread,
Aug 8, 2013, 4:51:14 PM8/8/13
to address-...@googlegroups.com
Hi Dmitry! I tried that too, and doesn't work =(.

Dmitry Vyukov

unread,
Aug 8, 2013, 5:22:54 PM8/8/13
to address-sanitizer
Can you build a single file this way? I.e. 
$ clang 1.cpp -fsanitize=address -c
$ clang 1.o -fsanitize=address

If not, what error it produces?
If yes, dump compiler invocations during your build and see what is wrong.

Timur Iskhodzhanov

unread,
Aug 9, 2013, 1:14:59 AM8/9/13
to address-...@googlegroups.com

How did you get that version of clang? Did you build it from source?
If so - have you checked out compiler-rt before compiling?

09 авг. 2013 г. 0:42 пользователь "leandro moreno" <moreno.l...@gmail.com> написал:
--

leandro moreno

unread,
Aug 9, 2013, 8:44:02 AM8/9/13
to address-...@googlegroups.com
I get it with the LLVM repository http://llvm.org/apt/. I can build a single file with asan, the problem is when I have to link more than one .o.

Alexey Samsonov

unread,
Aug 9, 2013, 8:49:21 AM8/9/13
to address-...@googlegroups.com

"When linking shared libraries, the AddressSanitizer run-time is not linked, so -Wl,-z,defs may cause link errors (don’t use it with AddressSanitizer)."
--
Alexey Samsonov, MSK

leandro moreno

unread,
Aug 9, 2013, 8:50:36 AM8/9/13
to address-...@googlegroups.com
ld command is called with this params. So I can see that all libraries are good load.

"/usr/bin/ld" -whole-archive /usr/bin/../lib/clang/3.4/lib/linux/libclang_rt.asan-x86_64.a -no-whole-archive -z relro --hash-style=gnu --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.6/crtbegin.o -L/usr/lib/gcc/x86_64-linux-gnu/4.6 -L/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.6/../../.. -L/lib -L/usr/lib hello.o -lpthread -lrt -ldl -export-dynamic -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/4.6/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crtn.o

What is wrong here?

leandro moreno

unread,
Aug 9, 2013, 8:55:24 AM8/9/13
to address-...@googlegroups.com
Yes, I saw that too! But, I don't know how can I take off the -z flag from scons =(. Scons manage that. Sorry for publish a lot of messages.
I added -v flag in my project, and ld has the next params:

 "/usr/bin/ld" -z relro --hash-style=gnu --build-id --eh-frame-hdr -m elf_x86_64 -shared -o build/biopp/libbiopp.so /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.6/crtbeginS.o -Linstall/libs -L/usr/lib/gcc/x86_64-linux-gnu/4.6 -L/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.6/../../.. -L/lib -L/usr/lib -rpath=/home/moreno/fudepan-build/install/libs build/biopp/src/bio_molecular/bio_molecular.os build/biopp/src/bio_molecular/triplets.os build/biopp/src/rna_structure/rna_structure.os -lstdc++ -lm -lgcc_s -lc -lgcc_s /usr/lib/gcc/x86_64-linux-gnu/4.6/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crtn.o

I can not see the asan libraries loaded =(

Alexey Samsonov

unread,
Aug 9, 2013, 9:12:29 AM8/9/13
to address-...@googlegroups.com
On Fri, Aug 9, 2013 at 4:55 PM, leandro moreno <moreno.l...@gmail.com> wrote:
Yes, I saw that too! But, I don't know how can I take off the -z flag from scons =(. Scons manage that. Sorry for publish a lot of messages.
I added -v flag in my project, and ld has the next params:

 "/usr/bin/ld" -z relro --hash-style=gnu --build-id --eh-frame-hdr -m elf_x86_64 -shared -o build/biopp/libbiopp.so /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.6/crtbeginS.o -Linstall/libs -L/usr/lib/gcc/x86_64-linux-gnu/4.6 -L/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.6/../../.. -L/lib -L/usr/lib -rpath=/home/moreno/fudepan-build/install/libs build/biopp/src/bio_molecular/bio_molecular.os build/biopp/src/bio_molecular/triplets.os build/biopp/src/rna_structure/rna_structure.os -lstdc++ -lm -lgcc_s -lc -lgcc_s /usr/lib/gcc/x86_64-linux-gnu/4.6/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crtn.o

I can not see the asan libraries loaded =(

This is fine, ASan library should not be linked into the shared object files. What you should do is to somehow allow your build system to build .so files with unresolved symbols.



--
Alexey Samsonov, MSK

leandro moreno

unread,
Aug 9, 2013, 9:49:44 AM8/9/13
to address-...@googlegroups.com
But if I do an example and I build it by myself, ld take this params, and the libclang_rt.asan is there!

 "/usr/bin/ld" -whole-archive /usr/bin/../lib/clang/3.4/lib/linux/libclang_rt.asan-x86_64.a -no-whole-archive -z relro --hash-style=gnu --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.6/crtbegin.o -L/usr/lib/gcc/x86_64-linux-gnu/4.6 -L/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.6/../../.. -L/lib -L/usr/lib hello.o -lpthread -lrt -ldl -export-dynamic -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/4.6/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crtn.o

leandro moreno

unread,
Aug 9, 2013, 9:58:21 AM8/9/13
to address-...@googlegroups.com
Oh God! Finally I did it! I was setting the -fsanitize=address in the wrong place. Now this compile!!! Thank you very much to you guys. Thank you for the fast answers =).

Alexey Samsonov

unread,
Aug 9, 2013, 10:03:26 AM8/9/13
to address-...@googlegroups.com
Right, ASan runtime is:
* linked into executables (a.out in your example)
* not linked into shared objects (*.so)
Reply all
Reply to author
Forward
0 new messages