<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - powerpc64 exceptions: code sequence calling __cxa_begin_catch is missing "ld r2,40(r1)""
   href="https://bugs.llvm.org/show_bug.cgi?id=41050">41050</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>powerpc64 exceptions: code sequence calling __cxa_begin_catch is missing "ld r2,40(r1)"
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>8.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Other
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>FreeBSD
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>release blocker
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>marklmi26-fbsd@yahoo.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>[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.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>