[llvm-bugs] [Bug 41050] New: powerpc64 exceptions: code sequence calling __cxa_begin_catch is missing "ld r2, 40(r1)"

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Mar 12 21:25:18 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=41050

            Bug ID: 41050
           Summary: powerpc64 exceptions: code sequence calling
                    __cxa_begin_catch is missing "ld r2,40(r1)"
           Product: clang
           Version: 8.0
          Hardware: Other
                OS: FreeBSD
            Status: NEW
          Severity: release blocker
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: marklmi26-fbsd at yahoo.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

[On amd64 something analogous would be a
"release blocker". I'm not sure powerpc64
is ever one. Change teh severity as
needed.]

The example program:

#include <exception>

int main(void)
{
  try { throw std::exception(); }
  catch (std::exception& e) {}
  return 0;
}

The produced code for c++ -g (no -O):

Dump of assembler code for function main():
 0x0000000010000d64 <+0>:       mflr    r0
 0x0000000010000d68 <+4>:       std     r31,-8(r1)
 0x0000000010000d6c <+8>:       std     r0,16(r1)
 0x0000000010000d70 <+12>:      stdu    r1,-160(r1)
 0x0000000010000d74 <+16>:      mr      r31,r1
 0x0000000010000d78 <+20>:      li      r3,0
 0x0000000010000d7c <+24>:      stw     r3,148(r31)
 0x0000000010000d80 <+28>:      li      r3,8
 0x0000000010000d84 <+32>:      bl      0x100007a0
<00000018.plt_call.__cxa_allocate_exception@@CXXABI_1.3>
 0x0000000010000d88 <+36>:      ld      r2,40(r1)
 0x0000000010000d8c <+40>:      std     r3,112(r31)
 0x0000000010000d90 <+44>:      bl      0x10000e00
<std::exception::exception()>
 0x0000000010000d94 <+48>:      nop
 0x0000000010000d98 <+52>:      ld      r4,-32728(r2)
 0x0000000010000d9c <+56>:      nop
 0x0000000010000da0 <+60>:      ld      r5,-32720(r2)
 0x0000000010000da4 <+64>:      ld      r3,112(r31)
 0x0000000010000da8 <+68>:      bl      0x10000800
<00000018.plt_call.__cxa_throw@@CXXABI_1.3>
 0x0000000010000dac <+72>:      ld      r2,40(r1)
 0x0000000010000db0 <+76>:      b       0x10000df4 <main()+144>
 0x0000000010000db4 <+80>:      mr      r5,r4
 0x0000000010000db8 <+84>:      std     r3,136(r31)
 0x0000000010000dbc <+88>:      stw     r5,132(r31)
 0x0000000010000dc0 <+92>:      b       0x10000dc4 <main()+96>
 0x0000000010000dc4 <+96>:      ld      r3,136(r31)
 0x0000000010000dc8 <+100>:     bl      0x100007c0
<00000018.plt_call.__cxa_begin_catch@@CXXABI_1.3>
 0x0000000010000dcc <+104>:     ld      r2,40(r1)
 0x0000000010000dd0 <+108>:     std     r3,120(r31)
 0x0000000010000dd4 <+112>:     bl      0x100007e0
<00000018.plt_call.__cxa_end_catch@@CXXABI_1.3>
 0x0000000010000dd8 <+116>:     ld      r2,40(r1)
 0x0000000010000ddc <+120>:     li      r3,0
 0x0000000010000de0 <+124>:     addi    r1,r1,160
 0x0000000010000de4 <+128>:     ld      r0,16(r1)
 0x0000000010000de8 <+132>:     ld      r31,-8(r1)
 0x0000000010000dec <+136>:     mtlr    r0
 0x0000000010000df0 <+140>:     blr
 0x0000000010000df4 <+144>:     .long 0x0
 0x0000000010000df8 <+148>:     .long 0x0
 0x0000000010000dfc <+152>:     .long 0x0
End of assembler dump.

Manually setting r2 based on 40(r1) before the the bl to __cxa_begin_catch
allows the program to work (its a WITH_LLVM_LIBUNWIND based context).

libunwind's code returns to 0x0000000010000db4 .

By contrast -O2 has an "ld r2,40(r1)" but in that context the return is
to the instruction after it (the bl instruction):

(gdb) disass main
Dump of assembler code for function main():
  0x0000000010000d64 <+0>:      mflr    r0
  0x0000000010000d68 <+4>:      std     r31,-8(r1)
  0x0000000010000d6c <+8>:      std     r0,16(r1)
  0x0000000010000d70 <+12>:     stdu    r1,-128(r1)
  0x0000000010000d74 <+16>:     mr      r31,r1
  0x0000000010000d78 <+20>:     li      r3,8
  0x0000000010000d7c <+24>:     bl      0x100007a0
<00000018.plt_call.__cxa_allocate_exception@@CXXABI_1.3>
  0x0000000010000d80 <+28>:     ld      r2,40(r1)
  0x0000000010000d84 <+32>:     nop
  0x0000000010000d88 <+36>:     ld      r4,-32728(r2)
  0x0000000010000d8c <+40>:     addi    r4,r4,16
  0x0000000010000d90 <+44>:     std     r4,0(r3)
  0x0000000010000d94 <+48>:     nop
  0x0000000010000d98 <+52>:     nop
  0x0000000010000d9c <+56>:     ld      r4,-32720(r2)
  0x0000000010000da0 <+60>:     ld      r5,-32712(r2)
  0x0000000010000da4 <+64>:     bl      0x10000800
<00000018.plt_call.__cxa_throw@@CXXABI_1.3>
  0x0000000010000da8 <+68>:     ld      r2,40(r1)
  0x0000000010000dac <+72>:     bl      0x100007c0
<00000018.plt_call.__cxa_begin_catch@@CXXABI_1.3>
  0x0000000010000db0 <+76>:     ld      r2,40(r1)
  0x0000000010000db4 <+80>:     bl      0x100007e0
<00000018.plt_call.__cxa_end_catch@@CXXABI_1.3>
  0x0000000010000db8 <+84>:     ld      r2,40(r1)
  0x0000000010000dbc <+88>:     li      r3,0
  0x0000000010000dc0 <+92>:     addi    r1,r1,128
  0x0000000010000dc4 <+96>:     ld      r0,16(r1)
  0x0000000010000dc8 <+100>:    ld      r31,-8(r1)
  0x0000000010000dcc <+104>:    mtlr    r0
  0x0000000010000dd0 <+108>:    blr
  0x0000000010000dd4 <+112>:    .long 0x0
  0x0000000010000dd8 <+116>:    .long 0x0
  0x0000000010000ddc <+120>:    .long 0x0
End of assembler dump.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190313/2ee35056/attachment-0001.html>


More information about the llvm-bugs mailing list