# gcc/clang address sanitizer



## xibo (Sep 10, 2014)

Hello,

I've tried to build binaries using -fsanitize=address several times in the past using ports and base clang, always resulting in a failure diagnosing something like libasan not found. Now ports' lang/gcc has been updated to 4.8 and address sanitize is mentioned in the commit log, however trying to build in sanitize mode results in the same message clang has been omiting:


```
% cat test.c
#include <stdlib.h>

int main ()
{
  return (EXIT_SUCCESS);
}
% gcc48 -fsanitize=address test.c                
/usr/local/bin/ld: cannot find -lasan
collect2: error: ld returned 1 exit status
% cc -fsanitize=address test.c 
/tmp/test-c5ed86.o: In function `main':
test.c:(.text+0x1a): undefined reference to `__asan_option_detect_stack_use_after_return'
test.c:(.text+0x45): undefined reference to `__asan_stack_malloc_1'
test.c:(.text+0xfc): undefined reference to `__asan_report_store4'
/tmp/test-c5ed86.o: In function `asan.module_ctor':
test.c:(.text+0x179): undefined reference to `__asan_init_v3'
cc: error: linker command failed with exit code 1 (use -v to see invocation)
```

Probably I'm missing something trival, can anyone give me a hint?


----------



## SirDice (Sep 11, 2014)

You probably need to add -L/usr/local/lib and -I/usr/local/include.


----------

