This is an archive of the discontinued LLVM Phabricator instance.

[libsanitizer] Handle assembler-generated dwarf info in backtrace
Needs ReviewPublic

Authored by vries on Feb 21 2019, 1:50 AM.

Details

Summary

[ This patch attempts to fix a problem, for which another patch was submitted earlier ( https://reviews.llvm.org/D34149 ). ]

Consider this test-case, which generates a segmentation fault:
...
int
main (void)
{

void *ptr = (void *)0x01;
int value = *((int *) ptr);
return 0;

}
...

Using LD_PRELOAD we can see how libasan handles the segfault:
...
$ LD_PRELOAD=install/lib64/libasan.so ./a.out
...

Focusing just on the backtrace part for main we have:
...

#0 0x4004a6 in main (a.out+0x4004a6)

...
and when compiled with -g, we have instead instead:
...

#0 0x4004a6 in main test.c:5

...

When we compile the test-case to assembly without -g, but compile the
assembly with -g like this:
...
$ gcc test.c -S
$ gcc test.s -gdwarf-2 -c
$ gcc test.o
...
we get this, similar to the case without -g:
...

#0 0x400481 in main (a.out+0x400481)

...

In this case, the executable contains DWARF file and line number information
for the assembly file, but it's not used because the function name is
missing in the DWARF .debug_info.

This patch fixes this, allowing us to get:
...

#0 0x400481 in main test.s:14

...

Diff Detail

Event Timeline

vries created this revision.Feb 21 2019, 1:50 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptFeb 21 2019, 1:50 AM
Herald added subscribers: Restricted Project, llvm-commits, jdoerfert and 2 others. · View Herald Transcript

@vries Thanks for reopen this problem,
by the way,
this is a really hard to face in real world, you have to compile by gcc without debuginfo or write on assembly, and then add debuginfo by "as".