[Bug backtrace/24605] New: Stack trace broken when noreturn optimization is done

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[Bug backtrace/24605] New: Stack trace broken when noreturn optimization is done

alahay01 at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=24605

            Bug ID: 24605
           Summary: Stack trace broken when noreturn optimization is done
           Product: gdb
           Version: 7.11
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: backtrace
          Assignee: unassigned at sourceware dot org
          Reporter: ololjiiu373fds at 163 dot com
  Target Milestone: ---

Created attachment 11791
  --> https://sourceware.org/bugzilla/attachment.cgi?id=11791&action=edit
libc __assert_fail

gcc removes dead code after a function call to function with noreturn
attribute, so instruction pointer register (PC) will point to the place after
this call which may not belong to this function. I found this with a simple
assert(0) on my aarch64 platform with following configuration:

Distribution: openwrt
gcc: aarch64-openwrt-linux-gcc 5.3.0
glibc: libc-2.22

gdb can't display backtrace correctly:
(gdb) bt  
#0  0x0000007fb785cd90 in raise () from /lib/libc.so.6 <- $pc
#1  0x0000007fb785e028 in abort () from /lib/libc.so.6 <- $x30
#2  0x0000007fb7857048 in ?? () from /lib/libc.so.6    <- $sp + 8
#3  0x000000000044e010 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

(gdb) info reg
x0             0x0      0
x1             0x3883   14467
x2             0x6      6
x3             0x3883   14467
x4             0x7fb7fef000     548547784704
x5             0x7fb7fef6f0     548547786480
x6             0x0      0
x7             0x0      0
x8             0x83     131
x9             0x7f7f7f7f7f7f7f7f       9187201950435737471
x10            0xfefefefefeff092d       -72340172838074067
x11            0x7f7f7f7f7f7f7f7f       9187201950435737471
x12            0x101010101010101        72340172838076673
x13            0x203a74656b636f73       2322296536805109619
x14            0x6f69747265737341       8028075845441778497
x15            0x58     88
x16            0x7fb7951010     548540846096
x17            0x7fb785d590     548539848080
x18            0x0      0
x19            0x7fb7952000     548540850176
x20            0x7fb7fef000     548547784704
x21            0x7fffffeea8     549755809448
x22            0x1      1
---Type <return> to continue, or q <return> to quit---
x23            0x44e078 4513912
x24            0x0      0
x25            0x0      0
x26            0x0      0
x27            0x0      0
x28            0x0      0
x29            0x7fffffee70     549755809392
x30            0x7fb785e028     548539850792
sp             0x7fffffee70     0x7fffffee70
pc             0x7fb785cd90     0x7fb785cd90 <raise+84>
cpsr           0x20000000       536870912
fpsr           0x10     16
fpcr           0x0      0

(gdb) x/512xg $sp
0x7fffffee70:   0x0000007fffffefd0      0x0000007fb7857048
0x7fffffee80:   0x0000007fb7737000      0x0000007fb7927cb1
0x7fffffee90:   0x000000000044e010      0x000000000000006b
0x7fffffeea0:   0x0000007fffffefd0      0x0000000000000020
0x7fffffeeb0:   0x0000000000000000      0x0000000000000000
0x7fffffeec0:   0x0000000000000000      0x0000000000000000
0x7fffffeed0:   0x0000000000000000      0x0000000000000000
0x7fffffeee0:   0x0000000000000000      0x0000000000000000
0x7fffffeef0:   0x0000000000000000      0x0000000000000000
0x7fffffef00:   0x0000000000000000      0x0000000000000000
0x7fffffef10:   0x0000000000000000      0x0000000000000000
0x7fffffef20:   0x0000000000000000      0x0000007f00000000
0x7fffffef30:   0x0000007fb7737000      0x0000007fb7927cb1
0x7fffffef40:   0x000000000044e010      0x000000000000006b
0x7fffffef50:   0x000000000044e078      0x0000000000000000
0x7fffffef60:   0x0000000000000000      0x0000000000000000
0x7fffffef70:   0x0000000000000000      0x0000000000000000
0x7fffffef80:   0x0000007fb7952468      0x4010040140100401
0x7fffffef90:   0x0000007fffffefd0      0x0000007fb7856fac
0x7fffffefa0:   0x000000000044e368      0x0000007fb7927cb1
0x7fffffefb0:   0x0000007fffffefd0      0x0000000000000000
0x7fffffefc0:   0x000000000044e078      0x0000007ffffff014
0x7fffffefd0:   0x0000007ffffff020      0x0000007fb7857094
---Type <return> to continue, or q <return> to quit---
0x7fffffefe0:   0x000000000044e078      0x000000000044e010
0x7fffffeff0:   0x000000000000006b      0x000000000044e368
0x7ffffff000:   0x0000000000000000      0x0000000000000000
0x7ffffff010:   0x0000100040100001      0x0000000000483700
0x7ffffff020:   0x0000007ffffff060      0x00000000004323f0
0x7ffffff030:   0x0000000000471660      0x000000000044f088
0x7ffffff040:   0x000000000046e540      0x000000000046e580

I attach two screenshot of disassemble of related functions in glibc.

Some part of memory map:
cat /proc/14467/maps
7fb782d000-7fb793e000 r-xp 00000000 b3:02 314                          
/lib/libc-2.22.so
7fb793e000-7fb794d000 ---p 00111000 b3:02 314                          
/lib/libc-2.22.so
7fb794d000-7fb7951000 r--p 00110000 b3:02 314                          
/lib/libc-2.22.so
7fb7951000-7fb7953000 rw-p 00114000 b3:02 314                          
/lib/libc-2.22.so

--
You are receiving this mail because:
You are on the CC list for the bug.
Reply | Threaded
Open this post in threaded view
|

[Bug backtrace/24605] Stack trace broken when noreturn optimization is done

alahay01 at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=24605

--- Comment #1 from ololjiiu373fds at 163 dot com ---
Created attachment 11792
  --> https://sourceware.org/bugzilla/attachment.cgi?id=11792&action=edit
libc_abort

--
You are receiving this mail because:
You are on the CC list for the bug.
Reply | Threaded
Open this post in threaded view
|

[Bug backtrace/24605] Stack trace broken when noreturn optimization is done

alahay01 at gcc dot gnu.org
In reply to this post by alahay01 at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=24605

--- Comment #2 from ololjiiu373fds at 163 dot com ---
Created attachment 11797
  --> https://sourceware.org/bugzilla/attachment.cgi?id=11797&action=edit
libc_raise

--
You are receiving this mail because:
You are on the CC list for the bug.
Reply | Threaded
Open this post in threaded view
|

[Bug backtrace/24605] Stack trace broken when noreturn optimization is done

alahay01 at gcc dot gnu.org
In reply to this post by alahay01 at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=24605

ololjiiu373fds at 163 dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #3 from ololjiiu373fds at 163 dot com ---
After some investigation, I found that gdb can handle this case and print stack
trace
correctly. Our glibc didn't compile with -funwind-tables and there was no entry
in .eh_frame for __assert_fail and related functions.

--
You are receiving this mail because:
You are on the CC list for the bug.