llvm submittal 41050 created for powerpc64 C++ exception code generation: ld r2,40(r1) missing or skipped before bl __cxa_begin_catch code

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

llvm submittal 41050 created for powerpc64 C++ exception code generation: ld r2,40(r1) missing or skipped before bl __cxa_begin_catch code

freebsd-toolchain mailing list
I have submitted:

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

for the clang 8 code generation problem of
no code for setting r2 appropriately before
the:

bl . . . <00000018.plt_call.__cxa_begin_catch@@CXXABI_1.3>

in unoptimized code ( no -O ). For the -O2 code:

ld r2,40(r1)

is present but is being skipped by the libunwind return
to the code: it returns to the just-following bl
instruction (like above) instead.

In both cases:

(gdb) x/32i  0x100007c0
  0x100007c0 <00000018.plt_call.__cxa_begin_catch@@CXXABI_1.3>: std     r2,40(r1)
  0x100007c4 <00000018.plt_call.__cxa_begin_catch@@CXXABI_1.3+4>: ld      r12,-32608(r2)
  0x100007c8 <00000018.plt_call.__cxa_begin_catch@@CXXABI_1.3+8>: mtctr   r12
  0x100007cc <00000018.plt_call.__cxa_begin_catch@@CXXABI_1.3+12>: ld      r11,-32592(r2)
  0x100007d0 <00000018.plt_call.__cxa_begin_catch@@CXXABI_1.3+16>: ld      r2,-32600(r2)
  0x100007d4 <00000018.plt_call.__cxa_begin_catch@@CXXABI_1.3+20>: bctr
  0x100007d8 <00000018.plt_call.__cxa_begin_catch@@CXXABI_1.3+24>: .long 0x0
  0x100007dc <00000018.plt_call.__cxa_begin_catch@@CXXABI_1.3+28>: .long 0x0
. . .

with an inappropriate r2 value leads to jumping to
inappropriate places.

The example source code was:

#include <exception>

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



Note:

This is from investigations of head -r345044 using
WITH_LLVM_LIBUNWIND= on powerpc64.


===
Mark Millard
marklmi at yahoo.com
( dsl-only.net went
away in early 2018-Mar)

_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-toolchain
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: llvm submittal 41050 created for powerpc64 C++ exception code generation: ld r2,40(r1) missing or skipped before bl __cxa_begin_catch code

freebsd-toolchain mailing list


On 2019-Mar-12, at 22:08, Mark Millard <marklmi at yahoo.com> wrote:

> I have submitted:
>
> https://bugs.llvm.org//show_bug.cgi?id=41050
>
> for the clang 8 code generation problem of
> no code for setting r2 appropriately before
> the:
>
> bl . . . <00000018.plt_call.__cxa_begin_catch@@CXXABI_1.3>
>
> in unoptimized code ( no -O ). For the -O2 code:
>
> ld r2,40(r1)
>
> is present but is being skipped by the libunwind return
> to the code: it returns to the just-following bl
> instruction (like above) instead.
>
> In both cases:
>
> (gdb) x/32i  0x100007c0
>  0x100007c0 <00000018.plt_call.__cxa_begin_catch@@CXXABI_1.3>: std     r2,40(r1)
>  0x100007c4 <00000018.plt_call.__cxa_begin_catch@@CXXABI_1.3+4>: ld      r12,-32608(r2)
>  0x100007c8 <00000018.plt_call.__cxa_begin_catch@@CXXABI_1.3+8>: mtctr   r12
>  0x100007cc <00000018.plt_call.__cxa_begin_catch@@CXXABI_1.3+12>: ld      r11,-32592(r2)
>  0x100007d0 <00000018.plt_call.__cxa_begin_catch@@CXXABI_1.3+16>: ld      r2,-32600(r2)
>  0x100007d4 <00000018.plt_call.__cxa_begin_catch@@CXXABI_1.3+20>: bctr
>  0x100007d8 <00000018.plt_call.__cxa_begin_catch@@CXXABI_1.3+24>: .long 0x0
>  0x100007dc <00000018.plt_call.__cxa_begin_catch@@CXXABI_1.3+28>: .long 0x0
> . . .
>
> with an inappropriate r2 value leads to jumping to
> inappropriate places.
>
> The example source code was:
>
> #include <exception>
>
> int main(void)
> {
>   try { throw std::exception(); }
>   catch (std::exception& e) {}
>   return 0;
> }
>
>
>
> Note:
>
> This is from investigations of head -r345044 using
> WITH_LLVM_LIBUNWIND= on powerpc64.
>

The discussion on https://bugs.llvm.org//show_bug.cgi?id=41050
indicates that the ld r2,??? to restore the value appropriate to
the a.out code in my example should be happening via the library
holding libunwind's code instead of the ld executing in the
a.out code.

So: thus far it is viewed as a libunwind issue instead of a clang
one.


===
Mark Millard
marklmi at yahoo.com
( dsl-only.net went
away in early 2018-Mar)

_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-toolchain
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: llvm submittal 41050 created for powerpc64 C++ exception code generation: ld r2,40(r1) missing or skipped before bl __cxa_begin_catch code

freebsd-toolchain mailing list
[Looks like insufficient DW_CFA_* information is output and so
insufficient code is executed.]

On 2019-Mar-14, at 18:23, Mark Millard <marklmi at yahoo.com> wrote:

> . . . (dropping history) . . .

(As usual, the history shows that I've been figuring things
out as I go.)

As I've looked into the code, operation, dwarfdump -v -v -v -F
output and the like, it seems to come down to:

A) Clang is not writing out any DW_CFA_* information for r2
   anywhere. It needs to in at least some places and that
   information needs to be interpreted by the libunwind code.

B) Clang may not be writing out various other DW_CFA_* things
   (and matching instructions in many cases) for some or all
   of:

   _Unwind_Resume
   _Unwind_Resume_or_Rethrow
   _Unwind_RaiseException
   _Unwind_FrocedUnwind

[I'm sure of (A) but am less sure of what (B)'s details should
be.]

I did find the DQ_CFA_* related interpreter and its use. Also,
using the likes of,

# export LIBUNWIND_PRINT_UNWINDING=""
# export LIBUNWIND_PRINT_APIS=""
# export LIBUNWIND_PRINT_DWARF=""
# ./a.out

gives a good idea what is being done and in what sequence
for the unwind activity.

It may be that some of (B) might be because of libunwind
not using sufficient built-ins that control part of how
the code is generated for the likes of those 4 special
routines (including, possibly, some of the DW_CFA_*
information).

For (A) in some or all the of (B) routines, it may be that
some r2 related DF_CFA_* material needs to be written out
even absent local code in order to tied things together. An
example might be for picking up r2's value as it was before
the plt_call code targeting _Unwind_Resume was executed in
the a.out code.

===
Mark Millard
marklmi at yahoo.com
( dsl-only.net went
away in early 2018-Mar)

_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-toolchain
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: llvm submittal 41050 created for powerpc64 C++ exception code generation: ld r2,40(r1) missing or skipped before bl __cxa_begin_catch code

freebsd-toolchain mailing list

https://reviews.llvm.org/D59694 is a review for a fix for
WITH_LLVM_LIBUNWIND= when WITHOUT_LIB32= is in use.

Why not lib32 as well? Well . . .

As stands:

A) 32-bit powerpc llvm-libunwind fails to build.

and:

B) If it did build, it would have the r2 (TOC) problem even after
   this patch.

Attempting to fix (B) without fixing (A) would leave an untestable
fix. So it is unlikely that covering (B) should be part of the 41050
defect's effort, even though powerpc64 FreeBSD will still be
incomplete for libunwind support overall.

===
Mark Millard
marklmi at yahoo.com
( dsl-only.net went
away in early 2018-Mar)

_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-toolchain
To unsubscribe, send any mail to "[hidden email]"