From 24c7eb55d7808bf425a6a182923d085ad1f2aac4 Mon Sep 17 00:00:00 2001 From: Xing Xue Date: Mon, 11 Nov 2024 10:31:29 -0500 Subject: [PATCH 1/4] Add crate "unwind" to link with libunwind on AIX. --- tests/ui/extern-flag/auxiliary/panic_handler.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/ui/extern-flag/auxiliary/panic_handler.rs b/tests/ui/extern-flag/auxiliary/panic_handler.rs index 5ca32fa992b05..b5121846ea23f 100644 --- a/tests/ui/extern-flag/auxiliary/panic_handler.rs +++ b/tests/ui/extern-flag/auxiliary/panic_handler.rs @@ -1,4 +1,4 @@ -#![feature(lang_items)] +#![feature(lang_items, panic_unwind)] #![no_std] // Since `rustc` generally passes `-nodefaultlibs` to the linker, @@ -10,6 +10,12 @@ #[cfg(not(all(windows, target_env = "msvc")))] extern crate libc; +// Since crate `unwind` is a dependency of crate `std`, and we are using +// `#![no_std]`, `libunwind` is not included in the link command on AIX +// by default. We need to include crate `unwind` manually. +#[cfg(target_os = "aix")] +extern crate unwind; + #[panic_handler] pub fn begin_panic_handler(_info: &core::panic::PanicInfo<'_>) -> ! { loop {} From 3a68be89506ca716decaf2fdcf0a675b86849344 Mon Sep 17 00:00:00 2001 From: Xing Xue Date: Mon, 11 Nov 2024 12:12:47 -0500 Subject: [PATCH 2/4] Only use feature `panic_handler` for AIX. --- tests/ui/extern-flag/auxiliary/panic_handler.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/ui/extern-flag/auxiliary/panic_handler.rs b/tests/ui/extern-flag/auxiliary/panic_handler.rs index b5121846ea23f..fe5df498b900d 100644 --- a/tests/ui/extern-flag/auxiliary/panic_handler.rs +++ b/tests/ui/extern-flag/auxiliary/panic_handler.rs @@ -1,5 +1,6 @@ -#![feature(lang_items, panic_unwind)] +#![feature(lang_items)] #![no_std] +#![cfg_attr(target_os = "aix", feature(panic_unwind))] // Since `rustc` generally passes `-nodefaultlibs` to the linker, // Rust programs link necessary system libraries via `#[link()]` From a676ef26f0ba48bcf40e648d8eceab52629c2e0b Mon Sep 17 00:00:00 2001 From: Xing Xue Date: Tue, 12 Nov 2024 16:00:11 -0500 Subject: [PATCH 3/4] Include the panic_unwind feature and specify the unwind crate unconditionally and remove the libc crate. --- .../ui/extern-flag/auxiliary/panic_handler.rs | 19 ++++--------------- .../runtime/signal-alternate-stack-cleanup.rs | 5 ++++- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/tests/ui/extern-flag/auxiliary/panic_handler.rs b/tests/ui/extern-flag/auxiliary/panic_handler.rs index fe5df498b900d..9140ceed22914 100644 --- a/tests/ui/extern-flag/auxiliary/panic_handler.rs +++ b/tests/ui/extern-flag/auxiliary/panic_handler.rs @@ -1,20 +1,9 @@ -#![feature(lang_items)] +#![feature(lang_items, panic_unwind)] #![no_std] -#![cfg_attr(target_os = "aix", feature(panic_unwind))] -// 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; - -// Since crate `unwind` is a dependency of crate `std`, and we are using -// `#![no_std]`, `libunwind` is not included in the link command on AIX -// by default. We need to include crate `unwind` manually. -#[cfg(target_os = "aix")] +// Since the `unwind` crate is a dependency of the `std` crate, and we have +// `#![no_std]`, the unwinder is not included in the link command by default. +// We need to include crate `unwind` manually. extern crate unwind; #[panic_handler] diff --git a/tests/ui/runtime/signal-alternate-stack-cleanup.rs b/tests/ui/runtime/signal-alternate-stack-cleanup.rs index f2af86be0a5f5..7172964a1538f 100644 --- a/tests/ui/runtime/signal-alternate-stack-cleanup.rs +++ b/tests/ui/runtime/signal-alternate-stack-cleanup.rs @@ -29,7 +29,10 @@ fn main() { // Install signal handler that runs on alternate signal stack. let mut action: sigaction = std::mem::zeroed(); action.sa_flags = (SA_ONSTACK | SA_SIGINFO) as _; - action.sa_sigaction = signal_handler as sighandler_t; + #[cfg(not(target_os = "aix"))] + { action.sa_sigaction = signal_handler as sighandler_t} + #[cfg(target_os = "aix")] + { action.sa_union.__su_sigaction = signal_handler as sighandler_t } sigaction(SIGWINCH, &action, std::ptr::null_mut()); // Send SIGWINCH on exit. From fc1c3d99d5be58d0dd5ff0ce1c39636d1e82f1f3 Mon Sep 17 00:00:00 2001 From: Xing Xue Date: Tue, 12 Nov 2024 17:14:40 -0500 Subject: [PATCH 4/4] Remove unrelated changes. --- tests/ui/runtime/signal-alternate-stack-cleanup.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/ui/runtime/signal-alternate-stack-cleanup.rs b/tests/ui/runtime/signal-alternate-stack-cleanup.rs index 7172964a1538f..f2af86be0a5f5 100644 --- a/tests/ui/runtime/signal-alternate-stack-cleanup.rs +++ b/tests/ui/runtime/signal-alternate-stack-cleanup.rs @@ -29,10 +29,7 @@ fn main() { // Install signal handler that runs on alternate signal stack. let mut action: sigaction = std::mem::zeroed(); action.sa_flags = (SA_ONSTACK | SA_SIGINFO) as _; - #[cfg(not(target_os = "aix"))] - { action.sa_sigaction = signal_handler as sighandler_t} - #[cfg(target_os = "aix")] - { action.sa_union.__su_sigaction = signal_handler as sighandler_t } + action.sa_sigaction = signal_handler as sighandler_t; sigaction(SIGWINCH, &action, std::ptr::null_mut()); // Send SIGWINCH on exit.