Skip to content

Commit 35c90a2

Browse files
author
katelyn a. martin
committed
add rust_eh_personality to #[no_std] alloc tests
### Changes This commit addresses some test failures that now occur in the following two tests: * no_std-alloc-error-handler-custom.rs * no_std-alloc-error-handler-default.rs Each test now defines a `rust_eh_personality` extern function, in the same manner as shown in the "Writing an executable without stdlib" section of the `lang_items` documentation here: https://doc.rust-lang.org/unstable-book/language-features/lang-items.html#writing-an-executable-without-stdlib Without this change, these tests would fail to compile due to a linking error explaining that there was an "undefined reference to `rust_eh_personality'."
1 parent b4884c6 commit 35c90a2

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/test/ui/allocator/no_std-alloc-error-handler-custom.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// compile-flags:-C panic=abort
88
// aux-build:helper.rs
99

10-
#![feature(start, rustc_private, new_uninit, panic_info_message)]
10+
#![feature(start, rustc_private, new_uninit, panic_info_message, lang_items)]
1111
#![feature(alloc_error_handler)]
1212
#![no_std]
1313

@@ -84,6 +84,13 @@ fn panic(panic_info: &core::panic::PanicInfo) -> ! {
8484
}
8585
}
8686

87+
// Because we are compiling this code with `-C panic=abort`, this wouldn't normally be needed.
88+
// However, `core` and `alloc` are both compiled with `-C panic=unwind`, which means that functions
89+
// in these libaries will refer to `rust_eh_personality` if LLVM can not *prove* the contents won't
90+
// unwind. So, for this test case we will define the symbol.
91+
#[lang = "eh_personality"]
92+
extern fn rust_eh_personality() {}
93+
8794
#[derive(Debug)]
8895
struct Page([[u64; 32]; 16]);
8996

src/test/ui/allocator/no_std-alloc-error-handler-default.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// aux-build:helper.rs
99
// gate-test-default_alloc_error_handler
1010

11-
#![feature(start, rustc_private, new_uninit, panic_info_message)]
11+
#![feature(start, rustc_private, new_uninit, panic_info_message, lang_items)]
1212
#![feature(default_alloc_error_handler)]
1313
#![no_std]
1414

@@ -71,6 +71,13 @@ fn panic(panic_info: &core::panic::PanicInfo) -> ! {
7171
}
7272
}
7373

74+
// Because we are compiling this code with `-C panic=abort`, this wouldn't normally be needed.
75+
// However, `core` and `alloc` are both compiled with `-C panic=unwind`, which means that functions
76+
// in these libaries will refer to `rust_eh_personality` if LLVM can not *prove* the contents won't
77+
// unwind. So, for this test case we will define the symbol.
78+
#[lang = "eh_personality"]
79+
extern fn rust_eh_personality() {}
80+
7481
#[derive(Debug)]
7582
struct Page([[u64; 32]; 16]);
7683

0 commit comments

Comments
 (0)