https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65749

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
Replacing the computation:
    uptr pc = GetPreviousInstructionPc(trace[i]);
with the assignment:
    uptr pc = trace[i];
makes the PC in active frame in the stack trace consistent with the one
reported on the ERROR: AddressSanitizer line, and the (return) addresses in
frames #1 and beyond consistent with those printed by GDB.  This patch however
causes regressions in a number of asan tests due to changes in the line
numbers.  An example is the stack-overflow-1.c test which is reported as
failing due to the change in the faulting line number in the stack trace from
the expected 16 to 13:

FAIL: c-c++-common/asan/stack-overflow-1.c   -O2  output pattern test, is
=================================================================
==14778==ERROR: AddressSanitizer: stack-buffer-overflow on address
0x7fff29383d3a at pc 0x000000400966 bp 0x7fff29383d00 sp 0x7fff29383cf8
READ of size 1 at 0x7fff29383d3a thread T0
    #0 0x400966 in main c-c++-common/asan/stack-overflow-1.c:13
    #1 0x7f1ad7283fe0 in __libc_start_main (/lib64/libc.so.6+0x1ffe0)
    #2 0x4009f5 
(/home/msebor/build/gcc-65479/gcc/testsuite/gcc/stack-overflow-1.exe+0x4009f5)

The line number reported by the patched sanitizer matches the line number
reported by tools like addr2line and readelf --debug-dump=decodedline:

$ addr2line 0x400966
/home/msebor/fsf/gcc-git/gcc/testsuite/c-c++-common/asan/stack-overflow-1.c:13

The complete line program for the test looks like this:

$ readelf  --debug-dump=decodedline a.out
Decoded dump of debug contents of section .debug_line:

CU:
/home/msebor/fsf/gcc-git/libsanitizer/sanitizer_common/sanitizer_stacktrace.h:
File name                            Line number    Starting address

CU:
/home/msebor/fsf/gcc-git/gcc/testsuite/c-c++-common/asan/stack-overflow-1.c:
File name                            Line number    Starting address
stack-overflow-1.c                            13            0x4008f6

stack-overflow-1.c                            15            0x40096e
stack-overflow-1.c                            16            0x400984
stack-overflow-1.c                            17            0x4009d7
stack-overflow-1.c                            13            0x4009dd
stack-overflow-1.c                            18            0x400a21
stack-overflow-1.c                            18            0x400a2e
stack-overflow-1.c                            18            0x400a32
stack-overflow-1.c                            18            0x400a43
stack-overflow-1.c                            18            0x400a47

Reply via email to