Skip to content

Commit 5735c25

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 abf56d8 commit 5735c25

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

scripts/Makefile.build

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

243243
quiet_cmd_rustc_o_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
244-
cmd_rustc_o_rs = $(rust_common_cmd) --emit=obj=$@ $< $(cmd_objtool)
244+
cmd_rustc_o_rs = $(rust_common_cmd) --emit=obj=$@ $(abspath $<) $(cmd_objtool)
245245

246246
define rule_rustc_o_rs
247247
$(call cmd_and_fixdep,rustc_o_rs)
@@ -253,20 +253,20 @@ $(obj)/%.o: $(obj)/%.rs FORCE
253253

254254
quiet_cmd_rustc_rsi_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
255255
cmd_rustc_rsi_rs = \
256-
$(rust_common_cmd) -Zunpretty=expanded $< >$@; \
256+
$(rust_common_cmd) -Zunpretty=expanded $(abspath $<) >$@; \
257257
command -v $(RUSTFMT) >/dev/null && $(RUSTFMT) $@
258258

259259
$(obj)/%.rsi: $(obj)/%.rs FORCE
260260
+$(call if_changed_dep,rustc_rsi_rs)
261261

262262
quiet_cmd_rustc_s_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
263-
cmd_rustc_s_rs = $(rust_common_cmd) --emit=asm=$@ $<
263+
cmd_rustc_s_rs = $(rust_common_cmd) --emit=asm=$@ $(abspath $<)
264264

265265
$(obj)/%.s: $(obj)/%.rs FORCE
266266
+$(call if_changed_dep,rustc_s_rs)
267267

268268
quiet_cmd_rustc_ll_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
269-
cmd_rustc_ll_rs = $(rust_common_cmd) --emit=llvm-ir=$@ $<
269+
cmd_rustc_ll_rs = $(rust_common_cmd) --emit=llvm-ir=$@ $(abspath $<)
270270

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

0 commit comments

Comments
 (0)