Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PowerPC generic trampoline doesn't handle exceptions properly #7396

Closed
NattyNarwhal opened this issue Mar 3, 2018 · 1 comment · Fixed by #7431
Closed

PowerPC generic trampoline doesn't handle exceptions properly #7396

NattyNarwhal opened this issue Mar 3, 2018 · 1 comment · Fixed by #7431

Comments

@NattyNarwhal
Copy link
Contributor

Steps to Reproduce

  1. Run the "exceptions" regression test in mono/mini
  2. Watch the stack trace.

Isolated:

using System;

public class Offending {
        public static int i;

        static Offending() {
                throw new Exception("Broken");
        }

        public static void Hello() {
                Console.WriteLine(i);
        }
}

public class Entry {
        public static void Main() {
                Offending.Hello();
        }
}

Current Behavior

The runtime bombs out, either with a SIGSEGV on Linux, or SIGILL on AIX. (because it tries to execute invalid opcodes from the null page)

Expected Behavior

The test should pass by handling exceptions properly.

This behaviour is because the PPC (and also from what I read, the SPARC and MIPS) trampoline code doesn't handle exceptions at all, unlike say, AMD64. (z seems to, but doesn't check for thread interrupts?)

@lewurm was working on a patch to fix this, but it doesn't work yet.

On which platforms did you notice this

[ ] macOS
[X] Linux
[ ] Windows
[X] AIX

Version Used:

Mono JIT compiler version 5.13.0 (master/e7ba41d Fri Mar  2 20:27:25 EST 2018)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       altstack
        Notifications: epoll
        Architecture:  ppc
        Disabled:      none
        Misc:          softdebug
        Interpreter:   yes
        GC:            sgen (concurrent by default)

Stacktrace

Test run: image=/home/calvin/mono/mono/mini/exceptions.exe, opts=
Stacktrace:

  at <unknown> <0xffffffff>
  at Tests.test_0_exception_in_cctor () [0x00006] in <ef453223541145b7af18554d739ea5b0>:0
/proc/self/maps:
10000000-10420000 r-xp 00000000 08:03 413981                             /home/calvin/mono/mono/mini/mono-sgen
10420000-10430000 r--p 00410000 08:03 413981                             /home/calvin/mono/mono/mini/mono-sgen
10430000-10480000 rw-p 00420000 08:03 413981                             /home/calvin/mono/mono/mini/mono-sgen
10480000-10c60000 rw-p 00000000 00:00 0                                  [heap]
40000000000-40000030000 r-xp 00000000 08:03 377186                       /lib64/ld-2.11.3.so
40000030000-40000040000 rw-p 00020000 08:03 377186                       /lib64/ld-2.11.3.so
40000040000-40000060000 r-xp 00000000 00:00 0                            [vdso]
40000060000-40000070000 r--p 00000000 08:03 683138                       /usr/lib/locale/en_US.utf8/LC_IDENTIFICATION
40000070000-40000080000 r--s 00000000 08:03 673571                       /usr/lib64/gconv/gconv-modules.cache
40000080000-40000090000 r--p 00000000 08:03 700322                       /usr/lib/locale/en_US.utf8/LC_MEASUREMENT
40000090000-400000a0000 r--p 00000000 08:03 696608                       /usr/lib/locale/en_US.utf8/LC_TELEPHONE
400000a0000-40000150000 r-xp 00000000 08:03 376879                       /lib64/power6/libm-2.11.3.so
40000150000-40000170000 rw-p 000a0000 08:03 376879                       /lib64/power6/libm-2.11.3.so
40000170000-40000180000 r-xp 00000000 08:03 376883                       /lib64/power6/librt-2.11.3.so
40000180000-40000190000 rw-p 00000000 08:03 376883                       /lib64/power6/librt-2.11.3.so
40000190000-400001a0000 r-xp 00000000 08:03 376846                       /lib64/libdl-2.11.3.so
400001a0000-400001b0000 rw-p 00000000 08:03 376846                       /lib64/libdl-2.11.3.so
400001b0000-400001d0000 r-xp 00000000 08:03 376881                       /lib64/power6/libpthread-2.11.3.so
400001d0000-400001e0000 r--p 00010000 08:03 376881                       /lib64/power6/libpthread-2.11.3.so
400001e0000-400001f0000 rw-p 00020000 08:03 376881                       /lib64/power6/libpthread-2.11.3.so
400001f0000-40000200000 rw-p 00000000 00:00 0
40000200000-400003c0000 r-xp 00000000 08:03 376876                       /lib64/power6/libc-2.11.3.so
400003c0000-400003e0000 rw-p 001b0000 08:03 376876                       /lib64/power6/libc-2.11.3.so
400003e0000-400003f0000 rw-p 00000000 00:00 0
400003f0000-40000400000 r--p 00000000 08:03 682136                       /usr/lib/locale/en_US.utf8/LC_ADDRESS
40000400000-40000410000 r--p 00000000 08:03 696625                       /usr/lib/locale/en_US.utf8/LC_NAME
40000410000-40000420000 r--p 00000000 08:03 696617                       /usr/lib/locale/en_US.utf8/LC_PAPER
40000420000-40000430000 r--p 00000000 08:03 689671                       /usr/lib/locale/en_US.utf8/LC_MESSAGES/SYS_LC_MESSAGES
40000430000-40000440000 r--p 00000000 08:03 683139                       /usr/lib/locale/en_US.utf8/LC_MONETARY
40000440000-40000560000 r--p 00000000 08:03 700326                       /usr/lib/locale/en_US.utf8/LC_COLLATE
40000560000-40000570000 r--p 00000000 08:03 683140                       /usr/lib/locale/en_US.utf8/LC_TIME
40000570000-40000580000 r--p 00000000 08:03 696643                       /usr/lib/locale/en_US.utf8/LC_NUMERIC
40000580000-400005c0000 r--p 00000000 08:03 696650                       /usr/lib/locale/en_US.utf8/LC_CTYPE
400005c0000-40000610000 rw-p 00000000 00:00 0
40000610000-40000620000 r--p 00000000 00:00 0
40000620000-40000630000 ---p 00000000 00:00 0
40000630000-40000730000 rwxp 00000000 00:00 0
40000730000-40000740000 rw-s 00000000 00:10 34847                        /dev/shm/mono.4601
40000740000-40000750000 rw-p 00000000 00:00 0
40000750000-400007a0000 ---p 00000000 00:00 0
400007a0000-40000c20000 rw-p 00000000 00:00 0
40000c20000-40000c30000 ---p 00000000 00:00 0
40000c30000-40002020000 rw-p 00000000 00:00 0
40002020000-40002030000 r--p 00000000 08:03 414010                       /home/calvin/mono/mono/mini/aot-tests.exe
40002030000-40002430000 r--p 00000000 08:03 733358                       /home/calvin/mono/mcs/class/lib/net_4_x-linux/mscorlib.dll
40002430000-40002530000 rwxp 00000000 00:00 0
40002530000-40002760000 rw-p 00000000 00:00 0
40002760000-40002770000 ---p 00000000 00:00 0
40002770000-40002790000 ---p 00000000 00:00 0
40002790000-40002980000 rw-p 00000000 00:00 0
40002980000-400029a0000 ---p 00000000 00:00 0
400029a0000-40002b90000 rw-p 00000000 00:00 0
40002b90000-40002bb0000 ---p 00000000 00:00 0
40002bb0000-40002d90000 rw-p 00000000 00:00 0
40002d90000-40002da0000 r--p 00000000 08:03 414017                       /home/calvin/mono/mono/mini/objects.exe
40002da0000-40002db0000 rw-p 00000000 00:00 0
40002db0000-40002dd0000 ---p 00000000 00:00 0
40002dd0000-40002fc0000 rw-p 00000000 00:00 0
40002fc0000-40003290000 r--p 00000000 08:03 733362                       /home/calvin/mono/mcs/class/lib/net_4_x-linux/System.dll
40003290000-400033a0000 r--p 00000000 08:03 733372                       /home/calvin/mono/mcs/class/lib/net_4_x-linux/System.Core.dll
400033a0000-400034a0000 rwxp 00000000 00:00 0
400034a0000-400034b0000 r--p 00000000 08:03 414011                       /home/calvin/mono/mono/mini/basic.exe
400034b0000-400035b0000 rwxp 00000000 00:00 0
400035b0000-400035c0000 r--p 00000000 08:03 414012                       /home/calvin/mono/mono/mini/basic-float.exe
400035c0000-400035d0000 r--p 00000000 08:03 414013                       /home/calvin/mono/mono/mini/basic-long.exe
400035d0000-400035e0000 r--p 00000000 08:03 414014                       /home/calvin/mono/mono/mini/basic-calls.exe
400035e0000-400036e0000 rwxp 00000000 00:00 0
400036e0000-400036f0000 r--p 00000000 08:03 414015                       /home/calvin/mono/mono/mini/builtin-types.exe
400036f0000-40003700000 r--p 00000000 08:03 414016                       /home/calvin/mono/mono/mini/gshared.exe
40003700000-40003710000 rw-p 00000000 00:00 0
40003710000-40003720000 r--p 00000000 08:03 414018                       /home/calvin/mono/mono/mini/arrays.exe
40003720000-40003760000 rw-p 00000000 00:00 0
40003760000-40003770000 r--p 00000000 08:03 414019                       /home/calvin/mono/mono/mini/basic-math.exe
40003770000-40003780000 r--p 00000000 08:03 414020                       /home/calvin/mono/mono/mini/exceptions.exe
40003780000-40003790000 rw-p 00000000 00:00 0
40003800000-40003900000 rw-p 00000000 00:00 0
40003900000-40004000000 rwxp 00000000 00:00 0
40004000000-40004040000 rw-p 00000000 00:00 0
40004040000-40008000000 ---p 00000000 00:00 0
40008000000-40008030000 rw-p 00000000 00:00 0
40008030000-4000c000000 ---p 00000000 00:00 0
4000c000000-4000c100000 rw-p 00000000 00:00 0
4000c100000-4000c200000 rwxp 00000000 00:00 0
4000c200000-4000c300000 rw-p 00000000 00:00 0
4000c300000-4000c400000 rwxp 00000000 00:00 0
ffff8360000-ffff9390000 rw-p 00000000 00:00 0                            [stack]

Native stacktrace:

        /home/calvin/mono/mono/mini/mono() [0x100bf678]
        /home/calvin/mono/mono/mini/mono() [0x1011c9f0]
        /home/calvin/mono/mono/mini/mono() [0x10037d08]
        [0x40000040448]
        [0x400006701d4]
        [0x4000c37f0d0]
        /home/calvin/mono/mono/mini/mono() [0x1008339c]
        /home/calvin/mono/mono/mini/mono(mono_main-0x3c7c78) [0x10085860]
        /home/calvin/mono/mono/mini/mono() [0x1002f234]
        /lib64/power6/libc.so.6(+0x5016c) [0x4000025016c]
        /lib64/power6/libc.so.6(__libc_start_main-0x17998c) [0x4000025038c]

Debug info from gdb:

Missing separate debuginfo for /lib64/power6/libm.so.6
Try: zypper install -C "debuginfo(build-id)=65df7c5078ab97a47b42aa2f87b773abf0781d9c"
Missing separate debuginfo for /lib64/power6/librt.so.1
Try: zypper install -C "debuginfo(build-id)=6e39a25fe83e562267168bf70c36e1aec8992a20"
Missing separate debuginfo for /lib64/libdl.so.2
Try: zypper install -C "debuginfo(build-id)=3cf8cd65b29b4cbedf55c63c3e8713cec7a03e82"
Missing separate debuginfo for /lib64/power6/libpthread.so.0
Try: zypper install -C "debuginfo(build-id)=ee8de43250e90a99d8215141f1918e44b4eb83ba"
[New LWP 4666]
[New LWP 4665]
[New LWP 4664]
[New LWP 4663]
[New LWP 4662]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/power6/libthread_db.so.1".
Missing separate debuginfo for /lib64/power6/libc.so.6
Try: zypper install -C "debuginfo(build-id)=0b5c04e84b0b05392c50a3fa596936c36dee037d"
Missing separate debuginfo for /lib64/ld64.so.1
Try: zypper install -C "debuginfo(build-id)=d4953a1040e2502a4562c6953e6258d78f315a34"
0x00000400001c7690 in .__libc_waitpid () from /lib64/power6/libpthread.so.0
  Id   Target Id         Frame
  6    Thread 0x4000101f1c0 (LWP 4662) "mono" 0x00000400001c1c64 in .pthread_cond_wait () from /lib64/power6/libpthread.so.0
  5    Thread 0x4000296f1c0 (LWP 4663) "mono" 0x00000400001c4e80 in .sem_wait () from /lib64/power6/libpthread.so.0
  4    Thread 0x40002b7f1c0 (LWP 4664) "mono" 0x00000400001c21ec in .pthread_cond_timedwait () from /lib64/power6/libpthread.so.0
  3    Thread 0x40002d8f1c0 (LWP 4665) "mono" 0x00000400001c50a0 in .sem_timedwait () from /lib64/power6/libpthread.so.0
  2    Thread 0x40002faf1c0 (LWP 4666) "mono" 0x00000400001c50a0 in .sem_timedwait () from /lib64/power6/libpthread.so.0
* 1    Thread 0x400001f12b0 (LWP 4601) "mono" 0x00000400001c7690 in .__libc_waitpid () from /lib64/power6/libpthread.so.0

Thread 6 (Thread 0x4000101f1c0 (LWP 4662)):
#0  0x00000400001c1c64 in .pthread_cond_wait () from /lib64/power6/libpthread.so.0
#1  0x0000000010322b0c in mono_os_cond_wait (mutex=0x10489650 <lock>, cond=0x10489698 <work_cond>) at ../../mono/utils/mono-os-mutex.h:173
#2  get_work (job=<synthetic pointer>, do_idle=<synthetic pointer>, work_context=<synthetic pointer>, worker_index=<optimized out>) at sgen-thread-pool.c:165
#3  thread_func (data=<optimized out>) at sgen-thread-pool.c:196
#4  0x00000400001bc6ac in .start_thread () from /lib64/power6/libpthread.so.0
#5  0x0000040000328b1c in .__clone () from /lib64/power6/libc.so.6

Thread 5 (Thread 0x4000296f1c0 (LWP 4663)):
#0  0x00000400001c4e80 in .sem_wait () from /lib64/power6/libpthread.so.0
#1  0x000000001029d3cc in mono_os_sem_wait (flags=MONO_SEM_FLAGS_ALERTABLE, sem=0x1047ab18 <finalizer_sem>) at ../../mono/utils/mono-os-semaphore.h:209
#2  mono_coop_sem_wait (flags=MONO_SEM_FLAGS_ALERTABLE, sem=0x1047ab18 <finalizer_sem>) at ../../mono/utils/mono-coop-semaphore.h:43
#3  finalizer_thread (unused=<optimized out>) at gc.c:900
#4  0x00000000102563d8 in start_wrapper_internal (stack_ptr=<optimized out>, start_info=0x0) at threads.c:1063
#5  start_wrapper (data=0x10503aa0) at threads.c:1123
#6  0x00000400001bc6ac in .start_thread () from /lib64/power6/libpthread.so.0
#7  0x0000040000328b1c in .__clone () from /lib64/power6/libc.so.6

Thread 4 (Thread 0x40002b7f1c0 (LWP 4664)):
#0  0x00000400001c21ec in .pthread_cond_timedwait () from /lib64/power6/libpthread.so.0
#1  0x00000000103347f4 in mono_os_cond_timedwait (cond=0x1048a0d0 <sleep_cond>, mutex=0x1048a0a8 <sleep_mutex>, timeout_ms=<optimized out>) at mono-os-mutex.c:75
#2  0x0000000010340908 in mono_coop_cond_timedwait (cond=0x1048a0d0 <sleep_cond>, mutex=0x1048a0a8 <sleep_mutex>, timeout_ms=500) at ../../mono/utils/mono-coop-mutex.h:102
#3  sleep_interruptable (alerted=0x40002b7e5b0, ms=<optimized out>) at mono-threads.c:1261
#4  mono_thread_info_sleep (ms=<optimized out>, alerted=0x40002b7e5b0) at mono-threads.c:1293
#5  0x00000000102bb0fc in monitor_thread (unused=<optimized out>) at threadpool-worker-default.c:703
#6  0x00000000102563d8 in start_wrapper_internal (stack_ptr=<optimized out>, start_info=0x0) at threads.c:1063
#7  start_wrapper (data=0x1052d470) at threads.c:1123
#8  0x00000400001bc6ac in .start_thread () from /lib64/power6/libpthread.so.0
#9  0x0000040000328b1c in .__clone () from /lib64/power6/libc.so.6

Thread 3 (Thread 0x40002d8f1c0 (LWP 4665)):
#0  0x00000400001c50a0 in .sem_timedwait () from /lib64/power6/libpthread.so.0
#1  0x00000000102ba480 in mono_os_sem_timedwait (flags=MONO_SEM_FLAGS_ALERTABLE, timeout_ms=12680, sem=0x1047b348 <worker+72>) at ../../mono/utils/mono-os-semaphore.h:258
#2  mono_coop_sem_timedwait (sem=0x1047b348 <worker+72>, flags=MONO_SEM_FLAGS_ALERTABLE, timeout_ms=12680) at ../../mono/utils/mono-coop-semaphore.h:57
#3  worker_park () at threadpool-worker-default.c:391
#4  worker_thread (unused=<optimized out>) at threadpool-worker-default.c:483
#5  0x00000000102563d8 in start_wrapper_internal (stack_ptr=<optimized out>, start_info=0x0) at threads.c:1063
#6  start_wrapper (data=0x1052d470) at threads.c:1123
#7  0x00000400001bc6ac in .start_thread () from /lib64/power6/libpthread.so.0
#8  0x0000040000328b1c in .__clone () from /lib64/power6/libc.so.6

Thread 2 (Thread 0x40002faf1c0 (LWP 4666)):
#0  0x00000400001c50a0 in .sem_timedwait () from /lib64/power6/libpthread.so.0
#1  0x00000000102ba480 in mono_os_sem_timedwait (flags=MONO_SEM_FLAGS_ALERTABLE, timeout_ms=48141, sem=0x1047b348 <worker+72>) at ../../mono/utils/mono-os-semaphore.h:258
#2  mono_coop_sem_timedwait (sem=0x1047b348 <worker+72>, flags=MONO_SEM_FLAGS_ALERTABLE, timeout_ms=48141) at ../../mono/utils/mono-coop-semaphore.h:57
#3  worker_park () at threadpool-worker-default.c:391
#4  worker_thread (unused=<optimized out>) at threadpool-worker-default.c:483
#5  0x00000000102563d8 in start_wrapper_internal (stack_ptr=<optimized out>, start_info=0x0) at threads.c:1063
#6  start_wrapper (data=0x40004020190) at threads.c:1123
#7  0x00000400001bc6ac in .start_thread () from /lib64/power6/libpthread.so.0
#8  0x0000040000328b1c in .__clone () from /lib64/power6/libc.so.6

Thread 1 (Thread 0x400001f12b0 (LWP 4601)):
#0  0x00000400001c7690 in .__libc_waitpid () from /lib64/power6/libpthread.so.0
#1  0x00000000100bf7b8 in mono_handle_native_crash (signal=0x1035c560 "SIGSEGV", ctx=<optimized out>, info=<optimized out>) at mini-exceptions.c:2722
#2  0x000000001011c9f0 in mono_arch_handle_altstack_exception (sigctx=0x40002742780, siginfo=0x40002742e58, fault_addr=<optimized out>, stack_ovf=<optimized out>) at exceptions-ppc.c:656
#3  0x0000000010037d08 in mono_sigsegv_signal_handler (_dummy=<optimized out>, _info=0x40002742e58, context=0x40002742780) at mini-runtime.c:3130
#4  <signal handler called>
#5  0x00000400006701d4 in ?? ()
#6  0x000004000c37f0d0 in ?? ()
#7  0x000000001008339c in mini_regression_step (image=image@entry=0x10ba5b40, verbose=verbose@entry=0, total_run=total_run@entry=0xffff938c2c0, total=total@entry=0xffff938c1f0, opt_flags=<optimized out>, timer=timer@entry=0x10ba4ef0, domain=domain@entry=0x104a25e0) at driver.c:404
#8  0x0000000010085860 in mini_regression (total_run=0xffff938c2c0, verbose=<optimized out>, image=0x10ba5b40) at driver.c:525
#9  mini_regression_list (images=<optimized out>, count=<optimized out>, verbose=0) at driver.c:553
#10 mono_main (argc=<optimized out>, argv=<optimized out>) at driver.c:2292
#11 0x000000001002f234 in mono_main_with_options (argv=0xffff938c958, argc=22) at main.c:50
#12 main (argc=22, argv=0xffff938c958) at main.c:398

=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================
@NattyNarwhal NattyNarwhal changed the title PowerPC JIT doesn't handle exceptions properly PowerPC generic trampoline doesn't handle exceptions properly Mar 3, 2018
@NattyNarwhal
Copy link
Contributor Author

FWIW, an easy pattern that triggers this is wrapper libraries like System.Drawing, where something as trivial as not having a library goes from an expected DllNotFoundException to a SIGSEGV/SIGILL like above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants