History

objtool/kbuild/rust: enable objtool for Rust

Now that we should be `objtool`-warning free, enable `objtool` for Rust too. Before this patch series, we were already getting warnings under e.g. IBT builds, since those would see Rust code via `vmlinux.o`.

Miguel Ojeda committed 2 years ago

Commit c4d7f541 parent 56d680d2 files · +21 −10Browse files

Unified · Split

2 files
  1. rust/Makefile +14 −8
  2. scripts/Makefile.build +7 −2
rust/Makefile+14−8
@@ -344,7 +344,8 @@ quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L · 343 unmodified lines
344344 --crate-type rlib -L$(objtree)/$(obj) \
345345 --crate-name $(patsubst %.o,%,$(notdir $@)) $< \
346346 --sysroot=/dev/null \
347− $(if $(rustc_objcopy),;$(OBJCOPY) $(rustc_objcopy) $@)
347+ $(if $(rustc_objcopy),;$(OBJCOPY) $(rustc_objcopy) $@) \
348+ $(cmd_objtool)
348349
349350 rust-analyzer:
350351 $(Q)$(srctree)/scripts/generate_rust_analyzer.py \
@@ -366,44 +367,49 @@ ifneq ($(or $(CONFIG_ARM64),$(and $(CONFIG_RISCV),$(CONFIG_64BIT))),) · 15 unmodified lines
366367 __ashlti3 __lshrti3
367368 endif
368369
370+define rule_rustc_library
371+ $(call cmd_and_fixdep,rustc_library)
372+ $(call cmd,gen_objtooldep)
373+endef
374+
369375 $(obj)/core.o: private skip_clippy = 1
370376 $(obj)/core.o: private skip_flags = -Wunreachable_pub
371377 $(obj)/core.o: private rustc_objcopy = $(foreach sym,$(redirect-intrinsics),--redefine-sym $(sym)=__rust$(sym))
372378 $(obj)/core.o: private rustc_target_flags = $(core-cfgs)
373379 $(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs FORCE
374− +$(call if_changed_dep,rustc_library)
380+ +$(call if_changed_rule,rustc_library)
375381 ifneq ($(or $(CONFIG_X86_64),$(CONFIG_X86_32)),)
376382 $(obj)/core.o: scripts/target.json
377383 endif
378384
379385 $(obj)/compiler_builtins.o: private rustc_objcopy = -w -W '__*'
380386 $(obj)/compiler_builtins.o: $(src)/compiler_builtins.rs $(obj)/core.o FORCE
381− +$(call if_changed_dep,rustc_library)
387+ +$(call if_changed_rule,rustc_library)
382388
383389 $(obj)/alloc.o: private skip_clippy = 1
384390 $(obj)/alloc.o: private skip_flags = -Wunreachable_pub
385391 $(obj)/alloc.o: private rustc_target_flags = $(alloc-cfgs)
386392 $(obj)/alloc.o: $(RUST_LIB_SRC)/alloc/src/lib.rs $(obj)/compiler_builtins.o FORCE
387− +$(call if_changed_dep,rustc_library)
393+ +$(call if_changed_rule,rustc_library)
388394
389395 $(obj)/build_error.o: $(src)/build_error.rs $(obj)/compiler_builtins.o FORCE
390− +$(call if_changed_dep,rustc_library)
396+ +$(call if_changed_rule,rustc_library)
391397
392398 $(obj)/bindings.o: $(src)/bindings/lib.rs \
393399 $(obj)/compiler_builtins.o \
394400 $(obj)/bindings/bindings_generated.rs \
395401 $(obj)/bindings/bindings_helpers_generated.rs FORCE
396− +$(call if_changed_dep,rustc_library)
402+ +$(call if_changed_rule,rustc_library)
397403
398404 $(obj)/uapi.o: $(src)/uapi/lib.rs \
399405 $(obj)/compiler_builtins.o \
400406 $(obj)/uapi/uapi_generated.rs FORCE
401− +$(call if_changed_dep,rustc_library)
407+ +$(call if_changed_rule,rustc_library)
402408
403409 $(obj)/kernel.o: private rustc_target_flags = --extern alloc \
404410 --extern build_error --extern macros --extern bindings --extern uapi
405411 $(obj)/kernel.o: $(src)/kernel/lib.rs $(obj)/alloc.o $(obj)/build_error.o \
406412 $(obj)/libmacros.so $(obj)/bindings.o $(obj)/uapi.o FORCE
407− +$(call if_changed_dep,rustc_library)
413+ +$(call if_changed_rule,rustc_library)
408414
409415 endif # CONFIG_RUST
scripts/Makefile.build+7−2
@@ -288,10 +288,15 @@ rust_common_cmd = \ · 287 unmodified lines
288288 # would not match each other.
289289
290290 quiet_cmd_rustc_o_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
291− cmd_rustc_o_rs = $(rust_common_cmd) --emit=obj=$@ $<
291+ cmd_rustc_o_rs = $(rust_common_cmd) --emit=obj=$@ $< $(cmd_objtool)
292+
293+define rule_rustc_o_rs
294+ $(call cmd_and_fixdep,rustc_o_rs)
295+ $(call cmd,gen_objtooldep)
296+endef
292297
293298 $(obj)/%.o: $(obj)/%.rs FORCE
294− +$(call if_changed_dep,rustc_o_rs)
299+ +$(call if_changed_rule,rustc_o_rs)
295300
296301 quiet_cmd_rustc_rsi_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
297302 cmd_rustc_rsi_rs = \