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

Allow foreign exceptions to unwind through Rust code and Rust panics to unwind through FFI #65646

Merged
merged 7 commits into from
Nov 3, 2019

Conversation

Amanieu
Copy link
Member

@Amanieu Amanieu commented Oct 21, 2019

This PR fixes interactions between Rust panics and foreign (mainly C++) exceptions.

C++ exceptions (and other FFI exceptions) can now safely unwind through Rust code:

  • The FFI function causing the unwind must be marked with #[unwind(allowed)]. If this is not the case then LLVM may optimize landing pads away with the assumption that they are unreachable.
  • Drop code will be executed as the exception unwinds through the stack, as with a Rust panic.
  • catch_unwind will not catch the exception, instead the exception will silently continue unwinding past it.

Rust panics can now safely unwind through C++ code:

  • C++ destructors will be called as the stack unwinds.
  • The Rust panic can only be caught with catch (...), after which it can be either rethrown or discarded.
  • C++ cannot name the type of the Rust exception object used for unwinding, which means that it can't be caught explicitly or have its contents inspected.

Tests have been added to ensure all of the above works correctly.

Some notes about non-C++ exceptions:

  • pthread_cancel and pthread_exit use unwinding on glibc. This has the same behavior as a C++ exception: destructors are run but it cannot be caught by catch_unwind.
  • longjmp on Windows is implemented using unwinding. Destructors are run on MSVC, but not on MinGW. In both cases the unwind cannot be caught by catch_unwind.
  • As with C++ exceptions, you need to mark the relevant FFI functions with #[unwind(allowed)], otherwise LLVM will optimize out the destructors since they seem unreachable.

I haven't updated any of the documentation, so officially unwinding through FFI is still UB. However this is a step towards making it well-defined.

Fixes #65441

cc @gnzlbg
r? @alexcrichton

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 21, 2019
@Amanieu
Copy link
Member Author

Amanieu commented Oct 21, 2019

Also note that I haven't tested this with SEH yet, so the test will probably fail on windows. Emscripten seems to be using some hack for unwinding that I don't fully understand, so I except that to fail the test as well.

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2019-10-21T02:06:59.2952533Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-10-21T02:06:59.3153690Z ##[command]git config gc.auto 0
2019-10-21T02:06:59.3239282Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-10-21T02:06:59.3295561Z ##[command]git config --get-all http.proxy
2019-10-21T02:06:59.3434999Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/65646/merge:refs/remotes/pull/65646/merge
---
2019-10-21T03:11:47.8805798Z .................................................................................................... 1600/9203
2019-10-21T03:11:53.3804577Z .................................................................................................... 1700/9203
2019-10-21T03:12:06.8236866Z ................................i...............i................................................... 1800/9203
2019-10-21T03:12:14.6484032Z .................................................................................................... 1900/9203
2019-10-21T03:12:29.3956931Z ......................iiiii......................................................................... 2000/9203
2019-10-21T03:12:40.4175560Z .................................................................................................... 2200/9203
2019-10-21T03:12:43.1227602Z .................................................................................................... 2300/9203
2019-10-21T03:12:48.4511658Z .................................................................................................... 2400/9203
2019-10-21T03:13:11.6795647Z .................................................................................................... 2500/9203
---
2019-10-21T03:16:13.3154598Z .........................i...............i.......................................................... 4800/9203
2019-10-21T03:16:26.1185024Z .................................................................................................... 4900/9203
2019-10-21T03:16:32.7373337Z .................................................................................................... 5000/9203
2019-10-21T03:16:42.6297719Z .................................................................................................... 5100/9203
2019-10-21T03:16:50.3816650Z .........................ii.ii...................................................................... 5200/9203
2019-10-21T03:17:00.9372135Z .................................................................................................... 5400/9203
2019-10-21T03:17:11.7751115Z ...........................................................................................i........ 5500/9203
2019-10-21T03:17:20.2922580Z .................................................................................................... 5600/9203
2019-10-21T03:17:25.3780642Z .................................................................................................... 5700/9203
2019-10-21T03:17:25.3780642Z .................................................................................................... 5700/9203
2019-10-21T03:17:36.5087520Z ........................................................................................ii...i..ii.. 5800/9203
2019-10-21T03:18:04.0082965Z .................................................................................................... 6000/9203
2019-10-21T03:18:13.6486558Z .................................................................................................... 6100/9203
2019-10-21T03:18:20.4833514Z .................................................................................................... 6200/9203
2019-10-21T03:18:20.4833514Z .................................................................................................... 6200/9203
2019-10-21T03:18:35.0330796Z ..........i..ii..................................................................................... 6300/9203
2019-10-21T03:18:55.7234890Z ......................................................................i............................. 6500/9203
2019-10-21T03:18:58.0012349Z .................................................................................................... 6600/9203
2019-10-21T03:19:00.5352260Z .............................................i...................................................... 6700/9203
2019-10-21T03:19:04.2687111Z .................................................................................................... 6800/9203
---
2019-10-21T03:23:47.5708693Z  finished in 5.784
2019-10-21T03:23:47.5936993Z Check compiletest suite=codegen mode=codegen (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-10-21T03:23:47.7672772Z 
2019-10-21T03:23:47.7673105Z running 153 tests
2019-10-21T03:23:51.0524904Z i....iii......iii..iiii...i.............................i..i..................i....i...........ii.i. 100/153
2019-10-21T03:23:53.1329109Z i..iiii..............i.........iii.i.........ii......
2019-10-21T03:23:53.1334659Z 
2019-10-21T03:23:53.1340601Z  finished in 5.540
2019-10-21T03:23:53.1539439Z Check compiletest suite=codegen-units mode=codegen-units (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-10-21T03:23:53.3137710Z 
---
2019-10-21T03:23:55.4579815Z  finished in 2.303
2019-10-21T03:23:55.4797334Z Check compiletest suite=assembly mode=assembly (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-10-21T03:23:55.6490571Z 
2019-10-21T03:23:55.6491414Z running 9 tests
2019-10-21T03:23:55.6500772Z iiiiiiiii
2019-10-21T03:23:55.6502466Z 
2019-10-21T03:23:55.6503417Z  finished in 0.171
2019-10-21T03:23:55.6724678Z Check compiletest suite=incremental mode=incremental (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-10-21T03:23:55.8428345Z 
---
2019-10-21T03:24:14.3528701Z  finished in 18.680
2019-10-21T03:24:14.3754553Z Check compiletest suite=debuginfo mode=debuginfo-gdb+lldb (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-10-21T03:24:14.5472437Z 
2019-10-21T03:24:14.5473451Z running 123 tests
2019-10-21T03:24:39.2170676Z .iiiii...i.....i..i...i..i.i.i..i.ii..i.i.....i..i....ii..........iiii..........i...ii...i.......ii. 100/123
2019-10-21T03:24:44.0015831Z i.i.i......iii.i.....ii
2019-10-21T03:24:44.0018619Z 
2019-10-21T03:24:44.0022756Z  finished in 29.626
2019-10-21T03:24:44.0034422Z Uplifting stage1 rustc (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-10-21T03:24:44.0034965Z Copying stage2 rustc from stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
---
2019-10-21T03:38:01.7207366Z 
2019-10-21T03:38:01.7209547Z    Doc-tests core
2019-10-21T03:38:07.0535172Z 
2019-10-21T03:38:07.0536043Z running 2406 tests
2019-10-21T03:38:18.5524418Z ......iiiii......................................................................................... 100/2406
2019-10-21T03:38:29.6716161Z ................................................................................ii.................. 200/2406
2019-10-21T03:38:55.9268234Z ..i................................................................................................. 400/2406
2019-10-21T03:38:55.9268234Z ..i................................................................................................. 400/2406
2019-10-21T03:39:06.8448525Z .................................................i..i.................iiii.......................... 500/2406
2019-10-21T03:39:28.5065038Z .................................................................................................... 700/2406
2019-10-21T03:39:39.2278640Z .................................................................................................... 800/2406
2019-10-21T03:39:50.0314470Z .................................................................................................... 900/2406
2019-10-21T03:40:00.7744277Z .................................................................................................... 1000/2406
---
2019-10-21T03:44:25.5682766Z 
2019-10-21T03:44:25.5683048Z running 994 tests
2019-10-21T03:44:47.3650329Z i................................................................................................... 100/994
2019-10-21T03:44:59.6149551Z .................................................................................................... 200/994
2019-10-21T03:45:08.2844196Z ...................iii......i......i...i......i..................................................... 300/994
2019-10-21T03:45:14.1670354Z .................................................................................................... 400/994
2019-10-21T03:45:22.1517858Z .....................................i..i.................................ii........................ 500/994
2019-10-21T03:45:37.6466938Z .................................................................................................... 700/994
2019-10-21T03:45:37.6466938Z .................................................................................................... 700/994
2019-10-21T03:45:46.0464065Z ....................iiii............................................................................ 800/994
2019-10-21T03:46:01.6440095Z .................................................................................................... 900/994
2019-10-21T03:46:09.5723136Z ..........................................iiii................................................
2019-10-21T03:46:09.5725367Z 
2019-10-21T03:46:09.5844763Z  finished in 205.226
2019-10-21T03:46:09.5861650Z Testing term stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-10-21T03:46:09.8169652Z    Compiling term v0.0.0 (/checkout/src/libterm)
---
2019-10-21T04:02:55.3894252Z  finished in 41.987
2019-10-21T04:02:55.4276329Z Check compiletest suite=run-make-fulldeps mode=run-make (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-10-21T04:02:55.5917037Z 
2019-10-21T04:02:55.5917281Z running 202 tests
2019-10-21T04:03:32.0876461Z ....................i...ii...........................F......................................i....... 100/202
2019-10-21T04:04:24.1046321Z ................................iiii.......i...........iiii.iii....................................i 200/202
2019-10-21T04:04:24.4294056Z failures:
2019-10-21T04:04:24.4303683Z 
2019-10-21T04:04:24.4305349Z ---- [run-make] run-make-fulldeps/foreign-exceptions stdout ----
2019-10-21T04:04:24.4306170Z 
2019-10-21T04:04:24.4306170Z 
2019-10-21T04:04:24.4306256Z error: make failed
2019-10-21T04:04:24.4306320Z status: exit code: 2
2019-10-21T04:04:24.4306357Z command: "make"
2019-10-21T04:04:24.4306410Z stdout:
2019-10-21T04:04:24.4306700Z ------------------------------------------
2019-10-21T04:04:24.4307033Z c++ -ffunction-sections -fdata-sections -fPIC -m64 -c -o /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/foreign-exceptions/foreign-exceptions/libfoo.o foo.cpp
2019-10-21T04:04:24.4307436Z ar crus /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/foreign-exceptions/foreign-exceptions/libfoo.a /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/foreign-exceptions/foreign-exceptions/libfoo.o
2019-10-21T04:04:24.4315226Z LD_LIBRARY_PATH="/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/foreign-exceptions/foreign-exceptions:/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib:/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-bootstrap-tools/x86_64-unknown-linux-gnu/release/deps:/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/lib" '/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc' --out-dir /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/foreign-exceptions/foreign-exceptions -L /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/foreign-exceptions/foreign-exceptions  foo.rs -lfoo -lstdc++
2019-10-21T04:04:24.4315783Z Makefile:7: recipe for target 'foo' failed
2019-10-21T04:04:24.4316063Z ------------------------------------------
2019-10-21T04:04:24.4316109Z stderr:
2019-10-21T04:04:24.4316300Z ------------------------------------------
2019-10-21T04:04:24.4316300Z ------------------------------------------
2019-10-21T04:04:24.4316732Z ar: `u' modifier ignored since `D' is the default (see `U')
2019-10-21T04:04:24.4316805Z error[E0658]: the `#[unwind]` attribute is an experimental feature
2019-10-21T04:04:24.4317102Z    |
2019-10-21T04:04:24.4317143Z 15 |     #[unwind(allowed)]
2019-10-21T04:04:24.4317182Z    |     ^^^^^^^^^^^^^^^^^^
2019-10-21T04:04:24.4317348Z    |
2019-10-21T04:04:24.4317348Z    |
2019-10-21T04:04:24.4317769Z    = note: for more information, see ***/issues/58760
2019-10-21T04:04:24.4317825Z    = help: add `#![feature(unwind_attributes)]` to the crate attributes to enable
2019-10-21T04:04:24.4317858Z 
2019-10-21T04:04:24.4317921Z error[E0658]: the `#[unwind]` attribute is an experimental feature
2019-10-21T04:04:24.4318498Z    |
2019-10-21T04:04:24.4318555Z 18 |     #[unwind(allowed)]
2019-10-21T04:04:24.4318593Z    |     ^^^^^^^^^^^^^^^^^^
2019-10-21T04:04:24.4318629Z    |
2019-10-21T04:04:24.4318629Z    |
2019-10-21T04:04:24.4318916Z    = note: for more information, see ***/issues/58760
2019-10-21T04:04:24.4318982Z    = help: add `#![feature(unwind_attributes)]` to the crate attributes to enable
2019-10-21T04:04:24.4319069Z error: aborting due to 2 previous errors
2019-10-21T04:04:24.4319096Z 
2019-10-21T04:04:24.4319322Z For more information about this error, try `rustc --explain E0658`.
2019-10-21T04:04:24.4319322Z For more information about this error, try `rustc --explain E0658`.
2019-10-21T04:04:24.4319367Z make: *** [foo] Error 1
2019-10-21T04:04:24.4319609Z ------------------------------------------
2019-10-21T04:04:24.4319638Z 
2019-10-21T04:04:24.4319661Z 
2019-10-21T04:04:24.4319683Z 
---
2019-10-21T04:04:24.4321210Z thread 'main' panicked at 'Some tests failed', src/tools/compiletest/src/main.rs:537:22
2019-10-21T04:04:24.4321284Z note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
2019-10-21T04:04:24.4321335Z 
2019-10-21T04:04:24.4321361Z 
2019-10-21T04:04:24.4325623Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--rustdoc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustdoc" "--src-base" "/checkout/src/test/run-make-fulldeps" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "run-make" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-6.0/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "6.0.0\n" "--system-llvm" "--cc" "cc" "--cxx" "c++" "--cflags" "-ffunction-sections -fdata-sections -fPIC -m64" "--llvm-components" "aarch64 aarch64asmparser aarch64asmprinter aarch64codegen aarch64desc aarch64disassembler aarch64info aarch64utils all all-targets amdgpu amdgpuasmparser amdgpuasmprinter amdgpucodegen amdgpudesc amdgpudisassembler amdgpuinfo amdgpuutils analysis arm armasmparser armasmprinter armcodegen armdesc armdisassembler arminfo armutils asmparser asmprinter binaryformat bitreader bitwriter bpf bpfasmparser bpfasmprinter bpfcodegen bpfdesc bpfdisassembler bpfinfo codegen core coroutines coverage debuginfocodeview debuginfodwarf debuginfomsf debuginfopdb demangle dlltooldriver engine executionengine fuzzmutate globalisel hexagon hexagonasmparser hexagoncodegen hexagondesc hexagondisassembler hexagoninfo instcombine instrumentation interpreter ipo irreader lanai lanaiasmparser lanaiasmprinter lanaicodegen lanaidesc lanaidisassembler lanaiinfo libdriver lineeditor linker lto mc mcdisassembler mcjit mcparser mips mipsasmparser mipsasmprinter mipscodegen mipsdesc mipsdisassembler mipsinfo mirparser msp430 msp430asmprinter msp430codegen msp430desc msp430info native nativecodegen nvptx nvptxasmprinter nvptxcodegen nvptxdesc nvptxinfo objcarcopts object objectyaml option orcjit passes powerpc powerpcasmparser powerpcasmprinter powerpccodegen powerpcdesc powerpcdisassembler powerpcinfo profiledata runtimedyld scalaropts selectiondag sparc sparcasmparser sparcasmprinter sparccodegen sparcdesc sparcdisassembler sparcinfo support symbolize systemz systemzasmparser systemzasmprinter systemzcodegen systemzdesc systemzdisassembler systemzinfo tablegen target transformutils vectorize windowsmanifest x86 x86asmparser x86asmprinter x86codegen x86desc x86disassembler x86info x86utils xcore xcoreasmprinter xcorecodegen xcoredesc xcoredisassembler xcoreinfo" "--llvm-cxxflags" "-I/usr/lib/llvm-6.0/include -std=c++0x -fuse-ld=gold -Wl,--no-keep-files-mapped -Wl,--no-map-whole-files -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment -ffunction-sections -fdata-sections -O2 -DNDEBUG  -fno-exceptions -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS" "--ar" "ar" "--llvm-bin-dir" "/usr/lib/llvm-6.0/bin" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
2019-10-21T04:04:24.4326467Z 
2019-10-21T04:04:24.4326495Z 
2019-10-21T04:04:24.4362199Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
2019-10-21T04:04:24.4362281Z Build completed unsuccessfully in 1:50:41
2019-10-21T04:04:24.4362281Z Build completed unsuccessfully in 1:50:41
2019-10-21T04:04:24.4392560Z == clock drift check ==
2019-10-21T04:04:24.4416648Z   local time: Mon Oct 21 04:04:24 UTC 2019
2019-10-21T04:04:24.7074150Z   network time: Mon, 21 Oct 2019 04:04:24 GMT
2019-10-21T04:04:24.7076416Z == end clock drift check ==
2019-10-21T04:04:31.7533944Z 
2019-10-21T04:04:31.7702996Z ##[error]Bash exited with code '1'.
2019-10-21T04:04:31.7762650Z ##[section]Starting: Checkout
2019-10-21T04:04:31.7765861Z ==============================================================================
2019-10-21T04:04:31.7765914Z Task         : Get sources
2019-10-21T04:04:31.7765984Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@Amanieu Amanieu force-pushed the foreign-exceptions branch 2 times, most recently from c7cd231 to 2c074a4 Compare October 21, 2019 11:53
@gnzlbg
Copy link
Contributor

gnzlbg commented Oct 21, 2019

This now means that foreign exceptions are not caught by the catch_unwind at the thread boundary right ? I'm not sure if letting all exceptions unwind up to the thread boundary is the right thing to do, we might want to actually catch foreign exceptions there and abort the process explaining what happened, but I'm not sure how to handle the foreign exceptions used by pthread_cancel in that case (those should not be caught).

@Amanieu
Copy link
Member Author

Amanieu commented Oct 21, 2019

Allowing an exception to unwind to the thread boundary will cause an abort anyways at the point of the throw since it won't be able to find a catch handler.

@gnzlbg
Copy link
Contributor

gnzlbg commented Oct 21, 2019

Allowing an exception to unwind to the thread boundary will cause an abort anyways at the point of the throw since it won't be able to find a catch handler.

I think we should have a test for the error message here. Also, this is not always the case, e.g., when the exception thrown performs forced unwinding, e.g., the exception thrown by cancellation points when pthread_cancel, abort won't be called (which is good).

@Amanieu
Copy link
Member Author

Amanieu commented Oct 21, 2019

I think we should have a test for the error message here. Also, this is not always the case, e.g., when the exception thrown performs forced unwinding, e.g., the exception thrown by cancellation points when pthread_cancel, abort won't be called (which is good).

Forced unwinds work differently from normal unwinds: there is a callback that is called on every frame which allows the caller of _Unwind_ForcedUnwind to choose when to stop unwinding the stack. This is what pthread_cancel uses to unwind to the root of the thread.

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2019-10-21T13:04:43.2845546Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-10-21T13:04:43.3051688Z ##[command]git config gc.auto 0
2019-10-21T13:04:43.3123209Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-10-21T13:04:43.3183328Z ##[command]git config --get-all http.proxy
2019-10-21T13:04:43.3334657Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/65646/merge:refs/remotes/pull/65646/merge
---
2019-10-21T14:09:39.5400699Z .................................................................................................... 1600/9203
2019-10-21T14:09:45.2728321Z .................................................................................................... 1700/9203
2019-10-21T14:09:58.8159245Z ................................i...............i................................................... 1800/9203
2019-10-21T14:10:06.6433508Z .................................................................................................... 1900/9203
2019-10-21T14:10:21.4055545Z ......................iiiii......................................................................... 2000/9203
2019-10-21T14:10:32.5697213Z .................................................................................................... 2200/9203
2019-10-21T14:10:35.2341630Z .................................................................................................... 2300/9203
2019-10-21T14:10:40.6209507Z .................................................................................................... 2400/9203
2019-10-21T14:11:03.6339514Z .................................................................................................... 2500/9203
---
2019-10-21T14:14:07.4597112Z .........................i...............i.......................................................... 4800/9203
2019-10-21T14:14:20.0086324Z .................................................................................................... 4900/9203
2019-10-21T14:14:26.6666822Z .................................................................................................... 5000/9203
2019-10-21T14:14:36.4961803Z .................................................................................................... 5100/9203
2019-10-21T14:14:44.5140913Z .........................ii.ii...................................................................... 5200/9203
2019-10-21T14:14:55.0098072Z .................................................................................................... 5400/9203
2019-10-21T14:15:05.8561671Z ...........................................................................................i........ 5500/9203
2019-10-21T14:15:14.5879551Z .................................................................................................... 5600/9203
2019-10-21T14:15:19.6150485Z .................................................................................................... 5700/9203
2019-10-21T14:15:19.6150485Z .................................................................................................... 5700/9203
2019-10-21T14:15:30.9331821Z ........................................................................................ii...i..ii.. 5800/9203
2019-10-21T14:15:58.5690768Z .................................................................................................... 6000/9203
2019-10-21T14:16:08.2913187Z .................................................................................................... 6100/9203
2019-10-21T14:16:17.7607892Z .................................................................................................... 6200/9203
2019-10-21T14:16:17.7607892Z .................................................................................................... 6200/9203
2019-10-21T14:16:33.5166184Z ..........i..ii..................................................................................... 6300/9203
2019-10-21T14:16:54.3487547Z ......................................................................i............................. 6500/9203
2019-10-21T14:16:56.5677565Z .................................................................................................... 6600/9203
2019-10-21T14:16:59.1348023Z .............................................i...................................................... 6700/9203
2019-10-21T14:17:02.8614344Z .................................................................................................... 6800/9203
---
2019-10-21T14:21:47.6347838Z  finished in 5.965
2019-10-21T14:21:47.6531219Z Check compiletest suite=codegen mode=codegen (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-10-21T14:21:47.8432768Z 
2019-10-21T14:21:47.8432947Z running 153 tests
2019-10-21T14:21:51.1484179Z i....iii......iii..iiii...i.............................i..i..................i....i...........ii.i. 100/153
2019-10-21T14:21:53.1731604Z i..iiii..............i.........iii.i.........ii......
2019-10-21T14:21:53.1733762Z 
2019-10-21T14:21:53.1737886Z  finished in 5.520
2019-10-21T14:21:53.1933125Z Check compiletest suite=codegen-units mode=codegen-units (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-10-21T14:21:53.3707327Z 
---
2019-10-21T14:21:55.5965121Z  finished in 2.403
2019-10-21T14:21:55.6201947Z Check compiletest suite=assembly mode=assembly (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-10-21T14:21:55.7894961Z 
2019-10-21T14:21:55.7895260Z running 9 tests
2019-10-21T14:21:55.7896095Z iiiiiiiii
2019-10-21T14:21:55.7896485Z 
2019-10-21T14:21:55.7896533Z  finished in 0.171
2019-10-21T14:21:55.8095295Z Check compiletest suite=incremental mode=incremental (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-10-21T14:21:55.9964749Z 
---
2019-10-21T14:22:14.7611584Z  finished in 18.951
2019-10-21T14:22:14.7839097Z Check compiletest suite=debuginfo mode=debuginfo-gdb+lldb (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-10-21T14:22:14.9724088Z 
2019-10-21T14:22:14.9725385Z running 123 tests
2019-10-21T14:22:40.6979926Z .iiiii...i.....i..i...i..i.i.i..i.ii..i.i.....i..i....ii..........iiii..........i...ii...i.......ii. 100/123
2019-10-21T14:22:45.8155342Z i.i.i......iii.i.....ii
2019-10-21T14:22:45.8157364Z 
2019-10-21T14:22:45.8164108Z  finished in 31.032
2019-10-21T14:22:45.8178312Z Uplifting stage1 rustc (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-10-21T14:22:45.8180058Z Copying stage2 rustc from stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
---
2019-10-21T14:36:00.2931432Z 
2019-10-21T14:36:00.2932591Z    Doc-tests core
2019-10-21T14:36:05.5241924Z 
2019-10-21T14:36:05.5242356Z running 2406 tests
2019-10-21T14:36:17.1927697Z ......iiiii......................................................................................... 100/2406
2019-10-21T14:36:28.7215256Z ................................................................................ii.................. 200/2406
2019-10-21T14:36:55.8840663Z ..i................................................................................................. 400/2406
2019-10-21T14:36:55.8840663Z ..i................................................................................................. 400/2406
2019-10-21T14:37:07.0907479Z .................................................i..i.................iiii.......................... 500/2406
2019-10-21T14:37:28.9072811Z .................................................................................................... 700/2406
2019-10-21T14:37:39.9555280Z .................................................................................................... 800/2406
2019-10-21T14:37:50.9600278Z .................................................................................................... 900/2406
2019-10-21T14:38:02.0497955Z .................................................................................................... 1000/2406
---
2019-10-21T14:42:29.3512881Z 
2019-10-21T14:42:29.3514150Z running 994 tests
2019-10-21T14:42:52.1871656Z i................................................................................................... 100/994
2019-10-21T14:43:04.5441025Z .................................................................................................... 200/994
2019-10-21T14:43:13.4393330Z ...................iii......i......i...i......i..................................................... 300/994
2019-10-21T14:43:19.4721454Z .................................................................................................... 400/994
2019-10-21T14:43:27.7626430Z .....................................i..i.................................ii........................ 500/994
2019-10-21T14:43:43.5039153Z .................................................................................................... 700/994
2019-10-21T14:43:43.5039153Z .................................................................................................... 700/994
2019-10-21T14:43:52.2107916Z ....................iiii............................................................................ 800/994
2019-10-21T14:44:08.0779302Z .................................................................................................... 900/994
2019-10-21T14:44:16.2328295Z ..........................................iiii................................................
2019-10-21T14:44:16.2331004Z 
2019-10-21T14:44:16.2373443Z  finished in 205.832
2019-10-21T14:44:16.2392937Z Testing term stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-10-21T14:44:16.4608521Z    Compiling term v0.0.0 (/checkout/src/libterm)
---
2019-10-21T15:01:03.5248268Z  finished in 43.607
2019-10-21T15:01:03.5592141Z Check compiletest suite=run-make-fulldeps mode=run-make (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-10-21T15:01:03.7498504Z 
2019-10-21T15:01:03.7499986Z running 202 tests
2019-10-21T15:01:40.6585891Z ....................i...ii............................F.....................................i....... 100/202
2019-10-21T15:02:32.7275122Z ................................iiii.......i...........iiii.iii....................................i 200/202
2019-10-21T15:02:33.0721327Z failures:
2019-10-21T15:02:33.0759539Z 
2019-10-21T15:02:33.0763443Z ---- [run-make] run-make-fulldeps/foreign-exceptions stdout ----
2019-10-21T15:02:33.0763548Z 
2019-10-21T15:02:33.0763548Z 
2019-10-21T15:02:33.0763637Z error: make failed
2019-10-21T15:02:33.0768977Z status: exit code: 2
2019-10-21T15:02:33.0769055Z command: "make"
2019-10-21T15:02:33.0769190Z stdout:
2019-10-21T15:02:33.0770523Z ------------------------------------------
2019-10-21T15:02:33.0771004Z c++ -ffunction-sections -fdata-sections -fPIC -m64 -c -o /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/foreign-exceptions/foreign-exceptions/libfoo.o foo.cpp
2019-10-21T15:02:33.0776255Z Makefile:10: recipe for target '/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/foreign-exceptions/foreign-exceptions/libfoo.o' failed
2019-10-21T15:02:33.0776641Z ------------------------------------------
2019-10-21T15:02:33.0776695Z stderr:
2019-10-21T15:02:33.0776911Z ------------------------------------------
2019-10-21T15:02:33.0776911Z ------------------------------------------
2019-10-21T15:02:33.0777586Z foo.cpp:6:16: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
2019-10-21T15:02:33.0777690Z      bool* ok = nullptr;
2019-10-21T15:02:33.0777737Z                 ^
2019-10-21T15:02:33.0778141Z foo.cpp:6:16: error: 'nullptr' was not declared in this scope
2019-10-21T15:02:33.0778483Z make: *** [/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/foreign-exceptions/foreign-exceptions/libfoo.o] Error 1
2019-10-21T15:02:33.0778751Z ------------------------------------------
2019-10-21T15:02:33.0778786Z 
2019-10-21T15:02:33.0778831Z 
2019-10-21T15:02:33.0778995Z 
---
2019-10-21T15:02:33.0782209Z thread 'main' panicked at 'Some tests failed', src/tools/compiletest/src/main.rs:537:22
2019-10-21T15:02:33.0782323Z note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
2019-10-21T15:02:33.0803527Z 
2019-10-21T15:02:33.0803620Z 
2019-10-21T15:02:33.0809318Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--rustdoc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustdoc" "--src-base" "/checkout/src/test/run-make-fulldeps" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "run-make" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-6.0/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "6.0.0\n" "--system-llvm" "--cc" "cc" "--cxx" "c++" "--cflags" "-ffunction-sections -fdata-sections -fPIC -m64" "--llvm-components" "aarch64 aarch64asmparser aarch64asmprinter aarch64codegen aarch64desc aarch64disassembler aarch64info aarch64utils all all-targets amdgpu amdgpuasmparser amdgpuasmprinter amdgpucodegen amdgpudesc amdgpudisassembler amdgpuinfo amdgpuutils analysis arm armasmparser armasmprinter armcodegen armdesc armdisassembler arminfo armutils asmparser asmprinter binaryformat bitreader bitwriter bpf bpfasmparser bpfasmprinter bpfcodegen bpfdesc bpfdisassembler bpfinfo codegen core coroutines coverage debuginfocodeview debuginfodwarf debuginfomsf debuginfopdb demangle dlltooldriver engine executionengine fuzzmutate globalisel hexagon hexagonasmparser hexagoncodegen hexagondesc hexagondisassembler hexagoninfo instcombine instrumentation interpreter ipo irreader lanai lanaiasmparser lanaiasmprinter lanaicodegen lanaidesc lanaidisassembler lanaiinfo libdriver lineeditor linker lto mc mcdisassembler mcjit mcparser mips mipsasmparser mipsasmprinter mipscodegen mipsdesc mipsdisassembler mipsinfo mirparser msp430 msp430asmprinter msp430codegen msp430desc msp430info native nativecodegen nvptx nvptxasmprinter nvptxcodegen nvptxdesc nvptxinfo objcarcopts object objectyaml option orcjit passes powerpc powerpcasmparser powerpcasmprinter powerpccodegen powerpcdesc powerpcdisassembler powerpcinfo profiledata runtimedyld scalaropts selectiondag sparc sparcasmparser sparcasmprinter sparccodegen sparcdesc sparcdisassembler sparcinfo support symbolize systemz systemzasmparser systemzasmprinter systemzcodegen systemzdesc systemzdisassembler systemzinfo tablegen target transformutils vectorize windowsmanifest x86 x86asmparser x86asmprinter x86codegen x86desc x86disassembler x86info x86utils xcore xcoreasmprinter xcorecodegen xcoredesc xcoredisassembler xcoreinfo" "--llvm-cxxflags" "-I/usr/lib/llvm-6.0/include -std=c++0x -fuse-ld=gold -Wl,--no-keep-files-mapped -Wl,--no-map-whole-files -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment -ffunction-sections -fdata-sections -O2 -DNDEBUG  -fno-exceptions -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS" "--ar" "ar" "--llvm-bin-dir" "/usr/lib/llvm-6.0/bin" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
2019-10-21T15:02:33.0810361Z 
2019-10-21T15:02:33.0810396Z 
2019-10-21T15:02:33.0810456Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
2019-10-21T15:02:33.0810530Z Build completed unsuccessfully in 1:50:57
2019-10-21T15:02:33.0810530Z Build completed unsuccessfully in 1:50:57
2019-10-21T15:02:33.0840875Z == clock drift check ==
2019-10-21T15:02:33.0859667Z   local time: Mon Oct 21 15:02:33 UTC 2019
2019-10-21T15:02:33.1436769Z   network time: Mon, 21 Oct 2019 15:02:33 GMT
2019-10-21T15:02:33.1439611Z == end clock drift check ==
2019-10-21T15:02:38.7241044Z 
2019-10-21T15:02:38.7353265Z ##[error]Bash exited with code '1'.
2019-10-21T15:02:38.7413518Z ##[section]Starting: Checkout
2019-10-21T15:02:38.7415407Z ==============================================================================
2019-10-21T15:02:38.7415488Z Task         : Get sources
2019-10-21T15:02:38.7415542Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@Centril Centril added I-nominated T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Oct 21, 2019
@Centril
Copy link
Contributor

Centril commented Oct 21, 2019

(It's unclear to me which team(s) owns what here, so I've nominated for all the relevant ones. Also, this interacts with the unwinding WG probably. cc @nikomatsakis @BatmanAoD)

@gnzlbg
Copy link
Contributor

gnzlbg commented Oct 21, 2019

Since the only code that can observe this change is code that has UB I think this is strictly a T-compiler issue.

@gnzlbg
Copy link
Contributor

gnzlbg commented Oct 21, 2019

Forced unwinds work differently from normal unwinds: there is a callback that is called on every frame which allows the caller of _Unwind_ForcedUnwind to choose when to stop unwinding the stack. This is what pthread_cancel uses to unwind to the root of the thread.

@Amanieu in my tests, the current implementation of catch_unwind (not the one in this PR) catches all forced unwinds though (EDIT: which results in garbage). The one used by pthreads has a callback at the thread boundary that catches it inside the pthread implementation, but I was wondering what to do with other forced unwinds that do reach the thread boundary (is there anything we can do about those or a way to tell them apart from the pthread one?)

@nikomatsakis
Copy link
Contributor

I definitely think this falls squarely under the nascent "wg-ffi-unwind".

@BatmanAoD
Copy link
Member

I don't have a Windows machine available for testing; can anyone confirm whether this approach works for SEH? (Also, does anyone know what the current behavior of catch_unwind is on Windows when longjmp crosses it?)

@Amanieu
Copy link
Member Author

Amanieu commented Oct 21, 2019

longjmp on Windows is implemented using SEH unwinding, so it should behave the same way as a C++ exception.

I'm going to let bors run the tests on the Windows targets since they are all tier 1.

@bors try

@bors
Copy link
Contributor

bors commented Oct 21, 2019

⌛ Trying commit 40ef77edc067975666ec3bcd62e80d7684512543 with merge 0eb353bac089a59e81b031c52c99a3fcef84cd8d...

@BatmanAoD
Copy link
Member

BatmanAoD commented Oct 21, 2019

@Amanieu In fact, @alexcrichton fixed some logic along those lines some time back. I was concerned about your statement above that you expect this patch to fail on Windows, but I look forward to bors showing us that your pessimism was unsubstantiated 😄

@bors
Copy link
Contributor

bors commented Oct 22, 2019

☀️ Try build successful - checks-azure
Build commit: 0eb353bac089a59e81b031c52c99a3fcef84cd8d (0eb353bac089a59e81b031c52c99a3fcef84cd8d)

@retep998
Copy link
Member

I know previously when we didn't abort on unwinding across the FFI barrier, C++ exceptions would call Rust drop code just fine and vice versa on pc-windows-msvc.

@Amanieu
Copy link
Member Author

Amanieu commented Oct 22, 2019

@bors try

@bors
Copy link
Contributor

bors commented Oct 22, 2019

⌛ Trying commit b8ccab341d0d6ed9fc3efa72aa0eb3bf1bc88793 with merge 1879eb5440b3f015d11e77e9c3b4f80a7c390384...

bors added a commit that referenced this pull request Nov 3, 2019
Allow foreign exceptions to unwind through Rust code and Rust panics to unwind through FFI

This PR fixes interactions between Rust panics and foreign (mainly C++) exceptions.

C++ exceptions (and other FFI exceptions) can now safely unwind through Rust code:
- The FFI function causing the unwind must be marked with `#[unwind(allowed)]`. If this is not the case then LLVM may optimize landing pads away with the assumption that they are unreachable.
- Drop code will be executed as the exception unwinds through the stack, as with a Rust panic.
- `catch_unwind` will *not* catch the exception, instead the exception will silently continue unwinding past it.

Rust panics can now safely unwind through C++ code:
- C++ destructors will be called as the stack unwinds.
- The Rust panic can only be caught with `catch (...)`, after which it can be either rethrown or discarded.
- C++ cannot name the type of the Rust exception object used for unwinding, which means that it can't be caught explicitly or have its contents inspected.

Tests have been added to ensure all of the above works correctly.

Some notes about non-C++ exceptions:
- `pthread_cancel` and `pthread_exit` use unwinding on glibc. This has the same behavior as a C++ exception: destructors are run but it cannot be caught by `catch_unwind`.
- `longjmp` on Windows is implemented using unwinding. Destructors are run on MSVC, but not on MinGW. In both cases the unwind cannot be caught by `catch_unwind`.
- As with C++ exceptions, you need to mark the relevant FFI functions with `#[unwind(allowed)]`, otherwise LLVM will optimize out the destructors since they seem unreachable.

I haven't updated any of the documentation, so officially unwinding through FFI is still UB. However this is a step towards making it well-defined.

Fixes #65441

cc @gnzlbg
r? @alexcrichton
@rust-highfive
Copy link
Collaborator

The job i686-apple of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2019-11-03T03:22:52.5618220Z status: exit code: 2
2019-11-03T03:22:52.5618320Z command: "make"
2019-11-03T03:22:52.5618390Z stdout:
2019-11-03T03:22:52.5619060Z ------------------------------------------
2019-11-03T03:22:52.5620090Z /Users/runner/runners/2.160.0/work/1/s/clang+llvm-7.0.0-x86_64-apple-darwin/bin/clang++ -ffunction-sections -fdata-sections -fPIC --target=i686-apple-darwin -stdlib=libc++ -c -o /Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/test/run-make-fulldeps/foreign-exceptions/foreign-exceptions/libfoo.o foo.cpp
2019-11-03T03:22:52.5621240Z ar crus /Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/test/run-make-fulldeps/foreign-exceptions/foreign-exceptions/libfoo.a /Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/test/run-make-fulldeps/foreign-exceptions/foreign-exceptions/libfoo.o
2019-11-03T03:22:52.5622770Z DYLD_LIBRARY_PATH="/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/test/run-make-fulldeps/foreign-exceptions/foreign-exceptions:/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/stage2/lib:" '/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/stage2/bin/rustc' --out-dir /Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/test/run-make-fulldeps/foreign-exceptions/foreign-exceptions -L /Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/test/run-make-fulldeps/foreign-exceptions/foreign-exceptions  foo.rs -lfoo 
2019-11-03T03:22:52.5623740Z ------------------------------------------
2019-11-03T03:22:52.5623870Z stderr:
2019-11-03T03:22:52.5624530Z ------------------------------------------
2019-11-03T03:22:52.5624530Z ------------------------------------------
2019-11-03T03:22:52.5624650Z error: linking with `cc` failed: exit code: 1
2019-11-03T03:22:52.5624750Z   |
2019-11-03T03:22:52.5638590Z   = note: "cc" "-m32" "-L" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/stage2/lib/rustlib/i686-apple-darwin/lib" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/test/run-make-fulldeps/foreign-exceptions/foreign-exceptions/foo.foo.7rcbfp3g-cgu.0.rcgu.o" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/test/run-make-fulldeps/foreign-exceptions/foreign-exceptions/foo.foo.7rcbfp3g-cgu.1.rcgu.o" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/test/run-make-fulldeps/foreign-exceptions/foreign-exceptions/foo.foo.7rcbfp3g-cgu.10.rcgu.o" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/test/run-make-fulldeps/foreign-exceptions/foreign-exceptions/foo.foo.7rcbfp3g-cgu.11.rcgu.o" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/test/run-make-fulldeps/foreign-exceptions/foreign-exceptions/foo.foo.7rcbfp3g-cgu.12.rcgu.o" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/test/run-make-fulldeps/foreign-exceptions/foreign-exceptions/foo.foo.7rcbfp3g-cgu.13.rcgu.o" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/test/run-make-fulldeps/foreign-exceptions/foreign-exceptions/foo.foo.7rcbfp3g-cgu.14.rcgu.o" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/test/run-make-fulldeps/foreign-exceptions/foreign-exceptions/foo.foo.7rcbfp3g-cgu.15.rcgu.o" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/test/run-make-fulldeps/foreign-exceptions/foreign-exceptions/foo.foo.7rcbfp3g-cgu.2.rcgu.o" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/test/run-make-fulldeps/foreign-exceptions/foreign-exceptions/foo.foo.7rcbfp3g-cgu.3.rcgu.o" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/test/run-make-fulldeps/foreign-exceptions/foreign-exceptions/foo.foo.7rcbfp3g-cgu.4.rcgu.o" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/test/run-make-fulldeps/foreign-exceptions/foreign-exceptions/foo.foo.7rcbfp3g-cgu.5.rcgu.o" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/test/run-make-fulldeps/foreign-exceptions/foreign-exceptions/foo.foo.7rcbfp3g-cgu.6.rcgu.o" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/test/run-make-fulldeps/foreign-exceptions/foreign-exceptions/foo.foo.7rcbfp3g-cgu.7.rcgu.o" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/test/run-make-fulldeps/foreign-exceptions/foreign-exceptions/foo.foo.7rcbfp3g-cgu.8.rcgu.o" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/test/run-make-fulldeps/foreign-exceptions/foreign-exceptions/foo.foo.7rcbfp3g-cgu.9.rcgu.o" "-o" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/test/run-make-fulldeps/foreign-exceptions/foreign-exceptions/foo" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/test/run-make-fulldeps/foreign-exceptions/foreign-exceptions/foo.belfx9afw9cmv8.rcgu.o" "-Wl,-dead_strip" "-nodefaultlibs" "-L" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/test/run-make-fulldeps/foreign-exceptions/foreign-exceptions" "-L" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/stage2/lib/rustlib/i686-apple-darwin/lib" "-lfoo" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/stage2/lib/rustlib/i686-apple-darwin/lib/libstd-b27f3461b48a7877.rlib" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/stage2/lib/rustlib/i686-apple-darwin/lib/libpanic_unwind-7e907693e86a707c.rlib" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/stage2/lib/rustlib/i686-apple-darwin/lib/libhashbrown-bf7b8793668f2842.rlib" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/stage2/lib/rustlib/i686-apple-darwin/lib/librustc_std_workspace_alloc-ae4dc4b119018ccb.rlib" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/stage2/lib/rustlib/i686-apple-darwin/lib/libbacktrace-93aecc0b3e3090ac.rlib" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/stage2/lib/rustlib/i686-apple-darwin/lib/libbacktrace_sys-68d9808dc96de59a.rlib" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/stage2/lib/rustlib/i686-apple-darwin/lib/librustc_demangle-78182cd429d4d797.rlib" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/stage2/lib/rustlib/i686-apple-darwin/lib/libunwind-0124aa79f4ab648e.rlib" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/stage2/lib/rustlib/i686-apple-darwin/lib/libcfg_if-99b009f93b503420.rlib" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/stage2/lib/rustlib/i686-apple-darwin/lib/liblibc-55e2934ec5c7cec2.rlib" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/stage2/lib/rustlib/i686-apple-darwin/lib/liballoc-a0ec04d43f8f41f3.rlib" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/stage2/lib/rustlib/i686-apple-darwin/lib/librustc_std_workspace_core-15e92aa1db6aeca3.rlib" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/stage2/lib/rustlib/i686-apple-darwin/lib/libcore-b9ca771f60ecf5e5.rlib" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/stage2/lib/rustlib/i686-apple-darwin/lib/libcompiler_builtins-38538b3493e3d38b.rlib" "-lSystem" "-lresolv" "-lc" "-lm"
2019-11-03T03:22:52.5641840Z   = note: Undefined symbols for architecture i386:
2019-11-03T03:22:52.5641960Z             "std::terminate()", referenced from:
2019-11-03T03:22:52.5642070Z                 ___clang_call_terminate in libfoo.a(libfoo.o)
2019-11-03T03:22:52.5642190Z             "___cxa_allocate_exception", referenced from:
2019-11-03T03:22:52.5642290Z                 callback() in libfoo.a(libfoo.o)
2019-11-03T03:22:52.5642420Z             "___gxx_personality_v0", referenced from:
2019-11-03T03:22:52.5642530Z                 _throw_cxx_exception in libfoo.a(libfoo.o)
2019-11-03T03:22:52.5642640Z                 _cxx_catch_callback in libfoo.a(libfoo.o)
2019-11-03T03:22:52.5642750Z                 drop_check::~drop_check() in libfoo.a(libfoo.o)
2019-11-03T03:22:52.5642860Z                 Dwarf Exception Unwind Info (__eh_frame) in libfoo.a(libfoo.o)
2019-11-03T03:22:52.5642980Z             "___cxa_rethrow", referenced from:
2019-11-03T03:22:52.5643090Z                 _cxx_catch_callback in libfoo.a(libfoo.o)
2019-11-03T03:22:52.5643200Z             "___cxa_throw", referenced from:
2019-11-03T03:22:52.5643310Z                 callback() in libfoo.a(libfoo.o)
2019-11-03T03:22:52.5643410Z             "___cxa_begin_catch", referenced from:
2019-11-03T03:22:52.5643520Z                 _throw_cxx_exception in libfoo.a(libfoo.o)
2019-11-03T03:22:52.5643620Z                 ___clang_call_terminate in libfoo.a(libfoo.o)
2019-11-03T03:22:52.5643750Z                 _cxx_catch_callback in libfoo.a(libfoo.o)
2019-11-03T03:22:52.5643860Z             "vtable for __cxxabiv1::__class_type_info", referenced from:
2019-11-03T03:22:52.5643980Z                 typeinfo for exception in libfoo.a(libfoo.o)
2019-11-03T03:22:52.5644100Z                 typeinfo for rust_panic in libfoo.a(libfoo.o)
2019-11-03T03:22:52.5644960Z             NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
2019-11-03T03:22:52.5645150Z             "___cxa_end_catch", referenced from:
2019-11-03T03:22:52.5645250Z                 _throw_cxx_exception in libfoo.a(libfoo.o)
2019-11-03T03:22:52.5645370Z                 _cxx_catch_callback in libfoo.a(libfoo.o)
2019-11-03T03:22:52.5645490Z           ld: symbol(s) not found for architecture i386
2019-11-03T03:22:52.5646350Z           clang: error: linker command failed with exit code 1 (use -v to see invocation)
2019-11-03T03:22:52.5646570Z 
2019-11-03T03:22:52.5646660Z error: aborting due to previous error
2019-11-03T03:22:52.5646720Z 
2019-11-03T03:22:52.5646720Z 
2019-11-03T03:22:52.5646790Z make: *** [foo] Error 1
2019-11-03T03:22:52.5647520Z ------------------------------------------
2019-11-03T03:22:52.5647620Z 
2019-11-03T03:22:52.5647660Z 
2019-11-03T03:22:52.5647710Z 
---
2019-11-03T03:22:52.5650170Z thread 'main' panicked at 'Some tests failed', src/tools/compiletest/src/main.rs:537:22
2019-11-03T03:22:52.5650340Z note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
2019-11-03T03:22:52.5650420Z 
2019-11-03T03:22:52.5650460Z 
2019-11-03T03:22:52.5657340Z command did not execute successfully: "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/stage0-tools-bin/compiletest" "--compile-lib-path" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/stage2/lib" "--run-lib-path" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/stage2/lib/rustlib/i686-apple-darwin/lib" "--rustc-path" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/stage2/bin/rustc" "--rustdoc-path" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/stage2/bin/rustdoc" "--src-base" "/Users/runner/runners/2.160.0/work/1/s/src/test/run-make-fulldeps" "--build-base" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/test/run-make-fulldeps" "--stage-id" "stage2-i686-apple-darwin" "--mode" "run-make" "--target" "i686-apple-darwin" "--host" "i686-apple-darwin" "--llvm-filecheck" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/llvm/build/bin/FileCheck" "--nodejs" "/usr/local/bin/node" "--host-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/native/rust-test-helpers" "--docck-python" "/usr/local/bin/python2.7" "--lldb-python" "/usr/bin/python" "--lldb-version" "lldb-902.0.79.2\n  Swift-4.1\n" "--lldb-python-dir" "/Applications/Xcode_9.3.app/Contents/SharedFrameworks/LLDB.framework/Resources/Python" "--llvm-version" "9.0.0-rust-1.40.0-dev\n" "--cc" "/Users/runner/runners/2.160.0/work/1/s/clang+llvm-7.0.0-x86_64-apple-darwin/bin/clang" "--cxx" "/Users/runner/runners/2.160.0/work/1/s/clang+llvm-7.0.0-x86_64-apple-darwin/bin/clang++" "--cflags" "-ffunction-sections -fdata-sections -fPIC --target=i686-apple-darwin -stdlib=libc++" "--llvm-components" "aarch64 aarch64asmparser aarch64codegen aarch64desc aarch64disassembler aarch64info aarch64utils aggressiveinstcombine all all-targets analysis arm armasmparser armcodegen armdesc armdisassembler arminfo armutils asmparser asmprinter binaryformat bitreader bitstreamreader bitwriter codegen core coroutines coverage debuginfocodeview debuginfodwarf debuginfogsym debuginfomsf debuginfopdb demangle dlltooldriver engine executionengine fuzzmutate globalisel gtest gtest_main hexagon hexagonasmparser hexagoncodegen hexagondesc hexagondisassembler hexagoninfo instcombine instrumentation interpreter ipo irreader jitlink libdriver lineeditor linker lto mc mca mcdisassembler mcjit mcparser mips mipsasmparser mipscodegen mipsdesc mipsdisassembler mipsinfo mirparser msp430 msp430asmparser msp430codegen msp430desc msp430disassembler msp430info native nativecodegen nvptx nvptxcodegen nvptxdesc nvptxinfo objcarcopts object objectyaml option orcjit passes powerpc powerpcasmparser powerpccodegen powerpcdesc powerpcdisassembler powerpcinfo profiledata remarks riscv riscvasmparser riscvcodegen riscvdesc riscvdisassembler riscvinfo riscvutils runtimedyld scalaropts selectiondag sparc sparcasmparser sparccodegen sparcdesc sparcdisassembler sparcinfo support symbolize systemz systemzasmparser systemzcodegen systemzdesc systemzdisassembler systemzinfo tablegen target testingsupport textapi transformutils vectorize webassembly webassemblyasmparser webassemblycodegen webassemblydesc webassemblydisassembler webassemblyinfo windowsmanifest x86 x86asmparser x86codegen x86desc x86disassembler x86info x86utils xray" "--llvm-cxxflags" "-I/Users/runner/runners/2.160.0/work/1/s/src/llvm-project/llvm/include -I/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/llvm/build/include -std=c++11 -stdlib=libc++  -fno-exceptions -fno-rtti -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS" "--ar" "ar" "--llvm-bin-dir" "/Users/runner/runners/2.160.0/work/1/s/build/i686-apple-darwin/llvm/build/bin" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
2019-11-03T03:22:52.5660100Z 
2019-11-03T03:22:52.5660150Z 
2019-11-03T03:22:52.5660260Z failed to run: /Users/runner/runners/2.160.0/work/1/s/build/bootstrap/debug/bootstrap test
2019-11-03T03:22:52.5660370Z Build completed unsuccessfully in 1:36:23
2019-11-03T03:22:52.5660370Z Build completed unsuccessfully in 1:36:23
2019-11-03T03:22:52.5713770Z == clock drift check ==
2019-11-03T03:22:52.5779620Z   local time: Sun Nov  3 03:22:52 UTC 2019
2019-11-03T03:22:52.6155370Z   network time: Sun, 03 Nov 2019 03:22:52 GMT
2019-11-03T03:22:52.6157410Z == end clock drift check ==
2019-11-03T03:22:52.6208300Z 
2019-11-03T03:22:52.6339590Z ##[error]Bash exited with code '1'.
2019-11-03T03:22:52.6385330Z ##[section]Starting: Checkout
2019-11-03T03:22:52.6388240Z ==============================================================================
2019-11-03T03:22:52.6388370Z Task         : Get sources
2019-11-03T03:22:52.6388470Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@bors
Copy link
Contributor

bors commented Nov 3, 2019

💔 Test failed - checks-azure

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 3, 2019
@Amanieu Amanieu force-pushed the foreign-exceptions branch 2 times, most recently from b91240a to f223e0d Compare November 3, 2019 17:04
@Amanieu
Copy link
Member Author

Amanieu commented Nov 3, 2019

@bors r=nikomatsakis

@bors
Copy link
Contributor

bors commented Nov 3, 2019

📌 Commit f223e0d has been approved by nikomatsakis

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 3, 2019
@bors
Copy link
Contributor

bors commented Nov 3, 2019

⌛ Testing commit f223e0d with merge b520af6...

bors added a commit that referenced this pull request Nov 3, 2019
Allow foreign exceptions to unwind through Rust code and Rust panics to unwind through FFI

This PR fixes interactions between Rust panics and foreign (mainly C++) exceptions.

C++ exceptions (and other FFI exceptions) can now safely unwind through Rust code:
- The FFI function causing the unwind must be marked with `#[unwind(allowed)]`. If this is not the case then LLVM may optimize landing pads away with the assumption that they are unreachable.
- Drop code will be executed as the exception unwinds through the stack, as with a Rust panic.
- `catch_unwind` will *not* catch the exception, instead the exception will silently continue unwinding past it.

Rust panics can now safely unwind through C++ code:
- C++ destructors will be called as the stack unwinds.
- The Rust panic can only be caught with `catch (...)`, after which it can be either rethrown or discarded.
- C++ cannot name the type of the Rust exception object used for unwinding, which means that it can't be caught explicitly or have its contents inspected.

Tests have been added to ensure all of the above works correctly.

Some notes about non-C++ exceptions:
- `pthread_cancel` and `pthread_exit` use unwinding on glibc. This has the same behavior as a C++ exception: destructors are run but it cannot be caught by `catch_unwind`.
- `longjmp` on Windows is implemented using unwinding. Destructors are run on MSVC, but not on MinGW. In both cases the unwind cannot be caught by `catch_unwind`.
- As with C++ exceptions, you need to mark the relevant FFI functions with `#[unwind(allowed)]`, otherwise LLVM will optimize out the destructors since they seem unreachable.

I haven't updated any of the documentation, so officially unwinding through FFI is still UB. However this is a step towards making it well-defined.

Fixes #65441

cc @gnzlbg
r? @alexcrichton
@bors
Copy link
Contributor

bors commented Nov 3, 2019

☀️ Test successful - checks-azure
Approved by: nikomatsakis
Pushing b520af6 to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

catch_unwind incorrectly tries to stop ForceUnwinds