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
344 --crate-type rlib -L$(objtree)/$(obj) \344 --crate-type rlib -L$(objtree)/$(obj) \
345 --crate-name $(patsubst %.o,%,$(notdir $@)) $< \345 --crate-name $(patsubst %.o,%,$(notdir $@)) $< \
346 --sysroot=/dev/null \346 --sysroot=/dev/null \
347 $(if $(rustc_objcopy),;$(OBJCOPY) $(rustc_objcopy) $@)347 $(if $(rustc_objcopy),;$(OBJCOPY) $(rustc_objcopy) $@) \
348 $(cmd_objtool)
348 349
349rust-analyzer:350rust-analyzer:
350 $(Q)$(srctree)/scripts/generate_rust_analyzer.py \351 $(Q)$(srctree)/scripts/generate_rust_analyzer.py \
@@ -366,44 +367,49 @@ ifneq ($(or $(CONFIG_ARM64),$(and $(CONFIG_RISCV),$(CONFIG_64BIT))),) · 15 unmodified lines
366 __ashlti3 __lshrti3367 __ashlti3 __lshrti3
367endif368endif
368 369
370define rule_rustc_library
371 $(call cmd_and_fixdep,rustc_library)
372 $(call cmd,gen_objtooldep)
373endef
374
369$(obj)/core.o: private skip_clippy = 1375$(obj)/core.o: private skip_clippy = 1
370$(obj)/core.o: private skip_flags = -Wunreachable_pub376$(obj)/core.o: private skip_flags = -Wunreachable_pub
371$(obj)/core.o: private rustc_objcopy = $(foreach sym,$(redirect-intrinsics),--redefine-sym $(sym)=__rust$(sym))377$(obj)/core.o: private rustc_objcopy = $(foreach sym,$(redirect-intrinsics),--redefine-sym $(sym)=__rust$(sym))
372$(obj)/core.o: private rustc_target_flags = $(core-cfgs)378$(obj)/core.o: private rustc_target_flags = $(core-cfgs)
373$(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs FORCE379$(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)
375ifneq ($(or $(CONFIG_X86_64),$(CONFIG_X86_32)),)381ifneq ($(or $(CONFIG_X86_64),$(CONFIG_X86_32)),)
376$(obj)/core.o: scripts/target.json382$(obj)/core.o: scripts/target.json
377endif383endif
378 384
379$(obj)/compiler_builtins.o: private rustc_objcopy = -w -W '__*'385$(obj)/compiler_builtins.o: private rustc_objcopy = -w -W '__*'
380$(obj)/compiler_builtins.o: $(src)/compiler_builtins.rs $(obj)/core.o FORCE386$(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)
382 388
383$(obj)/alloc.o: private skip_clippy = 1389$(obj)/alloc.o: private skip_clippy = 1
384$(obj)/alloc.o: private skip_flags = -Wunreachable_pub390$(obj)/alloc.o: private skip_flags = -Wunreachable_pub
385$(obj)/alloc.o: private rustc_target_flags = $(alloc-cfgs)391$(obj)/alloc.o: private rustc_target_flags = $(alloc-cfgs)
386$(obj)/alloc.o: $(RUST_LIB_SRC)/alloc/src/lib.rs $(obj)/compiler_builtins.o FORCE392$(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)
388 394
389$(obj)/build_error.o: $(src)/build_error.rs $(obj)/compiler_builtins.o FORCE395$(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)
391 397
392$(obj)/bindings.o: $(src)/bindings/lib.rs \398$(obj)/bindings.o: $(src)/bindings/lib.rs \
393 $(obj)/compiler_builtins.o \399 $(obj)/compiler_builtins.o \
394 $(obj)/bindings/bindings_generated.rs \400 $(obj)/bindings/bindings_generated.rs \
395 $(obj)/bindings/bindings_helpers_generated.rs FORCE401 $(obj)/bindings/bindings_helpers_generated.rs FORCE
396 +$(call if_changed_dep,rustc_library)402 +$(call if_changed_rule,rustc_library)
397 403
398$(obj)/uapi.o: $(src)/uapi/lib.rs \404$(obj)/uapi.o: $(src)/uapi/lib.rs \
399 $(obj)/compiler_builtins.o \405 $(obj)/compiler_builtins.o \
400 $(obj)/uapi/uapi_generated.rs FORCE406 $(obj)/uapi/uapi_generated.rs FORCE
401 +$(call if_changed_dep,rustc_library)407 +$(call if_changed_rule,rustc_library)
402 408
403$(obj)/kernel.o: private rustc_target_flags = --extern alloc \409$(obj)/kernel.o: private rustc_target_flags = --extern alloc \
404 --extern build_error --extern macros --extern bindings --extern uapi410 --extern build_error --extern macros --extern bindings --extern uapi
405$(obj)/kernel.o: $(src)/kernel/lib.rs $(obj)/alloc.o $(obj)/build_error.o \411$(obj)/kernel.o: $(src)/kernel/lib.rs $(obj)/alloc.o $(obj)/build_error.o \
406 $(obj)/libmacros.so $(obj)/bindings.o $(obj)/uapi.o FORCE412 $(obj)/libmacros.so $(obj)/bindings.o $(obj)/uapi.o FORCE
407 +$(call if_changed_dep,rustc_library)413 +$(call if_changed_rule,rustc_library)
408 414
409endif # CONFIG_RUST415endif # CONFIG_RUST
scripts/Makefile.build+7−2
@@ -288,10 +288,15 @@ rust_common_cmd = \ · 287 unmodified lines
288# would not match each other.288# would not match each other.
289 289
290quiet_cmd_rustc_o_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@290quiet_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
293define rule_rustc_o_rs
294 $(call cmd_and_fixdep,rustc_o_rs)
295 $(call cmd,gen_objtooldep)
296endef
292 297
293$(obj)/%.o: $(obj)/%.rs FORCE298$(obj)/%.o: $(obj)/%.rs FORCE
294 +$(call if_changed_dep,rustc_o_rs)299 +$(call if_changed_rule,rustc_o_rs)
295 300
296quiet_cmd_rustc_rsi_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@301quiet_cmd_rustc_rsi_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
297 cmd_rustc_rsi_rs = \302 cmd_rustc_rsi_rs = \