Skip to content

Commit 90346ea

Browse files
committed
Auto merge of #40549 - alexcrichton:uwtable-everywhere, r=eddyb
rustc: Always emit the `uwtable` attribute on Windows This commit alters the translation layer to unconditionally emit the `uwtable` LLVM attribute on Windows regardless of the `no_landing_pads` setting. Previously I believe we omitted this attribute as an optimization when the `-Cpanic=abort` flag was passed, but this unfortunately caused problems for Gecko. It [was discovered] that there was trouble unwinding through Rust functions due to foreign exceptions such as illegal instructions or otherwise in-practice methods used to abort a process. In testing it looked like the major difference between a working binary and a non-working binary is indeed this `uwtable` attribute, but this PR has unfortunately not been thoroughly tested in terms of compiling Gecko with `-C panic=abort` *and* this PR to see whether it works, so this is still somewhat working on just suspicion. [was discovered]: https://bugzilla.mozilla.org/show_bug.cgi?id=1302078
2 parents c6df67a + ef90d32 commit 90346ea

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

src/librustc_trans/base.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,24 @@ pub fn trans_instance<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, instance: Instance
583583

584584
ccx.stats().n_closures.set(ccx.stats().n_closures.get() + 1);
585585

586-
if !ccx.sess().no_landing_pads() {
586+
// The `uwtable` attribute according to LLVM is:
587+
//
588+
// This attribute indicates that the ABI being targeted requires that an
589+
// unwind table entry be produced for this function even if we can show
590+
// that no exceptions passes by it. This is normally the case for the
591+
// ELF x86-64 abi, but it can be disabled for some compilation units.
592+
//
593+
// Typically when we're compiling with `-C panic=abort` (which implies this
594+
// `no_landing_pads` check) we don't need `uwtable` because we can't
595+
// generate any exceptions! On Windows, however, exceptions include other
596+
// events such as illegal instructions, segfaults, etc. This means that on
597+
// Windows we end up still needing the `uwtable` attribute even if the `-C
598+
// panic=abort` flag is passed.
599+
//
600+
// You can also find more info on why Windows is whitelisted here in:
601+
// https://bugzilla.mozilla.org/show_bug.cgi?id=1302078
602+
if !ccx.sess().no_landing_pads() ||
603+
ccx.sess().target.target.options.is_like_windows {
587604
attributes::emit_uwtable(lldecl, true);
588605
}
589606

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// ignore-tidy-linelength
12+
13+
// This test is for *-windows-msvc only.
14+
// ignore-android
15+
// ignore-bitrig
16+
// ignore-macos
17+
// ignore-dragonfly
18+
// ignore-freebsd
19+
// ignore-haiku
20+
// ignore-ios
21+
// ignore-linux
22+
// ignore-netbsd
23+
// ignore-openbsd
24+
// ignore-solaris
25+
// ignore-emscripten
26+
27+
// compile-flags: -C no-prepopulate-passes -C panic=abort -O
28+
29+
#![crate_type = "lib"]
30+
31+
// CHECK: Function Attrs: uwtable
32+
// CHECK-NEXT: define void @normal_uwtable()
33+
#[no_mangle]
34+
pub fn normal_uwtable() {
35+
}
36+
37+
// CHECK: Function Attrs: nounwind uwtable
38+
// CHECK-NEXT: define void @extern_uwtable()
39+
#[no_mangle]
40+
pub extern fn extern_uwtable() {
41+
}

0 commit comments

Comments
 (0)