Skip to content

Commit d074991

Browse files
committed
Integrate compiler_builtins
This simplifies onboarding, it is smaller, faster to compile and it is one less dependency to worry about. It also simplifies the build system a tiny bit since now everything uses the 2018 edition. Fixes #69. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent d8e8a16 commit d074991

File tree

6 files changed

+135
-27
lines changed

6 files changed

+135
-27
lines changed

.github/workflows/ci.yaml

-3
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,6 @@ jobs:
131131
git checkout $(rustc -vV | grep -F 'commit-hash' | awk '{print $2}')
132132
git submodule update --init library
133133
134-
# Setup: compiler-builtins source
135-
- run: git clone --depth 1 -b 0.1.39 https://github.com/rust-lang/compiler-builtins.git $(rustc ${{ env.RUSTC_SYSROOT }} --print sysroot)/lib/rustlib/src/compiler-builtins
136-
137134
# Setup: bindgen
138135
- run: cargo install --version 0.56.0 bindgen
139136

Documentation/rust/quick-start.rst

-12
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,6 @@ repository into the installation folder of your nightly toolchain::
4949
git clone --recurse-submodules https://github.com/rust-lang/rust $(rustc --print sysroot)/lib/rustlib/src/rust
5050

5151

52-
compiler-builtins source
53-
************************
54-
55-
The source for ``compiler-builtins`` (a Rust port of LLVM's ``compiler-rt``)
56-
is required.
57-
58-
The build system expects the sources alongside the Rust ones we just installed,
59-
so you can clone it into the installation folder of your nightly toolchain::
60-
61-
git clone https://github.com/rust-lang/compiler-builtins $(rustc --print sysroot)/lib/rustlib/src/compiler-builtins
62-
63-
6452
bindgen
6553
*******
6654

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -502,10 +502,10 @@ KBUILD_CFLAGS := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \
502502
-Werror=return-type -Wno-format-security \
503503
-std=gnu89
504504
KBUILD_CPPFLAGS := -D__KERNEL__
505-
KBUILD_RUSTCFLAGS := --emit=dep-info,obj,metadata -Zbinary_dep_depinfo=y \
505+
KBUILD_RUSTCFLAGS := --emit=dep-info,obj,metadata --edition=2018 \
506506
-Cpanic=abort -Cembed-bitcode=n -Clto=n -Crpath=n \
507507
-Cforce-unwind-tables=n -Ccodegen-units=1 \
508-
-Zsymbol-mangling-version=v0
508+
-Zbinary_dep_depinfo=y -Zsymbol-mangling-version=v0
509509
KBUILD_AFLAGS_KERNEL :=
510510
KBUILD_CFLAGS_KERNEL :=
511511
KBUILD_RUSTCFLAGS_KERNEL :=

rust/Makefile

+4-9
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ $(objtree)/rust/exports_kernel_generated.h: $(objtree)/rust/kernel.o FORCE
6464

6565
quiet_cmd_rustc_procmacro = RUSTC P $@
6666
cmd_rustc_procmacro = \
67-
$(RUSTC) $(rustc_flags) --emit=dep-info,link --edition 2018 --extern proc_macro \
67+
$(RUSTC) $(rustc_flags) --emit=dep-info,link --extern proc_macro \
6868
--crate-type proc-macro --out-dir $(objtree)/rust/ \
6969
--crate-name $(patsubst lib%.so,%,$(notdir $@)) $<; \
7070
mv $(objtree)/rust/$(patsubst lib%.so,%,$(notdir $@)).d $(depfile); \
@@ -86,27 +86,22 @@ quiet_cmd_rustc_library = RUSTC L $@
8686
# `$(rustc_flags)` is passed in case the user added `--sysroot`.
8787
rustc_sysroot = $(shell $(RUSTC) $(rustc_flags) --print sysroot)
8888
rustc_src = $(rustc_sysroot)/lib/rustlib/src/rust
89-
compiler_builtins_src = $(rustc_sysroot)/lib/rustlib/src/compiler-builtins
9089

9190
.SECONDEXPANSION:
92-
$(objtree)/rust/core.o: rustc_target_flags = --edition 2018
9391
$(objtree)/rust/core.o: $$(rustc_src)/library/core/src/lib.rs FORCE
9492
$(call if_changed_dep,rustc_library)
9593

96-
$(objtree)/rust/compiler_builtins.o: rustc_objcopy = -w -W '__*' -W '!__rust*'
97-
$(objtree)/rust/compiler_builtins.o: rustc_target_flags = --edition 2015 \
98-
--cfg 'feature="compiler-builtins"' --cfg 'feature="default"'
99-
$(objtree)/rust/compiler_builtins.o: $$(compiler_builtins_src)/src/lib.rs \
94+
$(objtree)/rust/compiler_builtins.o: rustc_objcopy = -w -W '__*'
95+
$(objtree)/rust/compiler_builtins.o: $(srctree)/rust/compiler_builtins.rs \
10096
$(objtree)/rust/core.o FORCE
10197
$(call if_changed_dep,rustc_library)
10298

103-
$(objtree)/rust/alloc.o: rustc_target_flags = --edition 2018
10499
$(objtree)/rust/alloc.o: $$(rustc_src)/library/alloc/src/lib.rs \
105100
$(objtree)/rust/compiler_builtins.o FORCE
106101
$(call if_changed_dep,rustc_library)
107102

108103
# ICE on `--extern module`: https://github.com/rust-lang/rust/issues/56935
109-
$(objtree)/rust/kernel.o: rustc_target_flags = --edition 2018 --extern alloc \
104+
$(objtree)/rust/kernel.o: rustc_target_flags = --extern alloc \
110105
--extern module=$(objtree)/rust/libmodule.so
111106
$(objtree)/rust/kernel.o: $(srctree)/rust/kernel/lib.rs $(objtree)/rust/alloc.o \
112107
$(objtree)/rust/libmodule.so $(objtree)/rust/bindings_generated.rs FORCE

rust/compiler_builtins.rs

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
//! Our `compiler_builtins`.
4+
//!
5+
//! Rust provides `compiler_builtins` as a port of LLVM's `compiler-rt`.
6+
//! Since we don't 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 shouldn't be. For instance,
10+
//! `core` has floating-point functionality which we shouldn't be compiling in.
11+
//! For the moment, we define them to `panic!` at runtime for simplicity.
12+
//! These are actually a superset of the ones we actually need to define,
13+
//! but it seems simpler to ban entire categories at once. In the future,
14+
//! we might be able to remove all this by providing our own custom `core` etc.,
15+
//! or perhaps `core` itself might provide `cfg` options to disable enough
16+
//! functionality to avoid requiring some of these.
17+
//!
18+
//! In any case, all these symbols are weakened to ensure we don't override
19+
//! those that may be provided by the rest of the kernel.
20+
21+
#![feature(compiler_builtins)]
22+
#![compiler_builtins]
23+
24+
#![no_builtins]
25+
#![no_std]
26+
27+
macro_rules! define_panicking_intrinsics(
28+
($reason: tt, { $($ident: ident, )* }) => {
29+
$(
30+
#[no_mangle]
31+
pub extern "C" fn $ident() {
32+
panic!($reason);
33+
}
34+
)*
35+
}
36+
);
37+
38+
define_panicking_intrinsics!("non-inline stack probes should not be used", {
39+
__rust_probestack,
40+
});
41+
42+
define_panicking_intrinsics!("`f32` should not be used", {
43+
__addsf3,
44+
__addsf3vfp,
45+
__divsf3,
46+
__divsf3vfp,
47+
__eqsf2,
48+
__eqsf2vfp,
49+
__fixsfdi,
50+
__fixsfsi,
51+
__fixsfti,
52+
__fixunssfdi,
53+
__fixunssfsi,
54+
__fixunssfti,
55+
__floatdisf,
56+
__floatsisf,
57+
__floattisf,
58+
__floatundisf,
59+
__floatunsisf,
60+
__floatuntisf,
61+
__gesf2,
62+
__gesf2vfp,
63+
__gtsf2,
64+
__gtsf2vfp,
65+
__lesf2,
66+
__lesf2vfp,
67+
__ltsf2,
68+
__ltsf2vfp,
69+
__mulsf3,
70+
__mulsf3vfp,
71+
__nesf2,
72+
__nesf2vfp,
73+
__powisf2,
74+
__subsf3,
75+
__subsf3vfp,
76+
__unordsf2,
77+
});
78+
79+
define_panicking_intrinsics!("`f64` should not be used", {
80+
__adddf3,
81+
__adddf3vfp,
82+
__divdf3,
83+
__divdf3vfp,
84+
__eqdf2,
85+
__eqdf2vfp,
86+
__fixdfdi,
87+
__fixdfsi,
88+
__fixdfti,
89+
__fixunsdfdi,
90+
__fixunsdfsi,
91+
__fixunsdfti,
92+
__floatdidf,
93+
__floatsidf,
94+
__floattidf,
95+
__floatundidf,
96+
__floatunsidf,
97+
__floatuntidf,
98+
__gedf2,
99+
__gedf2vfp,
100+
__gtdf2,
101+
__gtdf2vfp,
102+
__ledf2,
103+
__ledf2vfp,
104+
__ltdf2,
105+
__ltdf2vfp,
106+
__muldf3,
107+
__muldf3vfp,
108+
__nedf2,
109+
__nedf2vfp,
110+
__powidf2,
111+
__subdf3,
112+
__subdf3vfp,
113+
__unorddf2,
114+
});
115+
116+
define_panicking_intrinsics!("`i128` should not be used", {
117+
__ashrti3,
118+
__muloti4,
119+
__multi3,
120+
});
121+
122+
define_panicking_intrinsics!("`u128` should not be used", {
123+
__ashlti3,
124+
__lshrti3,
125+
__udivmodti4,
126+
__udivti3,
127+
__umodti3,
128+
});

scripts/Makefile.build

+1-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ rustc_cross_flags := --target=$(srctree)/arch/$(SRCARCH)/rust/target.json
304304
quiet_cmd_rustc_o_rs = RUSTC $(quiet_modtag) $@
305305
cmd_rustc_o_rs = \
306306
RUST_MODFILE=$(modfile) \
307-
$(RUSTC) $(rustc_flags) $(rustc_cross_flags) --edition 2018 \
307+
$(RUSTC) $(rustc_flags) $(rustc_cross_flags) \
308308
--extern alloc --extern kernel \
309309
--crate-type rlib --out-dir $(obj) -L $(objtree)/rust/ \
310310
--crate-name $(patsubst %.o,%,$(notdir $@)) $<; \

0 commit comments

Comments
 (0)