forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 488
Expand file tree
/
Copy pathMakefile
More file actions
113 lines (96 loc) · 5.09 KB
/
Makefile
File metadata and controls
113 lines (96 loc) · 5.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# SPDX-License-Identifier: GPL-2.0
obj-$(CONFIG_RUST) += helpers.o exports.o
obj-$(CONFIG_RUST) += core.o compiler_builtins.o alloc.o kernel.o
extra-$(CONFIG_RUST) += bindings_generated.rs libmodule.so
extra-$(CONFIG_RUST) += exports_core_generated.h exports_alloc_generated.h
extra-$(CONFIG_RUST) += exports_kernel_generated.h
ifdef CONFIG_CC_IS_CLANG
bindgen_c_flags = $(c_flags)
else
# bindgen relies on libclang to parse C. Ideally, bindgen would support a GCC
# plugin backend and/or the Clang driver would be perfectly compatible with GCC.
#
# For the moment, here we are tweaking the flags on the fly. Some config
# options may not work (e.g. `GCC_PLUGIN_RANDSTRUCT` if we end up using one
# of those structs). We might want to redo how Clang flags are kept track of
# in the general `Makefile` even for GCC builds, similar to what we did with
# `TENTATIVE_CLANG_FLAGS`.
bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \
-mskip-rax-setup -mgeneral-regs-only -msign-return-address=% \
-mabi=lp64 -mstack-protector-guard% -fconserve-stack -falign-jumps=% \
-falign-loops=% -fno-ipa-cp-clone -fno-partial-inlining \
-fno-reorder-blocks -fno-allow-store-data-races -fasan-shadow-offset=% \
-Wno-packed-not-aligned -Wno-format-truncation -Wno-format-overflow \
-Wno-stringop-truncation -Wno-unused-but-set-variable \
-Wno-stringop-overflow -Wno-restrict -Wno-maybe-uninitialized \
-Werror=designated-init -Wno-zero-length-bounds \
--param=% --param asan-%
bindgen_extra_c_flags = $(TENTATIVE_CLANG_FLAGS) -Wno-address-of-packed-member
bindgen_c_flags = $(filter-out $(bindgen_skip_c_flags), $(c_flags)) \
$(bindgen_extra_c_flags)
endif
bindgen_opaque_types := xregs_state desc_struct arch_lbr_state
quiet_cmd_bindgen = BINDGEN $@
cmd_bindgen = \
$(BINDGEN) $< $(addprefix --opaque-type , $(bindgen_opaque_types)) \
--use-core --with-derive-default --ctypes-prefix c_types \
--size_t-is-usize -o $@ -- $(bindgen_c_flags)
$(objtree)/rust/bindings_generated.rs: $(srctree)/rust/kernel/bindings_helper.h FORCE
$(call if_changed_dep,bindgen)
quiet_cmd_exports = EXPORTS $@
cmd_exports = \
$(NM) -p --defined-only $< \
| grep -F ' T ' | cut -d ' ' -f 3 | grep -E '^(__rust_|_R)' \
| xargs -n1 -Isymbol \
echo 'EXPORT_SYMBOL$(exports_target_type)(symbol);' > $@
$(objtree)/rust/exports_core_generated.h: exports_target_type := _RUST
$(objtree)/rust/exports_core_generated.h: $(objtree)/rust/core.o FORCE
$(call if_changed,exports)
$(objtree)/rust/exports_alloc_generated.h: exports_target_type := _RUST
$(objtree)/rust/exports_alloc_generated.h: $(objtree)/rust/alloc.o FORCE
$(call if_changed,exports)
$(objtree)/rust/exports_kernel_generated.h: exports_target_type := _RUST_GPL
$(objtree)/rust/exports_kernel_generated.h: $(objtree)/rust/kernel.o FORCE
$(call if_changed,exports)
quiet_cmd_rustc_procmacro = RUSTC P $@
cmd_rustc_procmacro = \
$(RUSTC) $(rustc_flags) --emit=dep-info,link --edition 2018 --extern proc_macro \
--crate-type proc-macro --out-dir $(objtree)/rust/ \
--crate-name $(patsubst lib%.so,%,$(notdir $@)) $<; \
mv $(objtree)/rust/$(patsubst lib%.so,%,$(notdir $@)).d $(depfile); \
sed -i '/^\#/d' $(depfile)
$(objtree)/rust/libmodule.so: $(srctree)/rust/module.rs FORCE
$(call if_changed_dep,rustc_procmacro)
quiet_cmd_rustc_library = RUSTC L $@
cmd_rustc_library = \
RUST_BINDINGS_FILE=$(abspath $(objtree)/rust/bindings_generated.rs) \
$(RUSTC) $(rustc_flags) $(rustc_cross_flags) $(rustc_target_flags) \
--crate-type rlib --out-dir $(objtree)/rust/ -L $(objtree)/rust/ \
--crate-name $(patsubst %.o,%,$(notdir $@)) $<; \
mv $(objtree)/rust/$(patsubst %.o,%,$(notdir $@)).d $(depfile); \
sed -i '/^\#/d' $(depfile) \
$(if $(rustc_objcopy),;$(OBJCOPY) $(rustc_objcopy) $@)
# `$(rustc_flags)` is passed in case the user added `--sysroot`.
rustc_sysroot = $(shell $(RUSTC) $(rustc_flags) --print sysroot)
rustc_src = $(rustc_sysroot)/lib/rustlib/src/rust
compiler_builtins_src = $(rustc_sysroot)/lib/rustlib/src/compiler-builtins
.SECONDEXPANSION:
$(objtree)/rust/core.o: rustc_target_flags = --edition 2018
$(objtree)/rust/core.o: $$(rustc_src)/library/core/src/lib.rs FORCE
$(call if_changed_dep,rustc_library)
$(objtree)/rust/compiler_builtins.o: rustc_objcopy = -w -W '__*' -W '!__rust*'
$(objtree)/rust/compiler_builtins.o: rustc_target_flags = --edition 2015 \
--cfg 'feature="compiler-builtins"' --cfg 'feature="default"'
$(objtree)/rust/compiler_builtins.o: $$(compiler_builtins_src)/src/lib.rs \
$(objtree)/rust/core.o FORCE
$(call if_changed_dep,rustc_library)
$(objtree)/rust/alloc.o: rustc_target_flags = --edition 2018
$(objtree)/rust/alloc.o: $$(rustc_src)/library/alloc/src/lib.rs \
$(objtree)/rust/compiler_builtins.o FORCE
$(call if_changed_dep,rustc_library)
# ICE on `--extern module`: https://github.com/rust-lang/rust/issues/56935
$(objtree)/rust/kernel.o: rustc_target_flags = --edition 2018 --extern alloc \
--extern module=$(objtree)/rust/libmodule.so
$(objtree)/rust/kernel.o: $(srctree)/rust/kernel/lib.rs $(objtree)/rust/alloc.o \
$(objtree)/rust/libmodule.so $(objtree)/rust/bindings_generated.rs FORCE
$(call if_changed_dep,rustc_library)