Skip to content

Commit f2ed55a

Browse files
committed
rust: add compiler_builtins crate
Rust provides `compiler_builtins` as a port of LLVM's `compiler-rt`. Since we do not need the vast majority of them, we avoid the dependency by providing our own crate. Co-developed-by: Alex Gaynor <[email protected]> Signed-off-by: Alex Gaynor <[email protected]> Co-developed-by: Wedson Almeida Filho <[email protected]> Signed-off-by: Wedson Almeida Filho <[email protected]> Co-developed-by: Sven Van Asbroeck <[email protected]> Signed-off-by: Sven Van Asbroeck <[email protected]> Co-developed-by: Gary Guo <[email protected]> Signed-off-by: Gary Guo <[email protected]> Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 944b0e6 commit f2ed55a

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

rust/compiler_builtins.rs

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
//! Our own `compiler_builtins`.
4+
//!
5+
//! Rust provides [`compiler_builtins`] as a port of LLVM's [`compiler-rt`].
6+
//! Since we do not need the vast majority of them, we avoid the dependency
7+
//! by providing this file.
8+
//!
9+
//! At the moment, some builtins are required that should not be. For instance,
10+
//! [`core`] has 128-bit integers functionality which we should not be compiling
11+
//! in. We will work with upstream [`core`] to provide feature flags to disable
12+
//! the parts we do not need. For the moment, we define them to [`panic!`] at
13+
//! runtime for simplicity to catch mistakes, instead of performing surgery
14+
//! on `core.o`.
15+
//!
16+
//! In any case, all these symbols are weakened to ensure we do not override
17+
//! those that may be provided by the rest of the kernel.
18+
//!
19+
//! [`compiler_builtins`]: https://github.com/rust-lang/compiler-builtins
20+
//! [`compiler-rt`]: https://compiler-rt.llvm.org/
21+
22+
#![feature(compiler_builtins)]
23+
#![compiler_builtins]
24+
#![no_builtins]
25+
#![no_std]
26+
27+
macro_rules! define_panicking_intrinsics(
28+
($reason: tt, { $($ident: ident, )* }) => {
29+
$(
30+
#[doc(hidden)]
31+
#[no_mangle]
32+
pub extern "C" fn $ident() {
33+
panic!($reason);
34+
}
35+
)*
36+
}
37+
);
38+
39+
define_panicking_intrinsics!("`i128` should not be used", {
40+
__ashrti3,
41+
__muloti4,
42+
__multi3,
43+
});
44+
45+
define_panicking_intrinsics!("`u128` should not be used", {
46+
__ashlti3,
47+
__lshrti3,
48+
__udivmodti4,
49+
__udivti3,
50+
__umodti3,
51+
});
52+
53+
#[cfg(target_arch = "arm")]
54+
define_panicking_intrinsics!("`u64` division/modulo should not be used", {
55+
__aeabi_uldivmod,
56+
__mulodi4,
57+
});

0 commit comments

Comments
 (0)