Use LLVM libunwind in a test case with `no_std`

Hi, The following is the code of Rust test case tests/ui/extern-flag/auxiliary/panic_handler.rs.

#![feature(lang_items)]
#![no_std]

// Since `rustc` generally passes `-nodefaultlibs` to the linker,
// Rust programs link necessary system libraries via `#[link()]`
// attributes in the `libc` crate. `libc` is a dependency of `std`,
// but as we are `#![no_std]`, we need to include it manually.
// Except on windows-msvc.
#![feature(rustc_private)]
#[cfg(not(all(windows, target_env = "msvc")))]
extern crate libc;

#[panic_handler]
pub fn begin_panic_handler(_info: &core::panic::PanicInfo<'_>) -> ! {
    loop {}
}

#[lang = "eh_personality"]
extern "C" fn eh_personality() {}

The Rust on IBM AIX uses LLVM libunwind for unwinding. Since crate unwind is a dependency of crate std and no_std is specified in the test case, libunwind is not specified on the link command line. As a result, the test case fails to link with error "Undefined symbol: ._Unwind_Resume" on AIX.

Adding the following statements in the test case makes it pass. But I am wondering how this test case works on other platforms that also use LLVM libunwind and if there are anything to be fixed in the Rust implementation to make the test case pass instead of modifying the test case. Insights and guidance would be greatly appreciated!

+#[cfg(target_os = "aix")]
+#[link(name = "unwind")]
+extern "C" {}

Try adding extern crate unwind; instead. This crate links against the unwinder that should be used.

Thanks for the suggestion! I’ll proceed with that approach if it’s preferable. To use extern crate unwind;, the panic_unwind feature is required, which involves updating the test case as follows.

-#![feature(lang_items)]
+#![feature(lang_items, panic_unwind)]
 #![no_std]

 // Since `rustc` generally passes `-nodefaultlibs` to the linker,
@@ -10,6 +10,9 @@
 #[cfg(not(all(windows, target_env = "msvc")))]
 extern crate libc;

+#[cfg(target_os = "aix")]
+extern crate unwind;
+
 #[panic_handler]
 pub fn begin_panic_handler(_info: &core::panic::PanicInfo<'_>) -> ! {
     loop {}