]> git.lizzy.rs Git - rust.git/commitdiff
Mark all extern functions as nounwind
authorBjörn Steinbrink <bsteinbr@gmail.com>
Fri, 11 Sep 2015 18:10:43 +0000 (20:10 +0200)
committerBjörn Steinbrink <bsteinbr@gmail.com>
Mon, 14 Sep 2015 09:36:09 +0000 (11:36 +0200)
Unwinding across an FFI boundary is undefined behaviour, so we can mark
all external function as nounwind. The obvious exception are those
functions that actually perform the unwinding.

src/libcore/lib.rs
src/libcore/panicking.rs
src/librustc_trans/trans/foreign.rs
src/libstd/lib.rs
src/libstd/sys/common/libunwind.rs
src/libstd/sys/common/unwind/mod.rs
src/libstd/sys/common/unwind/seh.rs
src/libstd/sys/common/unwind/seh64_gnu.rs
src/test/codegen/extern-functions.rs [new file with mode: 0644]

index 78a467e365799125b2d5c3dde848bd61d2d133af..94408072932ea5d6a5ad1690602d1331b8eaaba9 100644 (file)
@@ -79,6 +79,7 @@
 #![feature(optin_builtin_traits)]
 #![feature(reflect)]
 #![feature(rustc_attrs)]
+#![feature(unwind_attributes)]
 #![cfg_attr(stage0, feature(simd))]
 #![cfg_attr(not(stage0), feature(repr_simd, platform_intrinsics))]
 #![feature(staged_api)]
index b443ae0636faa979a9319b1636f4800098ff3feb..93ddfa72f63ca78f65413726246f5a2a538365e4 100644 (file)
@@ -62,6 +62,7 @@ pub fn panic_fmt(fmt: fmt::Arguments, file_line: &(&'static str, u32)) -> ! {
     #[allow(improper_ctypes)]
     extern {
         #[lang = "panic_fmt"]
+        #[unwind]
         fn panic_impl(fmt: fmt::Arguments, file: &'static str, line: u32) -> !;
     }
     let (file, line) = *file_line;
index 9a561249594929d0c9d96149c0abc427b22e0a3c..cbb092aa4eb33b3ada7e399e4a1e2b3faaf451d9 100644 (file)
@@ -211,6 +211,7 @@ pub fn register_foreign_item_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
     let llfn_ty = lltype_for_fn_from_foreign_types(ccx, &tys);
 
     let llfn = get_extern_fn(ccx, &mut *ccx.externs().borrow_mut(), name, cc, llfn_ty, fty);
+    attributes::unwind(llfn, false);
     add_argument_attributes(&tys, llfn);
     attributes::from_fn_attrs(ccx, attrs, llfn);
     llfn
index fca4c66112eb6c89e3ad878ef0f442abbb6cf1e2..dc370d8382a4d4ada3b378bcf2f498d5786e15c4 100644 (file)
 #![feature(unique)]
 #![feature(unsafe_no_drop_flag, filling_drop)]
 #![feature(decode_utf16)]
+#![feature(unwind_attributes)]
 #![feature(vec_push_all)]
 #![feature(vec_resize)]
 #![feature(wrapping)]
index fde612014e9921f3b3f32b807d172b76894ca12d..c6bffb0f733eeab4223110db1017b4cd39f51921 100644 (file)
@@ -124,10 +124,12 @@ pub enum _Unwind_Context {}
     // iOS on armv7 uses SjLj exceptions and requires to link
     // against corresponding routine (..._SjLj_...)
     #[cfg(not(all(target_os = "ios", target_arch = "arm")))]
+    #[unwind]
     pub fn _Unwind_RaiseException(exception: *mut _Unwind_Exception)
                                   -> _Unwind_Reason_Code;
 
     #[cfg(all(target_os = "ios", target_arch = "arm"))]
+    #[unwind]
     fn _Unwind_SjLj_RaiseException(e: *mut _Unwind_Exception)
                                    -> _Unwind_Reason_Code;
 
index ff93d0526b7efaea749dfbd756adf3f69d7c8ab8..738681c3cfed7469023d2e39cb74d44743c57ab4 100644 (file)
@@ -192,6 +192,7 @@ fn rust_panic(cause: Box<Any + Send + 'static>) -> ! {
 #[cfg(not(test))]
 /// Entry point of panic from the libcore crate.
 #[lang = "panic_fmt"]
+#[unwind]
 pub extern fn rust_begin_unwind(msg: fmt::Arguments,
                                 file: &'static str, line: u32) -> ! {
     begin_unwind_fmt(msg, &(file, line))
index a201e406a23ead19324a66bf5a6c6221a6035080..a89e8b499acceae3d84c1fa2c8853621d26d775c 100644 (file)
@@ -62,6 +62,7 @@
 
 // This function is provided by kernel32.dll
 extern "system" {
+    #[unwind]
     fn RaiseException(dwExceptionCode: DWORD,
                       dwExceptionFlags: DWORD,
                       nNumberOfArguments: DWORD,
index 4d23794de244525ddb4b05bf969534858ad15f60..9478678fda995eee75c746ba7ad031169967aa03 100644 (file)
@@ -93,6 +93,7 @@ pub enum EXCEPTION_DISPOSITION {
 
 // From kernel32.dll
 extern "system" {
+    #[unwind]
     fn RaiseException(dwExceptionCode: DWORD,
                       dwExceptionFlags: DWORD,
                       nNumberOfArguments: DWORD,
@@ -198,6 +199,7 @@ pub unsafe fn cleanup(ptr: *mut u8) -> Box<Any + Send + 'static> {
 
 #[lang = "eh_unwind_resume"]
 #[cfg(not(test))]
+#[unwind]
 unsafe extern fn rust_eh_unwind_resume(panic_ctx: LPVOID) {
     let params = [panic_ctx as ULONG_PTR];
     RaiseException(RUST_PANIC,
diff --git a/src/test/codegen/extern-functions.rs b/src/test/codegen/extern-functions.rs
new file mode 100644 (file)
index 0000000..4c30b5c
--- /dev/null
@@ -0,0 +1,23 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// compile-flags: -C no-prepopulate-passes
+
+#![feature(unwind_attributes)]
+
+extern {
+// CHECK: Function Attrs: nounwind
+// CHECK-NEXT: declare void @extern_fn
+    fn extern_fn();
+// CHECK-NOT: Function Attrs: nounwind
+// CHECK: declare void @unwinding_extern_fn
+    #[unwind]
+    fn unwinding_extern_fn();
+}