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

rustc aborts when there is a compilation failure on FreeBSD and OpenBSD #43575

Open
dumbbell opened this issue Jul 31, 2017 · 9 comments
Open
Labels
C-bug Category: This is a bug. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. O-freebsd Operating system: FreeBSD O-openbsd Operating system: OpenBSD T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@dumbbell
Copy link
Contributor

When there is a compilation failure, the Rust compiler aborts with the following output:

$ rustc invalid.rs
error: requires at least a format string argument
 --> invalid.rs:2:5
  |
2 |     print!()
  |     ^^^^^^^^
  |
  = note: this error originates in a macro outside of the current crate

error: aborting due to previous error(s)

fatal runtime error: failed to initiate panic, error 5
Abort trap (core dumped)

I used the following invalid source file:

fn main() {
    print!()
}

Here is the backtrace:

(gdb) r
Starting program: /var/ports/obj/mnt/home/dumbbell/Projects/freebsd/ports/SVN/lang/rust/work/rustc-1.19.0-src/build/x86_64-unknown-freebsd/stage2/bin/rustc invalid.rs
[New LWP 101467 of process 50322]
error: requires at least a format string argument
 --> invalid.rs:2:5
  |
2 |     print!()
  |     ^^^^^^^^
  |
  = note: this error originates in a macro outside of the current crate

error: aborting due to previous error(s)

fatal runtime error: failed to initiate panic, error 5

Thread 2 received signal SIGABRT, Aborted.
[Switching to LWP 101467 of process 50322]
0x0000000801be1b5a in thr_kill () from /lib/libc.so.7
(gdb) bt
#0  0x0000000801be1b5a in thr_kill () from /lib/libc.so.7
#1  0x0000000801be1b24 in __raise (s=6) at /mnt/home/dumbbell/Projects/freebsd/src/SVN/head/lib/libc/gen/raise.c:52
#2  0x0000000801be1a99 in abort () at /mnt/home/dumbbell/Projects/freebsd/src/SVN/head/lib/libc/stdlib/abort.c:65
#3  0x000000080184b5a1 in std::sys_common::util::abort::h1ff3fd43e3f3affb () from /var/ports/obj/mnt/home/dumbbell/Projects/freebsd/ports/SVN/lang/rust/work/rustc-1.19.0-src/build/x86_64-unknown-freebsd/stage2/bin/../lib/libstd-8923652fdd8a524a.so
#4  0x0000000801859f2e in rust_panic () from /var/ports/obj/mnt/home/dumbbell/Projects/freebsd/ports/SVN/lang/rust/work/rustc-1.19.0-src/build/x86_64-unknown-freebsd/stage2/bin/../lib/libstd-8923652fdd8a524a.so
#5  0x0000000801859e96 in std::panicking::rust_panic_with_hook::h625888e35dbc23f2 () from /var/ports/obj/mnt/home/dumbbell/Projects/freebsd/ports/SVN/lang/rust/work/rustc-1.19.0-src/build/x86_64-unknown-freebsd/stage2/bin/../lib/libstd-8923652fdd8a524a.so
#6  0x0000000805b69a29 in std::panicking::begin_panic::h334ae91969cdd553 () from /var/ports/obj/mnt/home/dumbbell/Projects/freebsd/ports/SVN/lang/rust/work/rustc-1.19.0-src/build/x86_64-unknown-freebsd/stage2/lib/../lib/librustc_errors-7119f0b402b67ca4.so
#7  0x0000000805b84415 in rustc_errors::Handler::abort_if_errors::h0cb792d8711ba104 () from /var/ports/obj/mnt/home/dumbbell/Projects/freebsd/ports/SVN/lang/rust/work/rustc-1.19.0-src/build/x86_64-unknown-freebsd/stage2/lib/../lib/librustc_errors-7119f0b402b67ca4.so
#8  0x0000000801515cd8 in rustc_driver::driver::phase_2_configure_and_expand::_$u7b$$u7b$closure$u7d$$u7d$::hed28ccb91f2e1d2f ()
   from /var/ports/obj/mnt/home/dumbbell/Projects/freebsd/ports/SVN/lang/rust/work/rustc-1.19.0-src/build/x86_64-unknown-freebsd/stage2/bin/../lib/librustc_driver-d90bd0899d4860c7.so
#9  0x000000080150df01 in rustc_driver::driver::phase_2_configure_and_expand::hfdbd55e50731a10a ()
   from /var/ports/obj/mnt/home/dumbbell/Projects/freebsd/ports/SVN/lang/rust/work/rustc-1.19.0-src/build/x86_64-unknown-freebsd/stage2/bin/../lib/librustc_driver-d90bd0899d4860c7.so
#10 0x00000008015058f7 in rustc_driver::driver::compile_input::ha42b7de34a40dbc4 () from /var/ports/obj/mnt/home/dumbbell/Projects/freebsd/ports/SVN/lang/rust/work/rustc-1.19.0-src/build/x86_64-unknown-freebsd/stage2/bin/../lib/librustc_driver-d90bd0899d4860c7.so
#11 0x0000000801550877 in rustc_driver::run_compiler::h166e93bfe8677c78 () from /var/ports/obj/mnt/home/dumbbell/Projects/freebsd/ports/SVN/lang/rust/work/rustc-1.19.0-src/build/x86_64-unknown-freebsd/stage2/bin/../lib/librustc_driver-d90bd0899d4860c7.so
#12 0x00000008014744dc in std::sys_common::backtrace::__rust_begin_short_backtrace::h31e6f5e865f4c216 ()
   from /var/ports/obj/mnt/home/dumbbell/Projects/freebsd/ports/SVN/lang/rust/work/rustc-1.19.0-src/build/x86_64-unknown-freebsd/stage2/bin/../lib/librustc_driver-d90bd0899d4860c7.so
#13 0x0000000801865907 in __rust_maybe_catch_panic () from /var/ports/obj/mnt/home/dumbbell/Projects/freebsd/ports/SVN/lang/rust/work/rustc-1.19.0-src/build/x86_64-unknown-freebsd/stage2/bin/../lib/libstd-8923652fdd8a524a.so
#14 0x000000080149a2e1 in _$LT$F$u20$as$u20$alloc..boxed..FnBox$LT$A$GT$$GT$::call_box::h8348efc58e17166f ()
   from /var/ports/obj/mnt/home/dumbbell/Projects/freebsd/ports/SVN/lang/rust/work/rustc-1.19.0-src/build/x86_64-unknown-freebsd/stage2/bin/../lib/librustc_driver-d90bd0899d4860c7.so
#15 0x0000000801858948 in std::sys::imp::thread::Thread::new::thread_start::h40165c228796f269 () from /var/ports/obj/mnt/home/dumbbell/Projects/freebsd/ports/SVN/lang/rust/work/rustc-1.19.0-src/build/x86_64-unknown-freebsd/stage2/bin/../lib/libstd-8923652fdd8a524a.so
#16 0x00000008067e8bc5 in thread_start (curthread=0x80b8a2b00) at /mnt/home/dumbbell/Projects/freebsd/src/SVN/head/lib/libthr/thread/thr_create.c:289
#17 0x0000000000000000 in ?? ()
Backtrace stopped: Cannot access memory at address 0x7fffdfffe000

As you can see in the paths, this is with Rust 1.19.0. The same happens with previous versions, so this isn't a regression (or not a recent one).

In the example, Rust was compiled with Clang 4.0.0, but the bundled LLVM was used.

When I compile and run a program which panics, the panic looks to be handled correctly:

fn main() {
    panic!()
}
$ RUST_BACKTRACE=1 ./panic 
thread 'main' panicked at 'explicit panic', panic.rs:2
stack backtrace:
   0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
   1: std::sys_common::backtrace::_print
   2: std::panicking::default_hook::{{closure}}
   3: std::panicking::default_hook
   4: std::panicking::rust_panic_with_hook
   5: std::panicking::begin_panic
   6: panic::main
   7: __rust_maybe_catch_panic
   8: std::rt::lang_start
   9: main
  10: _start

I don't know how to debug this further. I tried with debuginfo = true and debuginfo-lines = true in config.toml, but then the problem vanishes. I'm willing to help but I would like some pointers to where to look :-)

@Mark-Simulacrum Mark-Simulacrum added C-bug Category: This is a bug. O-freebsd Operating system: FreeBSD labels Aug 3, 2017
@semarie
Copy link
Contributor

semarie commented Aug 7, 2017

I have the same problem with OpenBSD if I switch from stdc++ to libc++ and libc++abi.

Under this configuration (libc++), the compilation of rustc is done right, but several tests failed, specially in failing tests (compile-fail or parse-fail tests for example).

A simple way to reproduce the error is to run rustc -v: the compiler will crash.

$ rustc -vV
rustc 1.19.0
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-openbsd
release: 1.19.0
LLVM version: 4.0

$ rustc -v
error: no input filename given

fatal runtime error: failed to initiate panic, error 5
Abort trap (core dumped)

The error is correctly reported ("no input filename given"), but just after rustc die due to internal panic error.

I am suspecting a problem between rust and libc++ regarding unwinding. It could be a rustc problem as a libc++/libc++abi problem.

Please note that all unitary tests on panicking/unwinding passes.

Running via gdb, with unwind debugging:

$ gdb -args rustc -v
GNU gdb (GDB) 7.12.1
(gdb) set environment LIBUNWIND_PRINT_UNWINDING=1 LIBUNWIND_PRINT_APIS=1
(gdb) run
Starting program: /data/semarie/repos/openbsd/ports/pobj/rust-1.19.0/build-amd64/build/x86_64-unknown-openbsd/stage2/bin/rustc -v
error: no input filename given

libuwind: unwind_phase1(ex_ojb=0x1f1d1d5a7000): pc=0x1f1ccb1d9ce4, start_ip=0x1f1ccb1d9c70, func=__rust_start_panic, lsda=0x0, personality=0x0
libuwind: unwind_phase1(ex_ojb=0x1f1d1d5a7000): pc=0x1f1ccb1cd529, start_ip=0x1f1ccb1cd520, func=.anonymous., lsda=0x0, personality=0x0
libuwind: unwind_phase1(ex_ojb=0x1f1d1d5a7000): pc=0x1f1ccb1cd4e6, start_ip=0x1f1ccb1cd330, func=_ZN3std9panicking20rust_panic_with_hook17hf2d11de5f905222bE, lsda=0x1f1ccb382c3c, personality=0x1f1ccb1d97a0
libuwind: unwind_phase1(ex_ojb=0x1f1d1d5a7000): calling personality function 0x1f1ccb1d97a0
libuwind: unwind_phase1(ex_ojb=0x1f1d1d5a7000): _URC_CONTINUE_UNWIND
libuwind: unwind_phase1(ex_ojb=0x1f1d1d5a7000): pc=0x1f1d7cc32d78, start_ip=0x1f1d7cc32d60, func=.anonymous., lsda=0x0, personality=0x0
libuwind: unwind_phase1(ex_ojb=0x1f1d1d5a7000): pc=0x1f1d7ce2953d, start_ip=0x1f1d7ce29350, func=_ZN5rustc7session11early_error17h0187f9fdb6331d60E, lsda=0x1f1d7d156c98, personality=0x1f1ccb1d97a0
libuwind: unwind_phase1(ex_ojb=0x1f1d1d5a7000): calling personality function 0x1f1ccb1d97a0
libuwind: unwind_phase1(ex_ojb=0x1f1d1d5a7000): _URC_CONTINUE_UNWIND
libuwind: unwind_phase1(ex_ojb=0x1f1d1d5a7000): pc=0x1f1d108ebe6d, start_ip=0x1f1d108e9a10, func=_ZN93_$LT$rustc_driver..RustcDefaultCalls$u20$as$u20$rustc_driver..CompilerCalls$LT$$u27$a$GT$$GT$8no_input17hc57ca5476db31dacE, lsda=0x1f1d10a7ad9c, personality=0x1f1ccb1d97a0
libuwind: unwind_phase1(ex_ojb=0x1f1d1d5a7000): calling personality function 0x1f1ccb1d97a0
libuwind: unwind_phase1(ex_ojb=0x1f1d1d5a7000): _URC_CONTINUE_UNWIND
libuwind: unwind_phase1(ex_ojb=0x1f1d1d5a7000): pc=0x1f1d108e77ef, start_ip=0x1f1d108e7330, func=_ZN12rustc_driver12run_compiler17h8fb3410f76685058E, lsda=0x1f1d10a7a9d4, personality=0x1f1ccb1d97a0
libuwind: unwind_phase1(ex_ojb=0x1f1d1d5a7000): calling personality function 0x1f1ccb1d97a0
libuwind: unwind_phase1(ex_ojb=0x1f1d1d5a7000): _URC_CONTINUE_UNWIND
libuwind: unwind_phase1(ex_ojb=0x1f1d1d5a7000): unw_step() reached bottom => _URC_END_OF_STACK
fatal runtime error: failed to initiate panic, error 5
[New thread 259044]

Thread 2 received signal SIGABRT, Aborted.
[Switching to thread 259044]
thrkill () at -:3
3       -: No such file or directory.
(gdb) bt
#0  thrkill () at -:3
#1  0x00001f1d2ddb11ad in _libc_abort () at /usr/src/lib/libc/stdlib/abort.c:52
#2  0x00001f1ccb1bed31 in std::sys_common::util::abort::h076c0bb8451af0e6 () from /data/semarie/repos/openbsd/ports/pobj/rust-1.19.0/build-amd64/build/x86_64-unknown-openbsd/stage2/lib/libstd-2ce1d6a76eafdd05.so
#3  0x00001f1ccb1cd57e in rust_panic () from /data/semarie/repos/openbsd/ports/pobj/rust-1.19.0/build-amd64/build/x86_64-unknown-openbsd/stage2/lib/libstd-2ce1d6a76eafdd05.so
#4  0x00001f1ccb1cd4e6 in std::panicking::rust_panic_with_hook::hf2d11de5f905222b () from /data/semarie/repos/openbsd/ports/pobj/rust-1.19.0/build-amd64/build/x86_64-unknown-openbsd/stage2/lib/libstd-2ce1d6a76eafdd05.so
#5  0x00001f1d7cc32d78 in std::panicking::begin_panic::h6afedfaffc3f9d2e () from /data/semarie/repos/openbsd/ports/pobj/rust-1.19.0/build-amd64/build/x86_64-unknown-openbsd/stage2/lib/librustc-011439a32a903962.so
#6  0x00001f1d7ce2953d in rustc::session::early_error::h0187f9fdb6331d60 () from /data/semarie/repos/openbsd/ports/pobj/rust-1.19.0/build-amd64/build/x86_64-unknown-openbsd/stage2/lib/librustc-011439a32a903962.so
#7  0x00001f1d108ebe6d in _$LT$rustc_driver..RustcDefaultCalls$u20$as$u20$rustc_driver..CompilerCalls$LT$$u27$a$GT$$GT$::no_input::hc57ca5476db31dac () from /data/semarie/repos/openbsd/ports/pobj/rust-1.19.0/build-amd64/build/x86_64-unknown-openbsd/stage2/lib/librustc_driver-052b8dbae020bc96.so
#8  0x00001f1d108e77ef in rustc_driver::run_compiler::h8fb3410f76685058 () from /data/semarie/repos/openbsd/ports/pobj/rust-1.19.0/build-amd64/build/x86_64-unknown-openbsd/stage2/lib/librustc_driver-052b8dbae020bc96.so
#9  0x00001f1d1080c26c in std::sys_common::backtrace::__rust_begin_short_backtrace::hd612f4587ecab5f6 () from /data/semarie/repos/openbsd/ports/pobj/rust-1.19.0/build-amd64/build/x86_64-unknown-openbsd/stage2/lib/librustc_driver-052b8dbae020bc96.so
#10 0x00001f1ccb1d9c27 in __rust_maybe_catch_panic () from /data/semarie/repos/openbsd/ports/pobj/rust-1.19.0/build-amd64/build/x86_64-unknown-openbsd/stage2/lib/libstd-2ce1d6a76eafdd05.so
#11 0x00001f1d10831c61 in _$LT$F$u20$as$u20$alloc..boxed..FnBox$LT$A$GT$$GT$::call_box::hff49756066bea45b () from /data/semarie/repos/openbsd/ports/pobj/rust-1.19.0/build-amd64/build/x86_64-unknown-openbsd/stage2/lib/librustc_driver-052b8dbae020bc96.so
#12 0x00001f1ccb1cc1a8 in std::sys::imp::thread::Thread::new::thread_start::h4f30b5b9f427f3ca () from /data/semarie/repos/openbsd/ports/pobj/rust-1.19.0/build-amd64/build/x86_64-unknown-openbsd/stage2/lib/libstd-2ce1d6a76eafdd05.so
#13 0x00001f1d8fca15ce in _rthread_start (v=0x0) at /usr/src/lib/librthread/rthread.c:115
#14 0x00001f1d2dd5dbdb in __tfork_thread () at /usr/src/lib/libc/arch/amd64/sys/tfork_thread.S:75
#15 0x0000000000000000 in ?? ()
(gdb) 

@Mark-Simulacrum could you update the tags please ?

@Mark-Simulacrum Mark-Simulacrum added I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. O-openbsd Operating system: OpenBSD labels Aug 8, 2017
@semarie
Copy link
Contributor

semarie commented Aug 8, 2017

I confirm that building with debuginfo=true is enough to make to crash disappear.

@dumbbell dumbbell changed the title rustc aborts when there is a compilation failure on FreeBSD rustc aborts when there is a compilation failure on FreeBSD and OpenBSD Aug 8, 2017
@semarie
Copy link
Contributor

semarie commented Aug 8, 2017

Using a rustc binary compiled with debuginfo=true, I traced the program using libunwind debugging.

$ gdb -args rustc -v
GNU gdb (GDB) 7.12.1
(gdb) set environment LIBUNWIND_PRINT_UNWINDING=1 LIBUNWIND_PRINT_APIS=1
(gdb) run
libuwind: unwind_phase1(ex_ojb=0x7642d21b980): pc=0x763ec2fae54, start_ip=0x763ec2fade0, func=__rust_start_panic, lsda=0x0, personality=0x0
libuwind: unwind_phase1(ex_ojb=0x7642d21b980): pc=0x763ec2ee56d, start_ip=0x763ec2ee560, func=.anonymous., lsda=0x0, personality=0x0
libuwind: unwind_phase1(ex_ojb=0x7642d21b980): pc=0x763ec2ee517, start_ip=0x763ec2ee340, func=_ZN3std9panicking20rust_panic_with_hook17hf2d11de5f905222bE, lsda=0x763ec4a69c8, personality=0x763ec2fa8f0
libuwind: unwind_phase1(ex_ojb=0x7642d21b980): calling personality function 0x763ec2fa8f0
libuwind: unwind_phase1(ex_ojb=0x7642d21b980): _URC_CONTINUE_UNWIND
libuwind: unwind_phase1(ex_ojb=0x7642d21b980): pc=0x763600148fb, start_ip=0x763600148e0, func=.anonymous., lsda=0x0, personality=0x0
libuwind: unwind_phase1(ex_ojb=0x7642d21b980): pc=0x763601fefcb, start_ip=0x763601fedd0, func=_ZN5rustc7session11early_error17h0187f9fdb6331d60E, lsda=0x76360521010, personality=0x763ec2fa8f0
libuwind: unwind_phase1(ex_ojb=0x7642d21b980): calling personality function 0x763ec2fa8f0
libuwind: unwind_phase1(ex_ojb=0x7642d21b980): _URC_CONTINUE_UNWIND
libuwind: unwind_phase1(ex_ojb=0x7642d21b980): pc=0x7637809902a, start_ip=0x76378096e30, func=_ZN93_$LT$rustc_driver..RustcDefaultCalls$u20$as$u2
0$rustc_driver..CompilerCalls$LT$$u27$a$GT$$GT$8no_input17hc57ca5476db31dacE, lsda=0x76378226ca4, personality=0x763ec2fa8f0
libuwind: unwind_phase1(ex_ojb=0x7642d21b980): calling personality function 0x763ec2fa8f0
libuwind: unwind_phase1(ex_ojb=0x7642d21b980): _URC_CONTINUE_UNWIND
libuwind: unwind_phase1(ex_ojb=0x7642d21b980): pc=0x76378094e44, start_ip=0x763780949e0, func=_ZN12rustc_driver12run_compiler17h8fb3410f76685058E, lsda=0x763782268dc, personality=0x763ec2fa8f0
libuwind: unwind_phase1(ex_ojb=0x7642d21b980): calling personality function 0x763ec2fa8f0
libuwind: unwind_phase1(ex_ojb=0x7642d21b980): _URC_CONTINUE_UNWIND
libuwind: unwind_phase1(ex_ojb=0x7642d21b980): pc=0x76377fc01b2, start_ip=0x76377fbfe40, func=.anonymous., lsda=0x76378211190, personality=0x763ec2fa8f0
libuwind: unwind_phase1(ex_ojb=0x7642d21b980): calling personality function 0x763ec2fa8f0
libuwind: unwind_phase1(ex_ojb=0x7642d21b980): _URC_CONTINUE_UNWIND
libuwind: unwind_phase1(ex_ojb=0x7642d21b980): pc=0x763ec2fad9b, start_ip=0x763ec2fad80, func=__rust_maybe_catch_panic, lsda=0x763ec4a6be0, personality=0x763ec2fa8f0
libuwind: unwind_phase1(ex_ojb=0x7642d21b980): calling personality function 0x763ec2fa8f0
libuwind: unwind_phase1(ex_ojb=0x7642d21b980): _URC_HANDLER_FOUND
libuwind: unwind_phase2(ex_ojb=0x763b3a84880)
libuwind: unwind_phase2(ex_ojb=0x763b3a84880): start_ip=0x763ec2fade0, func=__rust_start_panic, sp=0x7f7ffffc8370, lsda=0x0, personality=0x0
libuwind: unwind_phase2(ex_ojb=0x763b3a84880): start_ip=0x763ec2ee560, func=.anonymous., sp=0x7f7ffffc83c0, lsda=0x0, personality=0x0
libuwind: unwind_phase2(ex_ojb=0x763b3a84880): start_ip=0x763ec2ee340, func=_ZN3std9panicking20rust_panic_with_hook17hf2d11de5f905222bE, sp=0x7f7ffffc8420, lsda=0x763ec4a69c8, personality=0x763ec2fa8f0
libuwind: unwind_phase2(ex_ojb=0x763b3a84880): _URC_CONTINUE_UNWIND
libuwind: unwind_phase2(ex_ojb=0x763b3a84880): start_ip=0x76377fc1510, func=.anonymous., sp=0x7f7ffffc84f0, lsda=0x0, personality=0x0
libuwind: unwind_phase2(ex_ojb=0x763b3a84880): start_ip=0x763780a3a50, func=_ZN12rustc_driver11exit_on_err17h4a90782c564b79d5E, sp=0x7f7ffffc8520, lsda=0x0, personality=0x0
libuwind: unwind_phase2(ex_ojb=0x763b3a84880): start_ip=0x763780a3be0, func=_ZN12rustc_driver4main17hd2323c6d770bec56E, sp=0x7f7ffffc8560, lsda=0x76378227e24, personality=0x763ec2fa8f0
libuwind: unwind_phase2(ex_ojb=0x763b3a84880): _URC_INSTALL_CONTEXT
libuwind: unwind_phase2(ex_ojb=0x763b3a84880): re-entering user code with ip=0x763780a4cab, sp=0x7f7ffffc8560
libuwind: unwind_phase2(ex_ojb=0x763b3a84880)
libuwind: unwind_phase2(ex_ojb=0x763b3a84880): start_ip=0x763780a3be0, func=_ZN12rustc_driver4main17hd2323c6d770bec56E, sp=0x7f7ffffc8560, lsda=0x76378227e24, personality=0x763ec2fa8f0
libuwind: unwind_phase2(ex_ojb=0x763b3a84880): _URC_CONTINUE_UNWIND
libuwind: unwind_phase2(ex_ojb=0x763b3a84880): start_ip=0x763ec2fad80, func=__rust_maybe_catch_panic, sp=0x7f7ffffc8a80, lsda=0x763ec4a6be0, personality=0x763ec2fa8f0
libuwind: unwind_phase2(ex_ojb=0x763b3a84880): _URC_INSTALL_CONTEXT
libuwind: unwind_phase2(ex_ojb=0x763b3a84880): re-entering user code with ip=0x763ec2fada6, sp=0x7f7ffffc8a80
[Inferior 1 (process 99116) exited with code 0145]
(gdb)

the main difference is where libunwind stop to unwind the stack trace.

in bogus one, libunwind found _ZN12rustc_driver12run_compiler17h8fb3410f76685058E and stop (return _URC_END_OF_STACK).

in right one, libunwind found an anonymous function just after, and continue unwinding with __rust_maybe_catch_panic where it founds the handler (and unwinding phase2 could start).

@semarie
Copy link
Contributor

semarie commented Nov 16, 2017

I finally found that i686-unknown-linux-musl, which use also libunwind from LLVM, uses a workaround for the same issue: it uses eliminate_frame_pointer = false in TargetOptions.

This way, all programs compiled with rustc will be compiled with functional unwinding.

For me, it is still a workaround, but it seems to work well.

The problem seems that some information (need usually by libunwind) is missing for anonymous function (unwinding-tables information ?), and with explicit framepointer libunwind is able to compensate this lake of information.

@dumbbell
Copy link
Contributor Author

I confirm that setting eliminate_frame_pointer to false results in a working compiler.

I talked to Ed Maste and Dimitry Andric about the bug in LLVM bugtracker you mentionned and they don't think this is the same problem. Ed told me about Clang's -fexceptions flag which could help. I find little to no informations about it, but I'll play a bit with it.

uqs pushed a commit to freebsd/freebsd-ports that referenced this issue Nov 30, 2017
Before the patch, the default behavior of the compiler was to omit frame
pointers. However, even though it looks fine for the code produced
by the compiler, the compiler itself was broken. When there was a
compilation error, rustc panics to report that error. While handling
that panic, it tries to unwind the stack but fails to do so, which
results in an abort(3).

Here is an example:

    $ rustc hello.rs
    error: invalid reference to argument `0` (no arguments given)
     --> hello.rs:2:5
      |
    2 |     println!("Hello {}")
      |     ^^^^^^^^^^^^^^^^^^^^
      |
      = note: this error originates in a macro outside of the current crate

    error: aborting due to previous error

    fatal runtime error: failed to initiate panic, error 5
    Abort trap (core dumped)

The problem also exists on other systems such as OpenBSD and
i686-unknown-linux-musl. "omit frame pointers" was already disabled for
i686-unknown-linux-musl:
https://github.com/rust-lang/rust/blob/88a28ff6028cf197ed6b4185d8cd4887f05e3e07/src/librustc_back/target/i686_unknown_linux_musl.rs#L22

The patch does the same for *-unknown-freebsd.

See the upstream bug for more informations:
rust-lang/rust#43575


git-svn-id: svn+ssh://svn.freebsd.org/ports/head@455198 35697150-7ecd-e111-bb59-0022644237b5
uqs pushed a commit to freebsd/freebsd-ports that referenced this issue Nov 30, 2017
Before the patch, the default behavior of the compiler was to omit frame
pointers. However, even though it looks fine for the code produced
by the compiler, the compiler itself was broken. When there was a
compilation error, rustc panics to report that error. While handling
that panic, it tries to unwind the stack but fails to do so, which
results in an abort(3).

Here is an example:

    $ rustc hello.rs
    error: invalid reference to argument `0` (no arguments given)
     --> hello.rs:2:5
      |
    2 |     println!("Hello {}")
      |     ^^^^^^^^^^^^^^^^^^^^
      |
      = note: this error originates in a macro outside of the current crate

    error: aborting due to previous error

    fatal runtime error: failed to initiate panic, error 5
    Abort trap (core dumped)

The problem also exists on other systems such as OpenBSD and
i686-unknown-linux-musl. "omit frame pointers" was already disabled for
i686-unknown-linux-musl:
https://github.com/rust-lang/rust/blob/88a28ff6028cf197ed6b4185d8cd4887f05e3e07/src/librustc_back/target/i686_unknown_linux_musl.rs#L22

The patch does the same for *-unknown-freebsd.

See the upstream bug for more informations:
rust-lang/rust#43575
@bdrewery
Copy link
Contributor

It seems like this workaround no longer works on FreeBSD but I'm not sure.

@bdrewery
Copy link
Contributor

Actually it does work, will submit a PR for it.

bdrewery added a commit to bdrewery/rust that referenced this issue Feb 24, 2018
kennytm added a commit to kennytm/rust that referenced this issue Feb 25, 2018
…, r=eddyb

Workaround abort(2) on compilation error on FreeBSD.

Same problem as OpenBSD, tracking bug rust-lang#43575.

@semarie @dumbbell
bdrewery added a commit to bdrewery/rust that referenced this issue Mar 9, 2018
bdrewery added a commit to bdrewery/rust that referenced this issue Mar 14, 2018
Same problem as OpenBSD, tracking bug rust-lang#43575.

Backport from rust-lang#48494
@jonas-schievink jonas-schievink added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Nov 22, 2019
@cemeyer
Copy link

cemeyer commented Jan 1, 2021

Is this issue resolved now? I see:

error: aborting due to 5 previous errors; 1 warning emitted

error: build failed

And no fatal runtime error or abort trap. FreeBSD 13ish, rust-nightly 1.49.

If it's resolved, let's close it! Thanks.

@nagisa
Copy link
Member

nagisa commented Jun 26, 2021

The bugzilla issue referenced in the code that works around this problem (https://bugs.llvm.org/show_bug.cgi?id=30879) has been fixed. Could anyone test with the workaround reverted?

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jul 26, 2021
…petrochenkov

freebsd remove compiler workaround.

related issue rust-lang#43575
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. O-freebsd Operating system: FreeBSD O-openbsd Operating system: OpenBSD T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants