Skip to content

Commit d461380

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 d097124 commit d461380

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
@@ -382,7 +382,7 @@ quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L
382382
--emit=dep-info=$(depfile) --emit=obj=$@ \
383383
--emit=metadata=$(dir $@)$(patsubst %.o,lib%.rmeta,$(notdir $@)) \
384384
--crate-type rlib -L$(objtree)/$(obj) \
385-
--crate-name $(patsubst %.o,%,$(notdir $@)) $< \
385+
--crate-name $(patsubst %.o,%,$(notdir $@)) $(abspath $<) \
386386
--sysroot=/dev/null \
387387
$(if $(rustc_objcopy),;$(OBJCOPY) $(rustc_objcopy) $@) \
388388
$(cmd_objtool)

scripts/Makefile.build

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

254254
quiet_cmd_rustc_o_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
255-
cmd_rustc_o_rs = $(rust_common_cmd) --emit=obj=$@ $< $(cmd_objtool)
255+
cmd_rustc_o_rs = $(rust_common_cmd) --emit=obj=$@ $(abspath $<) $(cmd_objtool)
256256

257257
define rule_rustc_o_rs
258258
$(call cmd_and_fixdep,rustc_o_rs)
@@ -264,20 +264,20 @@ $(obj)/%.o: $(obj)/%.rs FORCE
264264

265265
quiet_cmd_rustc_rsi_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
266266
cmd_rustc_rsi_rs = \
267-
$(rust_common_cmd) -Zunpretty=expanded $< >$@; \
267+
$(rust_common_cmd) -Zunpretty=expanded $(abspath $<) >$@; \
268268
command -v $(RUSTFMT) >/dev/null && $(RUSTFMT) $@
269269

270270
$(obj)/%.rsi: $(obj)/%.rs FORCE
271271
+$(call if_changed_dep,rustc_rsi_rs)
272272

273273
quiet_cmd_rustc_s_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
274-
cmd_rustc_s_rs = $(rust_common_cmd) --emit=asm=$@ $<
274+
cmd_rustc_s_rs = $(rust_common_cmd) --emit=asm=$@ $(abspath $<)
275275

276276
$(obj)/%.s: $(obj)/%.rs FORCE
277277
+$(call if_changed_dep,rustc_s_rs)
278278

279279
quiet_cmd_rustc_ll_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
280-
cmd_rustc_ll_rs = $(rust_common_cmd) --emit=llvm-ir=$@ $<
280+
cmd_rustc_ll_rs = $(rust_common_cmd) --emit=llvm-ir=$@ $(abspath $<)
281281

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

0 commit comments

Comments
 (0)