Skip to content

Commit f7439a5

Browse files
committed
rustc: Always emit uwtable on Android
Long ago (#40549) we enabled the `uwtable` attribute on Windows by default (even with `-C panic=abort`) to allow unwinding binaries for [stack unwinding information][winstack]. It looks like this same issue is [plaguing][arm1] Gecko's Android platforms [as well][arm2]. This commit applies the same fix as #40549 except that this time it's applied for all Android targets. Generating a `-C panic=abort` binary for `armv7-linux-androideabi` before this commit generated a number of `cantunwind` functions (detected with `readelf -u`) but after this commit they all list appropriate unwind information. Closes #49867 [winstack]: https://bugzilla.mozilla.org/show_bug.cgi?id=1302078 [arm1]: https://bugzilla.mozilla.org/show_bug.cgi?id=1453220 [arm2]: https://bugzilla.mozilla.org/show_bug.cgi?id=1451741
1 parent e59f78f commit f7439a5

File tree

6 files changed

+13
-1
lines changed

6 files changed

+13
-1
lines changed

src/librustc_back/target/android_base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ pub fn opts() -> TargetOptions {
2020
base.is_like_android = true;
2121
base.position_independent_executables = true;
2222
base.has_elf_tls = false;
23+
base.requires_uwtable = true;
2324
base
2425
}

src/librustc_back/target/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,11 @@ pub struct TargetOptions {
481481

482482
/// Whether a .debug_gdb_scripts section will be added to the output object file
483483
pub emit_debug_gdb_scripts: bool,
484+
485+
/// Whether or not to unconditionally `uwtable` attributes on functions,
486+
/// typically because the platform needs to unwind for things like stack
487+
/// unwinders.
488+
pub requires_uwtable: bool,
484489
}
485490

486491
impl Default for TargetOptions {
@@ -554,6 +559,7 @@ impl Default for TargetOptions {
554559
default_hidden_visibility: false,
555560
embed_bitcode: false,
556561
emit_debug_gdb_scripts: true,
562+
requires_uwtable: false,
557563
}
558564
}
559565
}
@@ -804,6 +810,7 @@ impl Target {
804810
key!(default_hidden_visibility, bool);
805811
key!(embed_bitcode, bool);
806812
key!(emit_debug_gdb_scripts, bool);
813+
key!(requires_uwtable, bool);
807814

808815
if let Some(array) = obj.find("abi-blacklist").and_then(Json::as_array) {
809816
for name in array.iter().filter_map(|abi| abi.as_string()) {
@@ -1008,6 +1015,7 @@ impl ToJson for Target {
10081015
target_option_val!(default_hidden_visibility);
10091016
target_option_val!(embed_bitcode);
10101017
target_option_val!(emit_debug_gdb_scripts);
1018+
target_option_val!(requires_uwtable);
10111019

10121020
if default.abi_blacklist != self.options.abi_blacklist {
10131021
d.insert("abi-blacklist".to_string(), self.options.abi_blacklist.iter()

src/librustc_back/target/windows_base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ pub fn opts() -> TargetOptions {
103103
custom_unwind_resume: true,
104104
abi_return_struct_as_int: true,
105105
emit_debug_gdb_scripts: false,
106+
requires_uwtable: true,
106107

107108
.. Default::default()
108109
}

src/librustc_back/target/windows_msvc_base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub fn opts() -> TargetOptions {
3535
crt_static_respected: true,
3636
abi_return_struct_as_int: true,
3737
emit_debug_gdb_scripts: false,
38+
requires_uwtable: true,
3839

3940
.. Default::default()
4041
}

src/librustc_trans/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ pub fn trans_instance<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>, instance: Instance<'tc
492492
// You can also find more info on why Windows is whitelisted here in:
493493
// https://bugzilla.mozilla.org/show_bug.cgi?id=1302078
494494
if !cx.sess().no_landing_pads() ||
495-
cx.sess().target.target.options.is_like_windows {
495+
cx.sess().target.target.options.requires_uwtable {
496496
attributes::emit_uwtable(lldecl, true);
497497
}
498498

src/test/codegen/nounwind.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// aux-build:nounwind.rs
1212
// compile-flags: -C no-prepopulate-passes -C panic=abort -C metadata=a
1313
// ignore-windows
14+
// ignore-android
1415

1516
#![crate_type = "lib"]
1617

0 commit comments

Comments
 (0)