Thread: Macro Help
View Single Post
Old April 19, 2015, 19:02   #9
chris
PosChengband Maintainer
 
Join Date: Jan 2008
Posts: 702
chris is on a distinguished road
Help? I can't seem to figure out why I stopped getting symbols in Address Sanitizer output when using clang as my compiler.

What I am doing:
Code:
./configure CFLAGS=-fsanitize=address LDFLAGS=-fsanitize=address --with-no-install CC=clang-3.5
and in Makefile:
Code:
CFLAGS += -DBUILD_ID=${VERSION} -I. -std=c99 -Wdeclaration-after-statement -O0 -g -fno-omit-frame-pointer
Now, if I drop the CC=clang-3.5 from my configure, and just use gcc, I get symbols. However, my gcc does not do leak detection and clang-3.5 does, so I'd like to be able to use that if possible.

The symbols must be in the executable, since clang barfs out a 25Mb file (versus 9 for gcc). However, I can't figure out what I might be missing.

Thanks for any help!

(FYI: Address sanitizer does not detect out of bounds stuff for arrays inside the middle of structs.)

EDIT: If I do exactly what is suggested here at the top, I don't get symbols either. So, how to get symbols with clang might be my problem:
Code:
> cat leak.c
#include <stdlib.h>

void *p;

int main() {
  p = malloc(7);
  p = 0; // The memory is leaked here.
  return 0;
}
> clang-3.5 -fsanitize=address -g leak.c
> ./a.out

=================================================================
==20475==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 7 byte(s) in 1 object(s) allocated from:
    #0 0x49a13b (/home/chris/Src/poschengband/src/a.out+0x49a13b)
    #1 0x4b79a0 (/home/chris/Src/poschengband/src/a.out+0x4b79a0)
    #2 0x7fcd376ceec4 (/lib/x86_64-linux-gnu/libc.so.6+0x21ec4)

SUMMARY: AddressSanitizer: 7 byte(s) leaked in 1 allocation(s).

EDIT2: Found answer here. Or an answer, anyway. Now I just need to remember to type:
Code:
./poschengband -g -uChris -- -n1 2>&1 | /tmp/asan_symbolize.py | c++filt
whenever I run

EDIT3: Better answer. Install llvm-3.5 package and run
Code:
ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer-3.5 ./poschengband -g -uChris -- -n1
. I'm not sure that's any easier to type, though!

Last edited by chris; April 19, 2015 at 19:47.
chris is offline   Reply With Quote