Skip to content

Commit fc3f4fb

Browse files
hoshinolinajannau
authored andcommitted
rust: Use absolute paths to build Rust objects
We want to use caller_location to uniquely identify callsites, to automatically create lockdep classes without macros. The location filename in local code uses the relative path passed to the compiler, but if that code is generic and instantiated from another crate, the path becomes absolute. To make this work and keep the paths consistent, always pass an absolute path to the compiler. Then the Location path is always identical regardless of how the code is being compiled. Signed-off-by: Asahi Lina <lina@asahilina.net>
1 parent 9324f86 commit fc3f4fb

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

rust/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L
339339
--emit=dep-info=$(depfile) --emit=obj=$@ \
340340
--emit=metadata=$(dir $@)$(patsubst %.o,lib%.rmeta,$(notdir $@)) \
341341
--crate-type rlib -L$(objtree)/$(obj) \
342-
--crate-name $(patsubst %.o,%,$(notdir $@)) $< \
342+
--crate-name $(patsubst %.o,%,$(notdir $@)) $(abspath $<) \
343343
--sysroot=/dev/null \
344344
$(if $(rustc_objcopy),;$(OBJCOPY) $(rustc_objcopy) $@) \
345345
$(cmd_objtool)

scripts/Makefile.build

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ rust_common_cmd = \
273273
# would not match each other.
274274

275275
quiet_cmd_rustc_o_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
276-
cmd_rustc_o_rs = $(rust_common_cmd) --emit=obj=$@ $< $(cmd_objtool)
276+
cmd_rustc_o_rs = $(rust_common_cmd) --emit=obj=$@ $(abspath $<) $(cmd_objtool)
277277

278278
define rule_rustc_o_rs
279279
$(call cmd_and_fixdep,rustc_o_rs)
@@ -285,20 +285,20 @@ $(obj)/%.o: $(obj)/%.rs FORCE
285285

286286
quiet_cmd_rustc_rsi_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
287287
cmd_rustc_rsi_rs = \
288-
$(rust_common_cmd) -Zunpretty=expanded $< >$@; \
288+
$(rust_common_cmd) -Zunpretty=expanded $(abspath $<) >$@; \
289289
command -v $(RUSTFMT) >/dev/null && $(RUSTFMT) $@
290290

291291
$(obj)/%.rsi: $(obj)/%.rs FORCE
292292
+$(call if_changed_dep,rustc_rsi_rs)
293293

294294
quiet_cmd_rustc_s_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
295-
cmd_rustc_s_rs = $(rust_common_cmd) --emit=asm=$@ $<
295+
cmd_rustc_s_rs = $(rust_common_cmd) --emit=asm=$@ $(abspath $<)
296296

297297
$(obj)/%.s: $(obj)/%.rs FORCE
298298
+$(call if_changed_dep,rustc_s_rs)
299299

300300
quiet_cmd_rustc_ll_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
301-
cmd_rustc_ll_rs = $(rust_common_cmd) --emit=llvm-ir=$@ $<
301+
cmd_rustc_ll_rs = $(rust_common_cmd) --emit=llvm-ir=$@ $(abspath $<)
302302

303303
$(obj)/%.ll: $(obj)/%.rs FORCE
304304
+$(call if_changed_dep,rustc_ll_rs)

0 commit comments

Comments
 (0)