Skip to content

Commit 30db261

Browse files
authored
Rollup merge of rust-lang#83391 - hyd-dev:uwtable, r=alexcrichton
Allow not emitting `uwtable` on Android `uwtable` is marked as required on Android, so it can't be disabled via `-C force-unwind-tables=no`. However, I found that the reason it's marked as required was to resolve a [backtrace issue in Gecko](rust-lang#49867), and I haven't find any other reasons that make it required ([yet](https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/Unwind.20tables.20are.20strictly.20required.20on.20Windows.20and.20Android)). Therefore, I assume it's safe to turn it off if a (nice) backtrace is not needed, and submit this PR to allow `-C force-unwind-tables=no` when targeting Android. Note that I haven't tested this change on Android as I don't have an Android environment for testing.
2 parents a42e62f + f900ee3 commit 30db261

File tree

5 files changed

+34
-2
lines changed

5 files changed

+34
-2
lines changed

compiler/rustc_session/src/session.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ impl Session {
863863
} else if self.target.requires_uwtable {
864864
true
865865
} else {
866-
self.opts.cg.force_unwind_tables.unwrap_or(false)
866+
self.opts.cg.force_unwind_tables.unwrap_or(self.target.default_uwtable)
867867
}
868868
}
869869

compiler/rustc_target/src/spec/android_base.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ pub fn opts() -> TargetOptions {
1212
base.dwarf_version = Some(2);
1313
base.position_independent_executables = true;
1414
base.has_elf_tls = false;
15-
base.requires_uwtable = true;
15+
// This is for backward compatibility, see https://github.com/rust-lang/rust/issues/49867
16+
// for context. (At that time, there was no `-C force-unwind-tables`, so the only solution
17+
// was to always emit `uwtable`).
18+
base.default_uwtable = true;
1619
base.crt_static_respected = false;
1720
base
1821
}

compiler/rustc_target/src/spec/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,10 @@ pub struct TargetOptions {
11111111
/// unwinders.
11121112
pub requires_uwtable: bool,
11131113

1114+
/// Whether or not to emit `uwtable` attributes on functions if `-C force-unwind-tables`
1115+
/// is not specified and `uwtable` is not required on this target.
1116+
pub default_uwtable: bool,
1117+
11141118
/// Whether or not SIMD types are passed by reference in the Rust ABI,
11151119
/// typically required if a target can be compiled with a mixed set of
11161120
/// target features. This is `true` by default, and `false` for targets like
@@ -1248,6 +1252,7 @@ impl Default for TargetOptions {
12481252
default_hidden_visibility: false,
12491253
emit_debug_gdb_scripts: true,
12501254
requires_uwtable: false,
1255+
default_uwtable: false,
12511256
simd_types_indirect: true,
12521257
limit_rdylib_exports: true,
12531258
override_export_symbols: None,
@@ -1711,6 +1716,7 @@ impl Target {
17111716
key!(default_hidden_visibility, bool);
17121717
key!(emit_debug_gdb_scripts, bool);
17131718
key!(requires_uwtable, bool);
1719+
key!(default_uwtable, bool);
17141720
key!(simd_types_indirect, bool);
17151721
key!(limit_rdylib_exports, bool);
17161722
key!(override_export_symbols, opt_list);
@@ -1947,6 +1953,7 @@ impl ToJson for Target {
19471953
target_option_val!(default_hidden_visibility);
19481954
target_option_val!(emit_debug_gdb_scripts);
19491955
target_option_val!(requires_uwtable);
1956+
target_option_val!(default_uwtable);
19501957
target_option_val!(simd_types_indirect);
19511958
target_option_val!(limit_rdylib_exports);
19521959
target_option_val!(override_export_symbols);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// revisions: WINDOWS ANDROID
2+
// needs-llvm-components: x86 arm
3+
// compile-flags: -C panic=abort
4+
// [WINDOWS] compile-flags: --target=x86_64-pc-windows-msvc
5+
// [ANDROID] compile-flags: --target=armv7-linux-androideabi
6+
7+
#![feature(no_core, lang_items)]
8+
#![crate_type = "lib"]
9+
#![no_core]
10+
11+
#[lang = "sized"]
12+
trait Sized {}
13+
14+
// CHECK: attributes #{{.*}} uwtable
15+
pub fn foo() {}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// compile-flags: -C no-prepopulate-passes -C panic=abort -C force-unwind-tables=n
2+
// ignore-windows
3+
4+
#![crate_type="lib"]
5+
6+
// CHECK-NOT: attributes #{{.*}} uwtable
7+
pub fn foo() {}

0 commit comments

Comments
 (0)