compiler_builtins.rs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // SPDX-License-Identifier: GPL-2.0
  2. //! Our own `compiler_builtins`.
  3. //!
  4. //! Rust provides [`compiler_builtins`] as a port of LLVM's [`compiler-rt`].
  5. //! Since we do not need the vast majority of them, we avoid the dependency
  6. //! by providing this file.
  7. //!
  8. //! At the moment, some builtins are required that should not be. For instance,
  9. //! [`core`] has 128-bit integers functionality which we should not be compiling
  10. //! in. We will work with upstream [`core`] to provide feature flags to disable
  11. //! the parts we do not need. For the moment, we define them to [`panic!`] at
  12. //! runtime for simplicity to catch mistakes, instead of performing surgery
  13. //! on `core.o`.
  14. //!
  15. //! In any case, all these symbols are weakened to ensure we do not override
  16. //! those that may be provided by the rest of the kernel.
  17. //!
  18. //! [`compiler_builtins`]: https://github.com/rust-lang/compiler-builtins
  19. //! [`compiler-rt`]: https://compiler-rt.llvm.org/
  20. #![allow(internal_features)]
  21. #![feature(compiler_builtins)]
  22. #![compiler_builtins]
  23. #![no_builtins]
  24. #![no_std]
  25. macro_rules! define_panicking_intrinsics(
  26. ($reason: tt, { $($ident: ident, )* }) => {
  27. $(
  28. #[doc(hidden)]
  29. #[export_name = concat!("__rust", stringify!($ident))]
  30. pub extern "C" fn $ident() {
  31. panic!($reason);
  32. }
  33. )*
  34. }
  35. );
  36. define_panicking_intrinsics!("`f32` should not be used", {
  37. __addsf3,
  38. __eqsf2,
  39. __extendsfdf2,
  40. __gesf2,
  41. __lesf2,
  42. __ltsf2,
  43. __mulsf3,
  44. __nesf2,
  45. __truncdfsf2,
  46. __unordsf2,
  47. });
  48. define_panicking_intrinsics!("`f64` should not be used", {
  49. __adddf3,
  50. __eqdf2,
  51. __ledf2,
  52. __ltdf2,
  53. __muldf3,
  54. __unorddf2,
  55. });
  56. define_panicking_intrinsics!("`i128` should not be used", {
  57. __ashrti3,
  58. __muloti4,
  59. __multi3,
  60. });
  61. define_panicking_intrinsics!("`u128` should not be used", {
  62. __ashlti3,
  63. __lshrti3,
  64. __udivmodti4,
  65. __udivti3,
  66. __umodti3,
  67. });
  68. // NOTE: if you are adding a new intrinsic here, you should also add it to
  69. // `redirect-intrinsics` in `rust/Makefile`.