Skip to content

Commit a4b9225

Browse files
authored
Rollup merge of rust-lang#62287 - petrhosek:libunwind-link-attribute, r=tmandry
Use link attributes on extern "C" blocks with llvm-libuwind When llvm-libunwind feature is enabled, we need to use link attribute on extern "C" blocks to make sure that symbols provided by LLVM's libunwind that's built as part of Rust's libunwind crate are re-exported. This addresses issue rust-lang#62088.
2 parents 510148b + 8d2f80b commit a4b9225

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/libunwind/build.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ fn main() {
44
println!("cargo:rerun-if-changed=build.rs");
55
let target = env::var("TARGET").expect("TARGET was not set");
66

7-
if cfg!(feature = "llvm-libunwind") &&
7+
// FIXME: the not(bootstrap) part is needed because of the issue addressed by #62286,
8+
// and could be removed once that change is in beta.
9+
if cfg!(all(not(bootstrap), feature = "llvm-libunwind")) &&
810
(target.contains("linux") ||
911
target.contains("fuchsia")) {
1012
// Build the unwinding from libunwind C/C++ source code.
11-
#[cfg(feature = "llvm-libunwind")]
13+
#[cfg(all(not(bootstrap), feature = "llvm-libunwind"))]
1214
llvm_libunwind::compile();
1315
} else if target.contains("linux") {
1416
if target.contains("musl") {
@@ -42,7 +44,7 @@ fn main() {
4244
}
4345
}
4446

45-
#[cfg(feature = "llvm-libunwind")]
47+
#[cfg(all(not(bootstrap), feature = "llvm-libunwind"))]
4648
mod llvm_libunwind {
4749
use std::env;
4850
use std::path::Path;

src/libunwind/libunwind.rs

+10
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ pub enum _Unwind_Context {}
6767

6868
pub type _Unwind_Exception_Cleanup_Fn = extern "C" fn(unwind_code: _Unwind_Reason_Code,
6969
exception: *mut _Unwind_Exception);
70+
#[cfg_attr(all(not(bootstrap), feature = "llvm-libunwind"),
71+
link(name = "unwind", kind = "static"))]
7072
extern "C" {
7173
#[unwind(allowed)]
7274
pub fn _Unwind_Resume(exception: *mut _Unwind_Exception) -> !;
@@ -91,6 +93,8 @@ if #[cfg(all(any(target_os = "ios", target_os = "netbsd", not(target_arch = "arm
9193
}
9294
pub use _Unwind_Action::*;
9395

96+
#[cfg_attr(all(not(bootstrap), feature = "llvm-libunwind"),
97+
link(name = "unwind", kind = "static"))]
9498
extern "C" {
9599
pub fn _Unwind_GetGR(ctx: *mut _Unwind_Context, reg_index: c_int) -> _Unwind_Word;
96100
pub fn _Unwind_SetGR(ctx: *mut _Unwind_Context, reg_index: c_int, value: _Unwind_Word);
@@ -144,6 +148,8 @@ if #[cfg(all(any(target_os = "ios", target_os = "netbsd", not(target_arch = "arm
144148
pub const UNWIND_POINTER_REG: c_int = 12;
145149
pub const UNWIND_IP_REG: c_int = 15;
146150

151+
#[cfg_attr(all(not(bootstrap), feature = "llvm-libunwind"),
152+
link(name = "unwind", kind = "static"))]
147153
extern "C" {
148154
fn _Unwind_VRS_Get(ctx: *mut _Unwind_Context,
149155
regclass: _Unwind_VRS_RegClass,
@@ -206,6 +212,8 @@ if #[cfg(all(any(target_os = "ios", target_os = "netbsd", not(target_arch = "arm
206212
cfg_if::cfg_if! {
207213
if #[cfg(not(all(target_os = "ios", target_arch = "arm")))] {
208214
// Not 32-bit iOS
215+
#[cfg_attr(all(not(bootstrap), feature = "llvm-libunwind"),
216+
link(name = "unwind", kind = "static"))]
209217
extern "C" {
210218
#[unwind(allowed)]
211219
pub fn _Unwind_RaiseException(exception: *mut _Unwind_Exception) -> _Unwind_Reason_Code;
@@ -215,6 +223,8 @@ if #[cfg(not(all(target_os = "ios", target_arch = "arm")))] {
215223
}
216224
} else {
217225
// 32-bit iOS uses SjLj and does not provide _Unwind_Backtrace()
226+
#[cfg_attr(all(not(bootstrap), feature = "llvm-libunwind"),
227+
link(name = "unwind", kind = "static"))]
218228
extern "C" {
219229
#[unwind(allowed)]
220230
pub fn _Unwind_SjLj_RaiseException(e: *mut _Unwind_Exception) -> _Unwind_Reason_Code;

0 commit comments

Comments
 (0)