1# SPDX-License-Identifier: GPL-2.0 2 3# Where to place rustdoc generated documentation 4rustdoc_output := $(objtree)/Documentation/output/rust/rustdoc 5 6obj-$(CONFIG_RUST) += core.o compiler_builtins.o ffi.o 7always-$(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. 11obj-$(CONFIG_RUST) += helpers/helpers.o 12CFLAGS_REMOVE_helpers/helpers.o = -Wmissing-prototypes -Wmissing-declarations 13 14always-$(CONFIG_RUST) += libmacros.so 15no-clean-files += libmacros.so 16 17always-$(CONFIG_RUST) += bindings/bindings_generated.rs bindings/bindings_helpers_generated.rs 18obj-$(CONFIG_RUST) += bindings.o kernel.o 19always-$(CONFIG_RUST) += exports_helpers_generated.h \ 20 exports_bindings_generated.h exports_kernel_generated.h 21 22always-$(CONFIG_RUST) += uapi/uapi_generated.rs 23obj-$(CONFIG_RUST) += uapi.o 24 25ifdef CONFIG_RUST_BUILD_ASSERT_ALLOW 26obj-$(CONFIG_RUST) += build_error.o 27else 28always-$(CONFIG_RUST) += build_error.o 29endif 30 31obj-$(CONFIG_RUST) += exports.o 32 33always-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated.rs 34always-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated_kunit.c 35 36obj-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated.o 37obj-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated_kunit.o 38 39always-$(subst y,$(CONFIG_RUST),$(CONFIG_JUMP_LABEL)) += kernel/generated_arch_static_branch_asm.rs 40 41# Avoids running `$(RUSTC)` for the sysroot when it may not be available. 42ifdef CONFIG_RUST 43 44# `$(rust_flags)` is passed in case the user added `--sysroot`. 45rustc_sysroot := $(shell MAKEFLAGS= $(RUSTC) $(rust_flags) --print sysroot) 46rustc_host_target := $(shell $(RUSTC) --version --verbose | grep -F 'host: ' | cut -d' ' -f2) 47RUST_LIB_SRC ?= $(rustc_sysroot)/lib/rustlib/src/rust/library 48 49ifneq ($(quiet),) 50rust_test_quiet=-q 51rustdoc_test_quiet=--test-args -q 52rustdoc_test_kernel_quiet=>/dev/null 53endif 54 55core-cfgs = \ 56 --cfg no_fp_fmt_parse 57 58core-edition := $(if $(call rustc-min-version,108700),2024,2021) 59 60# `rustdoc` did not save the target modifiers, thus workaround for 61# the time being (https://github.com/rust-lang/rust/issues/144521). 62rustdoc_modifiers_workaround := $(if $(call rustc-min-version,108800),-Cunsafe-allow-abi-mismatch=fixed-x18) 63 64quiet_cmd_rustdoc = RUSTDOC $(if $(rustdoc_host),H, ) $< 65 cmd_rustdoc = \ 66 OBJTREE=$(abspath $(objtree)) \ 67 $(RUSTDOC) $(filter-out $(skip_flags),$(if $(rustdoc_host),$(rust_common_flags),$(rust_flags))) \ 68 $(rustc_target_flags) -L$(objtree)/$(obj) \ 69 -Zunstable-options --generate-link-to-definition \ 70 --output $(rustdoc_output) \ 71 --crate-name $(subst rustdoc-,,$@) \ 72 $(rustdoc_modifiers_workaround) \ 73 $(if $(rustdoc_host),,--sysroot=/dev/null) \ 74 @$(objtree)/include/generated/rustc_cfg $< 75 76# The `html_logo_url` and `html_favicon_url` forms of the `doc` attribute 77# can be used to specify a custom logo. However: 78# - The given value is used as-is, thus it cannot be relative or a local file 79# (unlike the non-custom case) since the generated docs have subfolders. 80# - It requires adding it to every crate. 81# - It requires changing `core` which comes from the sysroot. 82# 83# Using `-Zcrate-attr` would solve the last two points, but not the first. 84# The https://github.com/rust-lang/rfcs/pull/3226 RFC suggests two new 85# command-like flags to solve the issue. Meanwhile, we use the non-custom case 86# and then retouch the generated files. 87rustdoc: rustdoc-core rustdoc-macros rustdoc-compiler_builtins \ 88 rustdoc-kernel 89 $(Q)cp $(srctree)/Documentation/images/logo.svg $(rustdoc_output)/static.files/ 90 $(Q)cp $(srctree)/Documentation/images/COPYING-logo $(rustdoc_output)/static.files/ 91 $(Q)find $(rustdoc_output) -name '*.html' -type f -print0 | xargs -0 sed -Ei \ 92 -e 's:rust-logo-[0-9a-f]+\.svg:logo.svg:g' \ 93 -e 's:favicon-[0-9a-f]+\.svg:logo.svg:g' \ 94 -e 's:<link rel="alternate icon" type="image/png" href="[/.]+/static\.files/favicon-(16x16|32x32)-[0-9a-f]+\.png">::g' \ 95 -e 's:<a href="srctree/([^"]+)">:<a href="$(realpath $(srctree))/\1">:g' 96 $(Q)for f in $(rustdoc_output)/static.files/rustdoc-*.css; do \ 97 echo ".logo-container > img { object-fit: contain; }" >> $$f; done 98 99rustdoc-macros: private rustdoc_host = yes 100rustdoc-macros: private rustc_target_flags = --crate-type proc-macro \ 101 --extern proc_macro 102rustdoc-macros: $(src)/macros/lib.rs rustdoc-clean FORCE 103 +$(call if_changed,rustdoc) 104 105# Starting with Rust 1.82.0, skipping `-Wrustdoc::unescaped_backticks` should 106# not be needed -- see https://github.com/rust-lang/rust/pull/128307. 107rustdoc-core: private skip_flags = --edition=2021 -Wrustdoc::unescaped_backticks 108rustdoc-core: private rustc_target_flags = --edition=$(core-edition) $(core-cfgs) 109rustdoc-core: $(RUST_LIB_SRC)/core/src/lib.rs rustdoc-clean FORCE 110 +$(call if_changed,rustdoc) 111 112rustdoc-compiler_builtins: $(src)/compiler_builtins.rs rustdoc-core FORCE 113 +$(call if_changed,rustdoc) 114 115rustdoc-ffi: $(src)/ffi.rs rustdoc-core FORCE 116 +$(call if_changed,rustdoc) 117 118rustdoc-kernel: private rustc_target_flags = --extern ffi \ 119 --extern build_error --extern macros=$(objtree)/$(obj)/libmacros.so \ 120 --extern bindings --extern uapi 121rustdoc-kernel: $(src)/kernel/lib.rs rustdoc-core rustdoc-ffi rustdoc-macros \ 122 rustdoc-compiler_builtins $(obj)/libmacros.so \ 123 $(obj)/bindings.o FORCE 124 +$(call if_changed,rustdoc) 125 126rustdoc-clean: FORCE 127 $(Q)rm -rf $(rustdoc_output) 128 129quiet_cmd_rustc_test_library = RUSTC TL $< 130 cmd_rustc_test_library = \ 131 OBJTREE=$(abspath $(objtree)) \ 132 $(RUSTC) $(rust_common_flags) \ 133 @$(objtree)/include/generated/rustc_cfg $(rustc_target_flags) \ 134 --crate-type $(if $(rustc_test_library_proc),proc-macro,rlib) \ 135 --out-dir $(objtree)/$(obj)/test --cfg testlib \ 136 -L$(objtree)/$(obj)/test \ 137 --crate-name $(subst rusttest-,,$(subst rusttestlib-,,$@)) $< 138 139rusttestlib-build_error: $(src)/build_error.rs FORCE 140 +$(call if_changed,rustc_test_library) 141 142rusttestlib-ffi: $(src)/ffi.rs FORCE 143 +$(call if_changed,rustc_test_library) 144 145rusttestlib-macros: private rustc_target_flags = --extern proc_macro 146rusttestlib-macros: private rustc_test_library_proc = yes 147rusttestlib-macros: $(src)/macros/lib.rs FORCE 148 +$(call if_changed,rustc_test_library) 149 150rusttestlib-kernel: private rustc_target_flags = --extern ffi \ 151 --extern build_error --extern macros \ 152 --extern bindings --extern uapi 153rusttestlib-kernel: $(src)/kernel/lib.rs \ 154 rusttestlib-bindings rusttestlib-uapi rusttestlib-build_error \ 155 $(obj)/libmacros.so $(obj)/bindings.o FORCE 156 +$(call if_changed,rustc_test_library) 157 158rusttestlib-bindings: private rustc_target_flags = --extern ffi 159rusttestlib-bindings: $(src)/bindings/lib.rs rusttestlib-ffi FORCE 160 +$(call if_changed,rustc_test_library) 161 162rusttestlib-uapi: private rustc_target_flags = --extern ffi 163rusttestlib-uapi: $(src)/uapi/lib.rs rusttestlib-ffi FORCE 164 +$(call if_changed,rustc_test_library) 165 166quiet_cmd_rustdoc_test = RUSTDOC T $< 167 cmd_rustdoc_test = \ 168 OBJTREE=$(abspath $(objtree)) \ 169 $(RUSTDOC) --test $(rust_common_flags) \ 170 -Zcrate-attr='feature(used_with_arg)' \ 171 @$(objtree)/include/generated/rustc_cfg \ 172 $(rustc_target_flags) $(rustdoc_test_target_flags) \ 173 $(rustdoc_test_quiet) \ 174 -L$(objtree)/$(obj)/test --output $(rustdoc_output) \ 175 --crate-name $(subst rusttest-,,$@) $< 176 177quiet_cmd_rustdoc_test_kernel = RUSTDOC TK $< 178 cmd_rustdoc_test_kernel = \ 179 rm -rf $(objtree)/$(obj)/test/doctests/kernel; \ 180 mkdir -p $(objtree)/$(obj)/test/doctests/kernel; \ 181 OBJTREE=$(abspath $(objtree)) \ 182 $(RUSTDOC) --test $(rust_flags) \ 183 -L$(objtree)/$(obj) --extern ffi --extern kernel \ 184 --extern build_error --extern macros \ 185 --extern bindings --extern uapi \ 186 --no-run --crate-name kernel -Zunstable-options \ 187 --sysroot=/dev/null \ 188 $(rustdoc_modifiers_workaround) \ 189 --test-builder $(objtree)/scripts/rustdoc_test_builder \ 190 $< $(rustdoc_test_kernel_quiet); \ 191 $(objtree)/scripts/rustdoc_test_gen 192 193%/doctests_kernel_generated.rs %/doctests_kernel_generated_kunit.c: \ 194 $(src)/kernel/lib.rs $(obj)/kernel.o \ 195 $(objtree)/scripts/rustdoc_test_builder \ 196 $(objtree)/scripts/rustdoc_test_gen FORCE 197 +$(call if_changed,rustdoc_test_kernel) 198 199# We cannot use `-Zpanic-abort-tests` because some tests are dynamic, 200# so for the moment we skip `-Cpanic=abort`. 201quiet_cmd_rustc_test = RUSTC T $< 202 cmd_rustc_test = \ 203 OBJTREE=$(abspath $(objtree)) \ 204 $(RUSTC) --test $(rust_common_flags) \ 205 @$(objtree)/include/generated/rustc_cfg \ 206 $(rustc_target_flags) --out-dir $(objtree)/$(obj)/test \ 207 -L$(objtree)/$(obj)/test \ 208 --crate-name $(subst rusttest-,,$@) $<; \ 209 $(objtree)/$(obj)/test/$(subst rusttest-,,$@) $(rust_test_quiet) \ 210 $(rustc_test_run_flags) 211 212rusttest: rusttest-macros rusttest-kernel 213 214rusttest-macros: private rustc_target_flags = --extern proc_macro \ 215 --extern macros --extern kernel 216rusttest-macros: private rustdoc_test_target_flags = --crate-type proc-macro 217rusttest-macros: $(src)/macros/lib.rs \ 218 rusttestlib-macros rusttestlib-kernel FORCE 219 +$(call if_changed,rustc_test) 220 +$(call if_changed,rustdoc_test) 221 222rusttest-kernel: private rustc_target_flags = --extern ffi \ 223 --extern build_error --extern macros --extern bindings --extern uapi 224rusttest-kernel: $(src)/kernel/lib.rs rusttestlib-ffi rusttestlib-kernel \ 225 rusttestlib-build_error rusttestlib-macros rusttestlib-bindings \ 226 rusttestlib-uapi FORCE 227 +$(call if_changed,rustc_test) 228 229ifdef CONFIG_CC_IS_CLANG 230bindgen_c_flags = $(c_flags) 231else 232# bindgen relies on libclang to parse C. Ideally, bindgen would support a GCC 233# plugin backend and/or the Clang driver would be perfectly compatible with GCC. 234# 235# For the moment, here we are tweaking the flags on the fly. This is a hack, 236# and some kernel configurations may not work (e.g. `GCC_PLUGIN_RANDSTRUCT` 237# if we end up using one of those structs). 238bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \ 239 -mskip-rax-setup -mgeneral-regs-only -msign-return-address=% \ 240 -mindirect-branch=thunk-extern -mindirect-branch-register \ 241 -mfunction-return=thunk-extern -mrecord-mcount -mabi=lp64 \ 242 -mindirect-branch-cs-prefix -mstack-protector-guard% -mtraceback=no \ 243 -mno-pointers-to-nested-functions -mno-string \ 244 -mno-strict-align -mstrict-align -mdirect-extern-access \ 245 -mexplicit-relocs -mno-check-zero-division \ 246 -fconserve-stack -falign-jumps=% -falign-loops=% \ 247 -femit-struct-debug-baseonly -fno-ipa-cp-clone -fno-ipa-sra \ 248 -fno-partial-inlining -fplugin-arg-arm_ssp_per_task_plugin-% \ 249 -fno-reorder-blocks -fno-allow-store-data-races -fasan-shadow-offset=% \ 250 -fzero-call-used-regs=% -fno-stack-clash-protection \ 251 -fno-inline-functions-called-once -fsanitize=bounds-strict \ 252 -fstrict-flex-arrays=% -fmin-function-alignment=% \ 253 -fzero-init-padding-bits=% -mno-fdpic \ 254 --param=% --param asan-% 255 256# Derived from `scripts/Makefile.clang`. 257BINDGEN_TARGET_x86 := x86_64-linux-gnu 258BINDGEN_TARGET_arm64 := aarch64-linux-gnu 259BINDGEN_TARGET_loongarch := loongarch64-linux-gnusf 260BINDGEN_TARGET := $(BINDGEN_TARGET_$(SRCARCH)) 261 262# All warnings are inhibited since GCC builds are very experimental, 263# many GCC warnings are not supported by Clang, they may only appear in 264# some configurations, with new GCC versions, etc. 265bindgen_extra_c_flags = -w --target=$(BINDGEN_TARGET) 266 267# Auto variable zero-initialization requires an additional special option with 268# clang that is going to be removed sometime in the future (likely in 269# clang-18), so make sure to pass this option only if clang supports it 270# (libclang major version < 16). 271# 272# https://github.com/llvm/llvm-project/issues/44842 273# https://github.com/llvm/llvm-project/blob/llvmorg-16.0.0-rc2/clang/docs/ReleaseNotes.rst#deprecated-compiler-flags 274ifdef CONFIG_INIT_STACK_ALL_ZERO 275libclang_maj_ver=$(shell $(BINDGEN) $(srctree)/scripts/rust_is_available_bindgen_libclang.h 2>&1 | sed -ne 's/.*clang version \([0-9]*\).*/\1/p') 276ifeq ($(shell expr $(libclang_maj_ver) \< 16), 1) 277bindgen_extra_c_flags += -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang 278endif 279endif 280 281bindgen_c_flags = $(filter-out $(bindgen_skip_c_flags), $(c_flags)) \ 282 $(bindgen_extra_c_flags) 283endif 284 285ifdef CONFIG_LTO 286bindgen_c_flags_lto = $(filter-out $(CC_FLAGS_LTO), $(bindgen_c_flags)) 287else 288bindgen_c_flags_lto = $(bindgen_c_flags) 289endif 290 291# `-fno-builtin` is passed to avoid `bindgen` from using `clang` builtin 292# prototypes for functions like `memcpy` -- if this flag is not passed, 293# `bindgen`-generated prototypes use `c_ulong` or `c_uint` depending on 294# architecture instead of generating `usize`. 295bindgen_c_flags_final = $(bindgen_c_flags_lto) -fno-builtin -D__BINDGEN__ 296 297# Each `bindgen` release may upgrade the list of Rust target versions. By 298# default, the highest stable release in their list is used. Thus we need to set 299# a `--rust-target` to avoid future `bindgen` releases emitting code that 300# `rustc` may not understand. On top of that, `bindgen` does not support passing 301# an unknown Rust target version. 302# 303# Therefore, the Rust target for `bindgen` can be only as high as the minimum 304# Rust version the kernel supports and only as high as the greatest stable Rust 305# target supported by the minimum `bindgen` version the kernel supports (that 306# is, if we do not test the actual `rustc`/`bindgen` versions running). 307# 308# Starting with `bindgen` 0.71.0, we will be able to set any future Rust version 309# instead, i.e. we will be able to set here our minimum supported Rust version. 310quiet_cmd_bindgen = BINDGEN $@ 311 cmd_bindgen = \ 312 $(BINDGEN) $< $(bindgen_target_flags) --rust-target 1.68 \ 313 --use-core --with-derive-default --ctypes-prefix ffi --no-layout-tests \ 314 --no-debug '.*' --enable-function-attribute-detection \ 315 -o $@ -- $(bindgen_c_flags_final) -DMODULE \ 316 $(bindgen_target_cflags) $(bindgen_target_extra) 317 318$(obj)/bindings/bindings_generated.rs: private bindgen_target_flags = \ 319 $(shell grep -Ev '^#|^$$' $(src)/bindgen_parameters) 320$(obj)/bindings/bindings_generated.rs: private bindgen_target_extra = ; \ 321 sed -Ei 's/pub const RUST_CONST_HELPER_([a-zA-Z0-9_]*)/pub const \1/g' $@ 322$(obj)/bindings/bindings_generated.rs: $(src)/bindings/bindings_helper.h \ 323 $(src)/bindgen_parameters FORCE 324 $(call if_changed_dep,bindgen) 325 326$(obj)/uapi/uapi_generated.rs: private bindgen_target_flags = \ 327 $(shell grep -Ev '^#|^$$' $(src)/bindgen_parameters) 328$(obj)/uapi/uapi_generated.rs: $(src)/uapi/uapi_helper.h \ 329 $(src)/bindgen_parameters FORCE 330 $(call if_changed_dep,bindgen) 331 332# See `CFLAGS_REMOVE_helpers.o` above. In addition, Clang on C does not warn 333# with `-Wmissing-declarations` (unlike GCC), so it is not strictly needed here 334# given it is `libclang`; but for consistency, future Clang changes and/or 335# a potential future GCC backend for `bindgen`, we disable it too. 336$(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_flags = \ 337 --blocklist-type '.*' --allowlist-var '' \ 338 --allowlist-function 'rust_helper_.*' 339$(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_cflags = \ 340 -I$(objtree)/$(obj) -Wno-missing-prototypes -Wno-missing-declarations 341$(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_extra = ; \ 342 sed -Ei 's/pub fn rust_helper_([a-zA-Z0-9_]*)/#[link_name="rust_helper_\1"]\n pub fn \1/g' $@ 343$(obj)/bindings/bindings_helpers_generated.rs: $(src)/helpers/helpers.c FORCE 344 $(call if_changed_dep,bindgen) 345 346rust_exports = $(NM) -p --defined-only $(1) | awk '$$2~/(T|R|D|B)/ && $$3!~/__cfi/ && $$3!~/__odr_asan/ { printf $(2),$$3 }' 347 348quiet_cmd_exports = EXPORTS $@ 349 cmd_exports = \ 350 $(call rust_exports,$<,"EXPORT_SYMBOL_RUST_GPL(%s);\n") > $@ 351 352$(obj)/exports_core_generated.h: $(obj)/core.o FORCE 353 $(call if_changed,exports) 354 355# Even though Rust kernel modules should never use the bindings directly, 356# symbols from the `bindings` crate and the C helpers need to be exported 357# because Rust generics and inlined functions may not get their code generated 358# in the crate where they are defined. Other helpers, called from non-inline 359# functions, may not be exported, in principle. However, in general, the Rust 360# compiler does not guarantee codegen will be performed for a non-inline 361# function either. Therefore, we export all symbols from helpers and bindings. 362# In the future, this may be revisited to reduce the number of exports after 363# the compiler is informed about the places codegen is required. 364$(obj)/exports_helpers_generated.h: $(obj)/helpers/helpers.o FORCE 365 $(call if_changed,exports) 366 367$(obj)/exports_bindings_generated.h: $(obj)/bindings.o FORCE 368 $(call if_changed,exports) 369 370$(obj)/exports_kernel_generated.h: $(obj)/kernel.o FORCE 371 $(call if_changed,exports) 372 373quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@ 374 cmd_rustc_procmacro = \ 375 $(RUSTC_OR_CLIPPY) $(rust_common_flags) \ 376 -Clinker-flavor=gcc -Clinker=$(HOSTCC) \ 377 -Clink-args='$(call escsq,$(KBUILD_PROCMACROLDFLAGS))' \ 378 --emit=dep-info=$(depfile) --emit=link=$@ --extern proc_macro \ 379 --crate-type proc-macro \ 380 --crate-name $(patsubst lib%.so,%,$(notdir $@)) $< 381 382# Procedural macros can only be used with the `rustc` that compiled it. 383$(obj)/libmacros.so: $(src)/macros/lib.rs FORCE 384 +$(call if_changed_dep,rustc_procmacro) 385 386quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L $@ 387 cmd_rustc_library = \ 388 OBJTREE=$(abspath $(objtree)) \ 389 $(if $(skip_clippy),$(RUSTC),$(RUSTC_OR_CLIPPY)) \ 390 $(filter-out $(skip_flags),$(rust_flags)) $(rustc_target_flags) \ 391 --emit=dep-info=$(depfile) --emit=obj=$@ \ 392 --emit=metadata=$(dir $@)$(patsubst %.o,lib%.rmeta,$(notdir $@)) \ 393 --crate-type rlib -L$(objtree)/$(obj) \ 394 --crate-name $(patsubst %.o,%,$(notdir $@)) $< \ 395 --sysroot=/dev/null \ 396 $(if $(rustc_objcopy),;$(OBJCOPY) $(rustc_objcopy) $@) \ 397 $(cmd_objtool) 398 399rust-analyzer: 400 $(Q)$(srctree)/scripts/generate_rust_analyzer.py \ 401 --cfgs='core=$(core-cfgs)' $(core-edition) \ 402 $(realpath $(srctree)) $(realpath $(objtree)) \ 403 $(rustc_sysroot) $(RUST_LIB_SRC) $(KBUILD_EXTMOD) > \ 404 $(if $(KBUILD_EXTMOD),$(extmod_prefix),$(objtree))/rust-project.json 405 406redirect-intrinsics = \ 407 __addsf3 __eqsf2 __extendsfdf2 __gesf2 __lesf2 __ltsf2 __mulsf3 __nesf2 __truncdfsf2 __unordsf2 \ 408 __adddf3 __eqdf2 __ledf2 __ltdf2 __muldf3 __unorddf2 \ 409 __muloti4 __multi3 \ 410 __udivmodti4 __udivti3 __umodti3 411 412ifneq ($(or $(CONFIG_ARM64),$(and $(CONFIG_RISCV),$(CONFIG_64BIT))),) 413 # These intrinsics are defined for ARM64 and RISCV64 414 redirect-intrinsics += \ 415 __ashrti3 \ 416 __ashlti3 __lshrti3 417endif 418 419ifdef CONFIG_MODVERSIONS 420cmd_gendwarfksyms = $(if $(skip_gendwarfksyms),, \ 421 $(call rust_exports,$@,"%s\n") | \ 422 scripts/gendwarfksyms/gendwarfksyms \ 423 $(if $(KBUILD_GENDWARFKSYMS_STABLE), --stable) \ 424 $(if $(KBUILD_SYMTYPES), --symtypes $(@:.o=.symtypes),) \ 425 $@ >> $(dot-target).cmd) 426endif 427 428define rule_rustc_library 429 $(call cmd_and_fixdep,rustc_library) 430 $(call cmd,gen_objtooldep) 431 $(call cmd,gendwarfksyms) 432endef 433 434define rule_rust_cc_library 435 $(call if_changed_rule,cc_o_c) 436 $(call cmd,force_checksrc) 437 $(call cmd,gendwarfksyms) 438endef 439 440# helpers.o uses the same export mechanism as Rust libraries, so ensure symbol 441# versions are calculated for the helpers too. 442$(obj)/helpers/helpers.o: $(src)/helpers/helpers.c $(recordmcount_source) FORCE 443 +$(call if_changed_rule,rust_cc_library) 444 445# Disable symbol versioning for exports.o to avoid conflicts with the actual 446# symbol versions generated from Rust objects. 447$(obj)/exports.o: private skip_gendwarfksyms = 1 448 449$(obj)/core.o: private skip_clippy = 1 450$(obj)/core.o: private skip_flags = --edition=2021 -Wunreachable_pub 451$(obj)/core.o: private rustc_objcopy = $(foreach sym,$(redirect-intrinsics),--redefine-sym $(sym)=__rust$(sym)) 452$(obj)/core.o: private rustc_target_flags = --edition=$(core-edition) $(core-cfgs) 453$(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs \ 454 $(wildcard $(objtree)/include/config/RUSTC_VERSION_TEXT) FORCE 455 +$(call if_changed_rule,rustc_library) 456ifneq ($(or $(CONFIG_X86_64),$(CONFIG_X86_32)),) 457$(obj)/core.o: scripts/target.json 458endif 459KCOV_INSTRUMENT_core.o := n 460 461$(obj)/compiler_builtins.o: private skip_gendwarfksyms = 1 462$(obj)/compiler_builtins.o: private rustc_objcopy = -w -W '__*' 463$(obj)/compiler_builtins.o: $(src)/compiler_builtins.rs $(obj)/core.o FORCE 464 +$(call if_changed_rule,rustc_library) 465 466 467$(obj)/build_error.o: private skip_gendwarfksyms = 1 468$(obj)/build_error.o: $(src)/build_error.rs $(obj)/compiler_builtins.o FORCE 469 +$(call if_changed_rule,rustc_library) 470 471$(obj)/ffi.o: private skip_gendwarfksyms = 1 472$(obj)/ffi.o: $(src)/ffi.rs $(obj)/compiler_builtins.o FORCE 473 +$(call if_changed_rule,rustc_library) 474 475$(obj)/bindings.o: private rustc_target_flags = --extern ffi 476$(obj)/bindings.o: $(src)/bindings/lib.rs \ 477 $(obj)/ffi.o \ 478 $(obj)/bindings/bindings_generated.rs \ 479 $(obj)/bindings/bindings_helpers_generated.rs FORCE 480 +$(call if_changed_rule,rustc_library) 481 482$(obj)/uapi.o: private rustc_target_flags = --extern ffi 483$(obj)/uapi.o: private skip_gendwarfksyms = 1 484$(obj)/uapi.o: $(src)/uapi/lib.rs \ 485 $(obj)/ffi.o \ 486 $(obj)/uapi/uapi_generated.rs FORCE 487 +$(call if_changed_rule,rustc_library) 488 489$(obj)/kernel.o: private rustc_target_flags = --extern ffi \ 490 --extern build_error --extern macros --extern bindings --extern uapi 491$(obj)/kernel.o: $(src)/kernel/lib.rs $(obj)/build_error.o \ 492 $(obj)/libmacros.so $(obj)/bindings.o $(obj)/uapi.o FORCE 493 +$(call if_changed_rule,rustc_library) 494 495ifdef CONFIG_JUMP_LABEL 496$(obj)/kernel.o: $(obj)/kernel/generated_arch_static_branch_asm.rs 497endif 498 499endif # CONFIG_RUST 500