compiler_builtins/
compiler_builtins.rs

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#![allow(internal_features)]
23#![feature(compiler_builtins)]
24#![compiler_builtins]
25#![no_builtins]
26#![no_std]
27
28macro_rules! define_panicking_intrinsics(
29    ($reason: tt, { $($ident: ident, )* }) => {
30        $(
31            #[doc(hidden)]
32            #[export_name = concat!("__rust", stringify!($ident))]
33            pub extern "C" fn $ident() {
34                panic!($reason);
35            }
36        )*
37    }
38);
39
40define_panicking_intrinsics!("`f32` should not be used", {
41    __addsf3,
42    __eqsf2,
43    __extendsfdf2,
44    __gesf2,
45    __lesf2,
46    __ltsf2,
47    __mulsf3,
48    __nesf2,
49    __truncdfsf2,
50    __unordsf2,
51});
52
53define_panicking_intrinsics!("`f64` should not be used", {
54    __adddf3,
55    __eqdf2,
56    __ledf2,
57    __ltdf2,
58    __muldf3,
59    __unorddf2,
60});
61
62define_panicking_intrinsics!("`i128` should not be used", {
63    __ashrti3,
64    __muloti4,
65    __multi3,
66});
67
68define_panicking_intrinsics!("`u128` should not be used", {
69    __ashlti3,
70    __lshrti3,
71    __udivmodti4,
72    __udivti3,
73    __umodti3,
74});
75
76#[cfg(target_arch = "arm")]
77define_panicking_intrinsics!("`f32` should not be used", {
78    __aeabi_fadd,
79    __aeabi_fmul,
80    __aeabi_fcmpeq,
81    __aeabi_fcmple,
82    __aeabi_fcmplt,
83    __aeabi_fcmpun,
84});
85
86#[cfg(target_arch = "arm")]
87define_panicking_intrinsics!("`f64` should not be used", {
88    __aeabi_dadd,
89    __aeabi_dmul,
90    __aeabi_dcmple,
91    __aeabi_dcmplt,
92    __aeabi_dcmpun,
93});
94
95#[cfg(target_arch = "arm")]
96define_panicking_intrinsics!("`u64` division/modulo should not be used", {
97    __aeabi_uldivmod,
98});
99
100// NOTE: if you are adding a new intrinsic here, you should also add it to
101// `redirect-intrinsics` in `rust/Makefile`.