google / sanitizers

AddressSanitizer, ThreadSanitizer, MemorySanitizer
Other
11.41k stars 1.03k forks source link

Unable to get line numbers using address sanitizer in stack traces #1248

Open akhikolla opened 4 years ago

akhikolla commented 4 years ago

Hello everyone, I'm trying to get AddressSanitizer to produce line numbers in its stack traces even after setting symbolizer flags. export ASAN_OPTIONS=symbol_line=1 export ASAN_SYMBOLIZER_PATH=/usr/local/bin/llvm-symbolizer it doesn't display line numbers I am using clang++ to compile my code and used - O1 -g and -fno-omit-frame-pointer

compile line: clang++ -O1 -g -fsanitize=address -fno-omit-frame-pointer -I${R_HOME}/include -I/home/akhila/deepstate/src/include -I/usr/lib/R/site-library/Rcpp/include -I/usr/lib/R/site-library/RInside/include -I/home/akhila/R/RcppDeepState/inst/include/ binseg_normal_DeepState_TestHarness.cpp -o binseg_normal_DeepState_TestHarness.o -c

I get the following stack traces without any line numbers. Can someone please help me how to get line numbers working: It shows me a read memory access error but not exactly where it occurred. image

image

Using memory sanitizer gives me the same: image

kcc commented 4 years ago

Please start form a simple test case (single .c file, injected bug, like this)

If you don't see the line numbers there, something is wrong with your asan installation/setup. If you see the lines there, but not in your large program, more likely you have a problem in your build system (e.g. it strips the binary at the late stage).

BTW, I don't know what export ASAN_OPTIONS=symbol_line=1 is

akhikolla commented 4 years ago

Thanks for the quick response. image image

I get the following when I run the function which you asked to me run. Still, no line numbers that I can see. So you think I have an issue with installation? Should I reinstall ASAN?

export ASAN_OPTIONS=symbol_line=1 -- so workaround I saw online

kcc commented 4 years ago

something is clearly broken in your installation. Do you have llvm-symbolizer in PATH?

There is not such option export ASAN_OPTIONS=symbol_line=1. There is export ASAN_OPTIONS=symbolize=1, but it's the default anyway, you don't need to use it.

akhikolla commented 4 years ago

I tried to install llvm again and used export ASAN_SYMBOLIZER_PATH=/usr/local/bin/llvm-symbolizer

And where exactly will the symbolized path be /usr/bin/llvm-symbolizer-6.0? or /usr/lib/llvm-6.0/bin

image It shows me a warning saying : ==4628==WARNING: invalid path to external symbolizer! ==4628==WARNING: Failed to use and restart external symbolizer!

What can I do about it? what's the problem with the setup how can I make it work?

kcc commented 4 years ago

try to make sure that when you type llvm-symbolizer it runs, i.e. the path to it is in PATH and the binary itself is named exactly like this, and not e.g. llvm-symbolizer-8

akhikolla commented 4 years ago

When I enter llvm-symbolizer on the console it does nothing. Does that mean the llvm-symbolizer is not in its path? If so what am I supposed to do? I tried to install a newer version of llvm and tried again, installed libasan-4 again for my gcc version 7.5. Still no line numbers or file names. I work on Linux 18.04 and any system compatibility issues?

kcc commented 4 years ago

llvm-symbolizer on the console it does nothing - that's expected. You can try llvm-symbolizer -help to see that it works.

Try this:

clang++ -g -fsanitize=address use-after-free.cc && ./a.out 

On my machine it prints something like

    #0 0x4cb44c in main .../use-after-free.cc:8:11

In your case, for some reason I don't yet understand, you see

    #0 0x4cb44c  (/path/to/a.out+0x4cb44c)

Now, try symbolizing that frame manually:

% llvm-symbolizer -e ./a.out 0x4cb44c
main
/path/to/use-after-free.cc:8:11

Do you see the same?

Also, try this:

% addr2line -e ./a.out 0x4cb44c

Next time you provide the output, please provide it as text inside triple backticks

   like this
akhikolla commented 4 years ago

Thanks a lot that resolved the Issue but I keep getting this new error:

SUMMARY: AddressSanitizer: SEGV /build/glibc-OTsEL5/glibc-2.27/string/../sysdeps/x86_64/multiarch/strlen-avx2.S:59 ==3351==ABORTING

Is there any meaning for these kind of error when using address sanitizer?

simonemainardi commented 3 years ago

FWIW, not having llvm-symbolizer in the PATH was the cause of the issue (Ubuntu16.04). Solved with

simone@devel:/usr/bin$ sudo ln -s ../lib/llvm-3.8/bin/llvm-symbolizer llvm-symbolizer

There were versioned but likely only the exact name was searched

llvm-symbolizer-3.8  llvm-symbolizer-6.0