rust: fix bindgen build error with fstrict-flex-arrays
[platform/kernel/linux-starfive.git] / rust / Makefile
1 # SPDX-License-Identifier: GPL-2.0
2
3 # Where to place rustdoc generated documentation
4 rustdoc_output := $(objtree)/Documentation/output/rust/rustdoc
5
6 obj-$(CONFIG_RUST) += core.o compiler_builtins.o
7 always-$(CONFIG_RUST) += exports_core_generated.h
8
9 # Missing prototypes are expected in the helpers since these are exported
10 # for Rust only, thus there is no header nor prototypes.
11 obj-$(CONFIG_RUST) += helpers.o
12 CFLAGS_REMOVE_helpers.o = -Wmissing-prototypes -Wmissing-declarations
13
14 always-$(CONFIG_RUST) += libmacros.so
15 no-clean-files += libmacros.so
16
17 always-$(CONFIG_RUST) += bindings/bindings_generated.rs bindings/bindings_helpers_generated.rs
18 obj-$(CONFIG_RUST) += alloc.o bindings.o kernel.o
19 always-$(CONFIG_RUST) += exports_alloc_generated.h exports_bindings_generated.h \
20     exports_kernel_generated.h
21
22 always-$(CONFIG_RUST) += uapi/uapi_generated.rs
23 obj-$(CONFIG_RUST) += uapi.o
24
25 ifdef CONFIG_RUST_BUILD_ASSERT_ALLOW
26 obj-$(CONFIG_RUST) += build_error.o
27 else
28 always-$(CONFIG_RUST) += build_error.o
29 endif
30
31 obj-$(CONFIG_RUST) += exports.o
32
33 always-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated.rs
34 always-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated_kunit.c
35
36 obj-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated.o
37 obj-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated_kunit.o
38
39 # Avoids running `$(RUSTC)` for the sysroot when it may not be available.
40 ifdef CONFIG_RUST
41
42 # `$(rust_flags)` is passed in case the user added `--sysroot`.
43 rustc_sysroot := $(shell $(RUSTC) $(rust_flags) --print sysroot)
44 rustc_host_target := $(shell $(RUSTC) --version --verbose | grep -F 'host: ' | cut -d' ' -f2)
45 RUST_LIB_SRC ?= $(rustc_sysroot)/lib/rustlib/src/rust/library
46
47 ifeq ($(quiet),silent_)
48 cargo_quiet=-q
49 rust_test_quiet=-q
50 rustdoc_test_quiet=--test-args -q
51 rustdoc_test_kernel_quiet=>/dev/null
52 else ifeq ($(quiet),quiet_)
53 rust_test_quiet=-q
54 rustdoc_test_quiet=--test-args -q
55 rustdoc_test_kernel_quiet=>/dev/null
56 else
57 cargo_quiet=--verbose
58 endif
59
60 core-cfgs = \
61     --cfg no_fp_fmt_parse
62
63 alloc-cfgs = \
64     --cfg no_borrow \
65     --cfg no_fmt \
66     --cfg no_global_oom_handling \
67     --cfg no_macros \
68     --cfg no_rc \
69     --cfg no_str \
70     --cfg no_string \
71     --cfg no_sync \
72     --cfg no_thin
73
74 quiet_cmd_rustdoc = RUSTDOC $(if $(rustdoc_host),H, ) $<
75       cmd_rustdoc = \
76         OBJTREE=$(abspath $(objtree)) \
77         $(RUSTDOC) $(if $(rustdoc_host),$(rust_common_flags),$(rust_flags)) \
78                 $(rustc_target_flags) -L$(objtree)/$(obj) \
79                 --output $(rustdoc_output) \
80                 --crate-name $(subst rustdoc-,,$@) \
81                 @$(objtree)/include/generated/rustc_cfg $<
82
83 # The `html_logo_url` and `html_favicon_url` forms of the `doc` attribute
84 # can be used to specify a custom logo. However:
85 #   - The given value is used as-is, thus it cannot be relative or a local file
86 #     (unlike the non-custom case) since the generated docs have subfolders.
87 #   - It requires adding it to every crate.
88 #   - It requires changing `core` which comes from the sysroot.
89 #
90 # Using `-Zcrate-attr` would solve the last two points, but not the first.
91 # The https://github.com/rust-lang/rfcs/pull/3226 RFC suggests two new
92 # command-like flags to solve the issue. Meanwhile, we use the non-custom case
93 # and then retouch the generated files.
94 rustdoc: rustdoc-core rustdoc-macros rustdoc-compiler_builtins \
95     rustdoc-alloc rustdoc-kernel
96         $(Q)cp $(srctree)/Documentation/images/logo.svg $(rustdoc_output)
97         $(Q)cp $(srctree)/Documentation/images/COPYING-logo $(rustdoc_output)
98         $(Q)find $(rustdoc_output) -name '*.html' -type f -print0 | xargs -0 sed -Ei \
99                 -e 's:rust-logo\.svg:logo.svg:g' \
100                 -e 's:rust-logo\.png:logo.svg:g' \
101                 -e 's:favicon\.svg:logo.svg:g' \
102                 -e 's:<link rel="alternate icon" type="image/png" href="[./]*favicon-(16x16|32x32)\.png">::g'
103         $(Q)echo '.logo-container > img { object-fit: contain; }' \
104                 >> $(rustdoc_output)/rustdoc.css
105
106 rustdoc-macros: private rustdoc_host = yes
107 rustdoc-macros: private rustc_target_flags = --crate-type proc-macro \
108     --extern proc_macro
109 rustdoc-macros: $(src)/macros/lib.rs FORCE
110         $(call if_changed,rustdoc)
111
112 rustdoc-core: private rustc_target_flags = $(core-cfgs)
113 rustdoc-core: $(RUST_LIB_SRC)/core/src/lib.rs FORCE
114         $(call if_changed,rustdoc)
115
116 rustdoc-compiler_builtins: $(src)/compiler_builtins.rs rustdoc-core FORCE
117         $(call if_changed,rustdoc)
118
119 # We need to allow `rustdoc::broken_intra_doc_links` because some
120 # `no_global_oom_handling` functions refer to non-`no_global_oom_handling`
121 # functions. Ideally `rustdoc` would have a way to distinguish broken links
122 # due to things that are "configured out" vs. entirely non-existing ones.
123 rustdoc-alloc: private rustc_target_flags = $(alloc-cfgs) \
124     -Arustdoc::broken_intra_doc_links
125 rustdoc-alloc: $(src)/alloc/lib.rs rustdoc-core rustdoc-compiler_builtins FORCE
126         $(call if_changed,rustdoc)
127
128 rustdoc-kernel: private rustc_target_flags = --extern alloc \
129     --extern build_error --extern macros=$(objtree)/$(obj)/libmacros.so \
130     --extern bindings --extern uapi
131 rustdoc-kernel: $(src)/kernel/lib.rs rustdoc-core rustdoc-macros \
132     rustdoc-compiler_builtins rustdoc-alloc $(obj)/libmacros.so \
133     $(obj)/bindings.o FORCE
134         $(call if_changed,rustdoc)
135
136 quiet_cmd_rustc_test_library = RUSTC TL $<
137       cmd_rustc_test_library = \
138         OBJTREE=$(abspath $(objtree)) \
139         $(RUSTC) $(rust_common_flags) \
140                 @$(objtree)/include/generated/rustc_cfg $(rustc_target_flags) \
141                 --crate-type $(if $(rustc_test_library_proc),proc-macro,rlib) \
142                 --out-dir $(objtree)/$(obj)/test --cfg testlib \
143                 --sysroot $(objtree)/$(obj)/test/sysroot \
144                 -L$(objtree)/$(obj)/test \
145                 --crate-name $(subst rusttest-,,$(subst rusttestlib-,,$@)) $<
146
147 rusttestlib-build_error: $(src)/build_error.rs rusttest-prepare FORCE
148         $(call if_changed,rustc_test_library)
149
150 rusttestlib-macros: private rustc_target_flags = --extern proc_macro
151 rusttestlib-macros: private rustc_test_library_proc = yes
152 rusttestlib-macros: $(src)/macros/lib.rs rusttest-prepare FORCE
153         $(call if_changed,rustc_test_library)
154
155 rusttestlib-bindings: $(src)/bindings/lib.rs rusttest-prepare FORCE
156         $(call if_changed,rustc_test_library)
157
158 rusttestlib-uapi: $(src)/uapi/lib.rs rusttest-prepare FORCE
159         $(call if_changed,rustc_test_library)
160
161 quiet_cmd_rustdoc_test = RUSTDOC T $<
162       cmd_rustdoc_test = \
163         OBJTREE=$(abspath $(objtree)) \
164         $(RUSTDOC) --test $(rust_common_flags) \
165                 @$(objtree)/include/generated/rustc_cfg \
166                 $(rustc_target_flags) $(rustdoc_test_target_flags) \
167                 --sysroot $(objtree)/$(obj)/test/sysroot $(rustdoc_test_quiet) \
168                 -L$(objtree)/$(obj)/test --output $(rustdoc_output) \
169                 --crate-name $(subst rusttest-,,$@) $<
170
171 quiet_cmd_rustdoc_test_kernel = RUSTDOC TK $<
172       cmd_rustdoc_test_kernel = \
173         rm -rf $(objtree)/$(obj)/test/doctests/kernel; \
174         mkdir -p $(objtree)/$(obj)/test/doctests/kernel; \
175         OBJTREE=$(abspath $(objtree)) \
176         $(RUSTDOC) --test $(rust_flags) \
177                 @$(objtree)/include/generated/rustc_cfg \
178                 -L$(objtree)/$(obj) --extern alloc --extern kernel \
179                 --extern build_error --extern macros \
180                 --extern bindings --extern uapi \
181                 --no-run --crate-name kernel -Zunstable-options \
182                 --test-builder $(objtree)/scripts/rustdoc_test_builder \
183                 $< $(rustdoc_test_kernel_quiet); \
184         $(objtree)/scripts/rustdoc_test_gen
185
186 %/doctests_kernel_generated.rs %/doctests_kernel_generated_kunit.c: \
187     $(src)/kernel/lib.rs $(obj)/kernel.o \
188     $(objtree)/scripts/rustdoc_test_builder \
189     $(objtree)/scripts/rustdoc_test_gen FORCE
190         $(call if_changed,rustdoc_test_kernel)
191
192 # We cannot use `-Zpanic-abort-tests` because some tests are dynamic,
193 # so for the moment we skip `-Cpanic=abort`.
194 quiet_cmd_rustc_test = RUSTC T  $<
195       cmd_rustc_test = \
196         OBJTREE=$(abspath $(objtree)) \
197         $(RUSTC) --test $(rust_common_flags) \
198                 @$(objtree)/include/generated/rustc_cfg \
199                 $(rustc_target_flags) --out-dir $(objtree)/$(obj)/test \
200                 --sysroot $(objtree)/$(obj)/test/sysroot \
201                 -L$(objtree)/$(obj)/test \
202                 --crate-name $(subst rusttest-,,$@) $<; \
203         $(objtree)/$(obj)/test/$(subst rusttest-,,$@) $(rust_test_quiet) \
204                 $(rustc_test_run_flags)
205
206 rusttest: rusttest-macros rusttest-kernel
207
208 # This prepares a custom sysroot with our custom `alloc` instead of
209 # the standard one.
210 #
211 # This requires several hacks:
212 #   - Unlike `core` and `alloc`, `std` depends on more than a dozen crates,
213 #     including third-party crates that need to be downloaded, plus custom
214 #     `build.rs` steps. Thus hardcoding things here is not maintainable.
215 #   - `cargo` knows how to build the standard library, but it is an unstable
216 #     feature so far (`-Zbuild-std`).
217 #   - `cargo` only considers the use case of building the standard library
218 #     to use it in a given package. Thus we need to create a dummy package
219 #     and pick the generated libraries from there.
220 #   - Since we only keep a subset of upstream `alloc` in-tree, we need
221 #     to recreate it on the fly by putting our sources on top.
222 #   - The usual ways of modifying the dependency graph in `cargo` do not seem
223 #     to apply for the `-Zbuild-std` steps, thus we have to mislead it
224 #     by modifying the sources in the sysroot.
225 #   - To avoid messing with the user's Rust installation, we create a clone
226 #     of the sysroot. However, `cargo` ignores `RUSTFLAGS` in the `-Zbuild-std`
227 #     steps, thus we use a wrapper binary passed via `RUSTC` to pass the flag.
228 #
229 # In the future, we hope to avoid the whole ordeal by either:
230 #   - Making the `test` crate not depend on `std` (either improving upstream
231 #     or having our own custom crate).
232 #   - Making the tests run in kernel space (requires the previous point).
233 #   - Making `std` and friends be more like a "normal" crate, so that
234 #     `-Zbuild-std` and related hacks are not needed.
235 quiet_cmd_rustsysroot = RUSTSYSROOT
236       cmd_rustsysroot = \
237         rm -rf $(objtree)/$(obj)/test; \
238         mkdir -p $(objtree)/$(obj)/test; \
239         cp -a $(rustc_sysroot) $(objtree)/$(obj)/test/sysroot; \
240         cp -r $(srctree)/$(src)/alloc/* \
241                 $(objtree)/$(obj)/test/sysroot/lib/rustlib/src/rust/library/alloc/src; \
242         echo '\#!/bin/sh' > $(objtree)/$(obj)/test/rustc_sysroot; \
243         echo "$(RUSTC) --sysroot=$(abspath $(objtree)/$(obj)/test/sysroot) \"\$$@\"" \
244                 >> $(objtree)/$(obj)/test/rustc_sysroot; \
245         chmod u+x $(objtree)/$(obj)/test/rustc_sysroot; \
246         $(CARGO) -q new $(objtree)/$(obj)/test/dummy; \
247         RUSTC=$(objtree)/$(obj)/test/rustc_sysroot $(CARGO) $(cargo_quiet) \
248                 test -Zbuild-std --target $(rustc_host_target) \
249                 --manifest-path $(objtree)/$(obj)/test/dummy/Cargo.toml; \
250         rm $(objtree)/$(obj)/test/sysroot/lib/rustlib/$(rustc_host_target)/lib/*; \
251         cp $(objtree)/$(obj)/test/dummy/target/$(rustc_host_target)/debug/deps/* \
252                 $(objtree)/$(obj)/test/sysroot/lib/rustlib/$(rustc_host_target)/lib
253
254 rusttest-prepare: FORCE
255         $(call if_changed,rustsysroot)
256
257 rusttest-macros: private rustc_target_flags = --extern proc_macro
258 rusttest-macros: private rustdoc_test_target_flags = --crate-type proc-macro
259 rusttest-macros: $(src)/macros/lib.rs rusttest-prepare FORCE
260         $(call if_changed,rustc_test)
261         $(call if_changed,rustdoc_test)
262
263 rusttest-kernel: private rustc_target_flags = --extern alloc \
264     --extern build_error --extern macros --extern bindings --extern uapi
265 rusttest-kernel: $(src)/kernel/lib.rs rusttest-prepare \
266     rusttestlib-build_error rusttestlib-macros rusttestlib-bindings \
267     rusttestlib-uapi FORCE
268         $(call if_changed,rustc_test)
269         $(call if_changed,rustc_test_library)
270
271 ifdef CONFIG_CC_IS_CLANG
272 bindgen_c_flags = $(c_flags)
273 else
274 # bindgen relies on libclang to parse C. Ideally, bindgen would support a GCC
275 # plugin backend and/or the Clang driver would be perfectly compatible with GCC.
276 #
277 # For the moment, here we are tweaking the flags on the fly. This is a hack,
278 # and some kernel configurations may not work (e.g. `GCC_PLUGIN_RANDSTRUCT`
279 # if we end up using one of those structs).
280 bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \
281         -mskip-rax-setup -mgeneral-regs-only -msign-return-address=% \
282         -mindirect-branch=thunk-extern -mindirect-branch-register \
283         -mfunction-return=thunk-extern -mrecord-mcount -mabi=lp64 \
284         -mindirect-branch-cs-prefix -mstack-protector-guard% -mtraceback=no \
285         -mno-pointers-to-nested-functions -mno-string \
286         -mno-strict-align -mstrict-align \
287         -fconserve-stack -falign-jumps=% -falign-loops=% \
288         -femit-struct-debug-baseonly -fno-ipa-cp-clone -fno-ipa-sra \
289         -fno-partial-inlining -fplugin-arg-arm_ssp_per_task_plugin-% \
290         -fno-reorder-blocks -fno-allow-store-data-races -fasan-shadow-offset=% \
291         -fzero-call-used-regs=% -fno-stack-clash-protection \
292         -fno-inline-functions-called-once -fsanitize=bounds-strict \
293         -fstrict-flex-arrays=% \
294         --param=% --param asan-%
295
296 # Derived from `scripts/Makefile.clang`.
297 BINDGEN_TARGET_x86      := x86_64-linux-gnu
298 BINDGEN_TARGET          := $(BINDGEN_TARGET_$(SRCARCH))
299
300 # All warnings are inhibited since GCC builds are very experimental,
301 # many GCC warnings are not supported by Clang, they may only appear in
302 # some configurations, with new GCC versions, etc.
303 bindgen_extra_c_flags = -w --target=$(BINDGEN_TARGET)
304
305 # Auto variable zero-initialization requires an additional special option with
306 # clang that is going to be removed sometime in the future (likely in
307 # clang-18), so make sure to pass this option only if clang supports it
308 # (libclang major version < 16).
309 #
310 # https://github.com/llvm/llvm-project/issues/44842
311 # https://github.com/llvm/llvm-project/blob/llvmorg-16.0.0-rc2/clang/docs/ReleaseNotes.rst#deprecated-compiler-flags
312 ifdef CONFIG_INIT_STACK_ALL_ZERO
313 libclang_maj_ver=$(shell $(BINDGEN) $(srctree)/scripts/rust_is_available_bindgen_libclang.h 2>&1 | sed -ne 's/.*clang version \([0-9]*\).*/\1/p')
314 ifeq ($(shell expr $(libclang_maj_ver) \< 16), 1)
315 bindgen_extra_c_flags += -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang
316 endif
317 endif
318
319 bindgen_c_flags = $(filter-out $(bindgen_skip_c_flags), $(c_flags)) \
320         $(bindgen_extra_c_flags)
321 endif
322
323 ifdef CONFIG_LTO
324 bindgen_c_flags_lto = $(filter-out $(CC_FLAGS_LTO), $(bindgen_c_flags))
325 else
326 bindgen_c_flags_lto = $(bindgen_c_flags)
327 endif
328
329 bindgen_c_flags_final = $(bindgen_c_flags_lto) -D__BINDGEN__
330
331 quiet_cmd_bindgen = BINDGEN $@
332       cmd_bindgen = \
333         $(BINDGEN) $< $(bindgen_target_flags) \
334                 --use-core --with-derive-default --ctypes-prefix core::ffi --no-layout-tests \
335                 --no-debug '.*' \
336                 -o $@ -- $(bindgen_c_flags_final) -DMODULE \
337                 $(bindgen_target_cflags) $(bindgen_target_extra)
338
339 $(obj)/bindings/bindings_generated.rs: private bindgen_target_flags = \
340     $(shell grep -v '^#\|^$$' $(srctree)/$(src)/bindgen_parameters)
341 $(obj)/bindings/bindings_generated.rs: $(src)/bindings/bindings_helper.h \
342     $(src)/bindgen_parameters FORCE
343         $(call if_changed_dep,bindgen)
344
345 $(obj)/uapi/uapi_generated.rs: private bindgen_target_flags = \
346     $(shell grep -v '^#\|^$$' $(srctree)/$(src)/bindgen_parameters)
347 $(obj)/uapi/uapi_generated.rs: $(src)/uapi/uapi_helper.h \
348     $(src)/bindgen_parameters FORCE
349         $(call if_changed_dep,bindgen)
350
351 # See `CFLAGS_REMOVE_helpers.o` above. In addition, Clang on C does not warn
352 # with `-Wmissing-declarations` (unlike GCC), so it is not strictly needed here
353 # given it is `libclang`; but for consistency, future Clang changes and/or
354 # a potential future GCC backend for `bindgen`, we disable it too.
355 $(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_flags = \
356     --blocklist-type '.*' --allowlist-var '' \
357     --allowlist-function 'rust_helper_.*'
358 $(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_cflags = \
359     -I$(objtree)/$(obj) -Wno-missing-prototypes -Wno-missing-declarations
360 $(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_extra = ; \
361     sed -Ei 's/pub fn rust_helper_([a-zA-Z0-9_]*)/#[link_name="rust_helper_\1"]\n    pub fn \1/g' $@
362 $(obj)/bindings/bindings_helpers_generated.rs: $(src)/helpers.c FORCE
363         $(call if_changed_dep,bindgen)
364
365 quiet_cmd_exports = EXPORTS $@
366       cmd_exports = \
367         $(NM) -p --defined-only $< \
368                 | grep -E ' (T|R|D) ' | cut -d ' ' -f 3 \
369                 | xargs -Isymbol \
370                 echo 'EXPORT_SYMBOL_RUST_GPL(symbol);' > $@
371
372 $(obj)/exports_core_generated.h: $(obj)/core.o FORCE
373         $(call if_changed,exports)
374
375 $(obj)/exports_alloc_generated.h: $(obj)/alloc.o FORCE
376         $(call if_changed,exports)
377
378 $(obj)/exports_bindings_generated.h: $(obj)/bindings.o FORCE
379         $(call if_changed,exports)
380
381 $(obj)/exports_kernel_generated.h: $(obj)/kernel.o FORCE
382         $(call if_changed,exports)
383
384 quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@
385       cmd_rustc_procmacro = \
386         $(RUSTC_OR_CLIPPY) $(rust_common_flags) \
387                 --emit=dep-info=$(depfile) --emit=link=$@ --extern proc_macro \
388                 --crate-type proc-macro \
389                 --crate-name $(patsubst lib%.so,%,$(notdir $@)) $<
390
391 # Procedural macros can only be used with the `rustc` that compiled it.
392 # Therefore, to get `libmacros.so` automatically recompiled when the compiler
393 # version changes, we add `core.o` as a dependency (even if it is not needed).
394 $(obj)/libmacros.so: $(src)/macros/lib.rs $(obj)/core.o FORCE
395         $(call if_changed_dep,rustc_procmacro)
396
397 quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L $@
398       cmd_rustc_library = \
399         OBJTREE=$(abspath $(objtree)) \
400         $(if $(skip_clippy),$(RUSTC),$(RUSTC_OR_CLIPPY)) \
401                 $(filter-out $(skip_flags),$(rust_flags) $(rustc_target_flags)) \
402                 --emit=dep-info=$(depfile) --emit=obj=$@ \
403                 --emit=metadata=$(dir $@)$(patsubst %.o,lib%.rmeta,$(notdir $@)) \
404                 --crate-type rlib -L$(objtree)/$(obj) \
405                 --crate-name $(patsubst %.o,%,$(notdir $@)) $< \
406         $(if $(rustc_objcopy),;$(OBJCOPY) $(rustc_objcopy) $@)
407
408 rust-analyzer:
409         $(Q)$(srctree)/scripts/generate_rust_analyzer.py \
410                 --cfgs='core=$(core-cfgs)' --cfgs='alloc=$(alloc-cfgs)' \
411                 $(abs_srctree) $(abs_objtree) \
412                 $(RUST_LIB_SRC) $(KBUILD_EXTMOD) > \
413                 $(if $(KBUILD_EXTMOD),$(extmod_prefix),$(objtree))/rust-project.json
414
415 redirect-intrinsics = \
416         __addsf3 __eqsf2 __gesf2 __lesf2 __ltsf2 __mulsf3 __nesf2 __unordsf2 \
417         __adddf3 __ledf2 __ltdf2 __muldf3 __unorddf2 \
418         __muloti4 __multi3 \
419         __udivmodti4 __udivti3 __umodti3
420
421 ifneq ($(or $(CONFIG_ARM64),$(and $(CONFIG_RISCV),$(CONFIG_64BIT))),)
422         # These intrinsics are defined for ARM64 and RISCV64
423         redirect-intrinsics += \
424                 __ashrti3 \
425                 __ashlti3 __lshrti3
426 endif
427
428 $(obj)/core.o: private skip_clippy = 1
429 $(obj)/core.o: private skip_flags = -Dunreachable_pub
430 $(obj)/core.o: private rustc_objcopy = $(foreach sym,$(redirect-intrinsics),--redefine-sym $(sym)=__rust$(sym))
431 $(obj)/core.o: private rustc_target_flags = $(core-cfgs)
432 $(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs scripts/target.json FORCE
433         $(call if_changed_dep,rustc_library)
434
435 $(obj)/compiler_builtins.o: private rustc_objcopy = -w -W '__*'
436 $(obj)/compiler_builtins.o: $(src)/compiler_builtins.rs $(obj)/core.o FORCE
437         $(call if_changed_dep,rustc_library)
438
439 $(obj)/alloc.o: private skip_clippy = 1
440 $(obj)/alloc.o: private skip_flags = -Dunreachable_pub
441 $(obj)/alloc.o: private rustc_target_flags = $(alloc-cfgs)
442 $(obj)/alloc.o: $(src)/alloc/lib.rs $(obj)/compiler_builtins.o FORCE
443         $(call if_changed_dep,rustc_library)
444
445 $(obj)/build_error.o: $(src)/build_error.rs $(obj)/compiler_builtins.o FORCE
446         $(call if_changed_dep,rustc_library)
447
448 $(obj)/bindings.o: $(src)/bindings/lib.rs \
449     $(obj)/compiler_builtins.o \
450     $(obj)/bindings/bindings_generated.rs \
451     $(obj)/bindings/bindings_helpers_generated.rs FORCE
452         $(call if_changed_dep,rustc_library)
453
454 $(obj)/uapi.o: $(src)/uapi/lib.rs \
455     $(obj)/compiler_builtins.o \
456     $(obj)/uapi/uapi_generated.rs FORCE
457         $(call if_changed_dep,rustc_library)
458
459 $(obj)/kernel.o: private rustc_target_flags = --extern alloc \
460     --extern build_error --extern macros --extern bindings --extern uapi
461 $(obj)/kernel.o: $(src)/kernel/lib.rs $(obj)/alloc.o $(obj)/build_error.o \
462     $(obj)/libmacros.so $(obj)/bindings.o $(obj)/uapi.o FORCE
463         $(call if_changed_dep,rustc_library)
464
465 endif # CONFIG_RUST