[cfe-dev] Link error compiling with -faddress-sanitizer (___asan_init undefined)

Alexander Potapenko glider at google.com
Tue Mar 13 12:25:06 PDT 2012


Sean, can you try to compile and link your program in two separate steps, i.e.:

clang -faddress-sanitizer test.c -c -v
clang -faddress-sanitizer test.o -v

On Tue, Mar 13, 2012 at 11:22 PM, Kostya Serebryany <kcc at google.com> wrote:
> For some reason the asan run-time library does not get added to the link
> command.
> It worked for me yesterday, but today my only Mac box is down, so I can't
> check immediately.
> The code that should add the run-time library is
> in tools/clang/lib/Driver/ToolChains.cpp (search for address_sanitizer),
> I'll try to check it later today once my Mac box is up.
>
> Does your clang build contain library called "libclang_rt.asan_osx.a"? You
> can probably try adding it manually.
>
> --kcc
>
>
>
>
> On Tue, Mar 13, 2012 at 12:12 PM, Sean McBride <sean at rogue-research.com>
> wrote:
>>
>> On Tue, 13 Mar 2012 12:03:09 -0700, Kostya Serebryany said:
>>
>> >Could you please run the same command line with "-v" to see what
>> > libraries
>> >get linked in?
>>
>> Kostya,
>>
>> Thanks for the fast reply.  Here is the whole thing:
>>
>> builder9:~ builder$ clang -O1 -g -faddress-sanitizer
>> -fno-omit-frame-pointer ~/Desktop/test.c -v
>> clang version 3.1 (trunk 152633)
>> Target: x86_64-apple-darwin10.8.0
>> Thread model: posix
>>  "/Users/builder/llvm/llvm-rel-bin-install/bin/clang-3.1" -cc1 -triple
>> x86_64-apple-macosx10.6.0 -emit-obj -disable-free -disable-llvm-verifier
>> -main-file-name test.c -pic-level 1 -mdisable-fp-elim -masm-verbose
>> -munwind-tables -target-cpu core2 -v -g -resource-dir
>> /Users/builder/llvm/llvm-rel-bin-install/bin/../lib/clang/3.1
>> -fmodule-cache-path
>> /var/folders/So/SoDaKVGNF1GdaUhl-VCLoE+++TI/-Tmp-/clang-module-cache -O1
>> -fdebug-compilation-dir /Users/builder -ferror-limit 19 -fmessage-length 179
>> -faddress-sanitizer -stack-protector 1 -mstackrealign -fblocks
>> -fobjc-dispatch-method=mixed -fobjc-default-synthesize-properties
>> -fdiagnostics-show-option -fcolor-diagnostics -o
>> /var/folders/So/SoDaKVGNF1GdaUhl-VCLoE+++TI/-Tmp-/test-cnlcGw.o -x c
>> /Users/builder/Desktop/test.c
>> clang -cc1 version 3.1 based upon LLVM 3.1svn default target
>> x86_64-apple-darwin10.8.0
>> #include "..." search starts here:
>> #include <...> search starts here:
>>  /usr/local/include
>>  /Users/builder/llvm/llvm-rel-bin-install/bin/../lib/clang/3.1/include
>>  /usr/include
>>  /System/Library/Frameworks (framework directory)
>>  /Library/Frameworks (framework directory)
>> End of search list.
>>  "/usr/llvm-gcc-4.2/libexec/gcc/i686-apple-darwin10/4.2.1/ld" -dynamic
>> -arch x86_64 -macosx_version_min 10.6.0 -o a.out -lcrt1.10.6.o
>> /var/folders/So/SoDaKVGNF1GdaUhl-VCLoE+++TI/-Tmp-/test-cnlcGw.o
>> /usr/lib/libstdc++.6.dylib -framework CoreFoundation -lSystem
>> Undefined symbols:
>>  "___asan_report_load4", referenced from:
>>      _main in test-cnlcGw.o
>>  "___asan_init", referenced from:
>>      _asan.module_ctor in test-cnlcGw.o
>> ld: symbol(s) not found
>> clang-3: error: linker command failed with exit code 1 (use -v to see
>> invocation)
>>
>>
>>
>



-- 
Alexander Potapenko
Software Engineer
Google Moscow




More information about the cfe-dev mailing list