* [PATCH] rust: build: remap path to avoid absolute path
@ 2026-02-07 14:43 Gary Guo
2026-02-07 15:22 ` Miguel Ojeda
0 siblings, 1 reply; 6+ messages in thread
From: Gary Guo @ 2026-02-07 14:43 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Nathan Chancellor, Nicolas Schier
Cc: Janne Grunau, Asahi Lina, rust-for-linux, linux-kernel,
linux-kbuild
From: Gary Guo <gary@garyguo.net>
When building with a out directory (O=), absolute paths can end up in the
file name in `#[track_caller]` or the panic message. This is not desirable
as this leaks the exact path being used to build the kernel into the binary
which is not very helpful to achieve reproducibility. It also means that
the same location can appear in two forms (relative or absolute).
This is reported by Asahi [1] and is being workaround in [2] previously to
force everything to be absolute path. Using absolute path for everything
sovles the inconsistency, however it does not address the reproducibility
issue. So, fix this by remap all absolute paths to srctree to relative path
instead.
This change can be validated by building a kernel with O=, strip debug info
on vmlinux, and then check if the absolute path exists in `strings vmlinux`,
e.g. `strings vmlinux |grep \/home`.
Reported-by: Janne Grunau <j@jannau.net>
Reported-by: Asahi Lina <lina+kernel@asahilina.net>
Closes: https://rust-for-linux.zulipchat.com/#narrow/channel/288089-General/topic/Per-call-site.20data.20and.20lock.20class.20keys/near/572466559 [1]
Link: https://github.com/AsahiLinux/linux/commit/54ab88878869036c9d6620101bfe17a81e88c2f9 [2]
Signed-off-by: Gary Guo <gary@garyguo.net>
---
rust/Makefile | 1 +
scripts/Makefile.build | 1 +
2 files changed, 2 insertions(+)
diff --git a/rust/Makefile b/rust/Makefile
index 629b3bdd2b20..598d2efede32 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -582,6 +582,7 @@ quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L
--crate-type rlib -L$(objtree)/$(obj) \
--crate-name $(patsubst %.o,%,$(notdir $@)) $< \
--sysroot=/dev/null \
+ --remap-path-prefix=$(abspath $(srctree))= \
-Zunstable-options \
$(if $(rustc_objcopy),;$(OBJCOPY) $(rustc_objcopy) $@) \
$(cmd_objtool)
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 204e58dd1bb0..03dde30e953c 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -333,6 +333,7 @@ rust_common_cmd = \
--crate-type rlib -L $(objtree)/rust/ \
--crate-name $(basename $(notdir $@)) \
--sysroot=/dev/null \
+ --remap-path-prefix=$(abspath $(srctree))= \
--out-dir $(dir $@) --emit=dep-info=$(depfile)
# `--emit=obj`, `--emit=asm` and `--emit=llvm-ir` imply a single codegen unit
base-commit: 36896083ef4dbc302e406f01975a227784160cf8
--
2.51.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] rust: build: remap path to avoid absolute path
2026-02-07 14:43 [PATCH] rust: build: remap path to avoid absolute path Gary Guo
@ 2026-02-07 15:22 ` Miguel Ojeda
2026-02-07 16:43 ` Gary Guo
0 siblings, 1 reply; 6+ messages in thread
From: Miguel Ojeda @ 2026-02-07 15:22 UTC (permalink / raw)
To: Gary Guo, Nathan Chancellor, Nicolas Schier
Cc: Miguel Ojeda, Boqun Feng, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
Janne Grunau, Asahi Lina, rust-for-linux, linux-kernel,
linux-kbuild
On Sat, Feb 7, 2026 at 3:44 PM Gary Guo <gary@kernel.org> wrote:
>
> So, fix this by remap all absolute paths to srctree to relative path
> instead.
In case it matters to Kbuild, we had a relatively recent revert
related to this flag:
dbdffaf50ff9 ("kbuild, rust: use -fremap-path-prefix to make paths relative")
8cf5b3f83614 ("Revert "kbuild, rust: use -fremap-path-prefix to make
paths relative"")
https://lore.kernel.org/rust-for-linux/20250511-kbuild-revert-file-prefix-map-v1-0-9ba640c8411e@weissschuh.net/
From what I see in the thread (but I didn't get a confirmation back
then), the issue was some developers relying on invoking the debugger
in a different working directory than the `srctree`.
Thanks Gary!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] rust: build: remap path to avoid absolute path
2026-02-07 15:22 ` Miguel Ojeda
@ 2026-02-07 16:43 ` Gary Guo
2026-02-07 22:05 ` Nathan Chancellor
0 siblings, 1 reply; 6+ messages in thread
From: Gary Guo @ 2026-02-07 16:43 UTC (permalink / raw)
To: Miguel Ojeda, Gary Guo, Nathan Chancellor, Nicolas Schier
Cc: Miguel Ojeda, Boqun Feng, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
Janne Grunau, Asahi Lina, rust-for-linux, linux-kernel,
linux-kbuild
On Sat Feb 7, 2026 at 3:22 PM GMT, Miguel Ojeda wrote:
> On Sat, Feb 7, 2026 at 3:44 PM Gary Guo <gary@kernel.org> wrote:
>>
>> So, fix this by remap all absolute paths to srctree to relative path
>> instead.
>
> In case it matters to Kbuild, we had a relatively recent revert
> related to this flag:
>
> dbdffaf50ff9 ("kbuild, rust: use -fremap-path-prefix to make paths relative")
> 8cf5b3f83614 ("Revert "kbuild, rust: use -fremap-path-prefix to make
> paths relative"")
>
> https://lore.kernel.org/rust-for-linux/20250511-kbuild-revert-file-prefix-map-v1-0-9ba640c8411e@weissschuh.net/
Ah, that explains why I recall we had this flag in Kbuild but can only find the
filter-out directives now. I missed the revert email.
I am not convinced that the ability to launch debugger outside source
directory overweights the benefit of not leaking absolute paths and making
builds reproducible.
The reverting cover letter says "As there is no simple or uniform way to
specify the source directory explicitly" which is clearly not the case as you
can just invoke the debugger in a different working directory... GDB also
provides a way to provide source directory search path:
https://sourceware.org/gdb/current/onlinedocs/gdb.html/Source-Path.html.
Similarly, LLDB provides `settings set target.source-map`:
https://lldb.llvm.org/use/map.html#remap-source-file-pathnames-for-the-debug-session
I think we should revert the revert, then.
Best,
Gary
>
> From what I see in the thread (but I didn't get a confirmation back
> then), the issue was some developers relying on invoking the debugger
> in a different working directory than the `srctree`.
>
> Thanks Gary!
>
> Cheers,
> Miguel
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] rust: build: remap path to avoid absolute path
2026-02-07 16:43 ` Gary Guo
@ 2026-02-07 22:05 ` Nathan Chancellor
2026-02-07 22:59 ` Gary Guo
0 siblings, 1 reply; 6+ messages in thread
From: Nathan Chancellor @ 2026-02-07 22:05 UTC (permalink / raw)
To: Gary Guo
Cc: Miguel Ojeda, Nicolas Schier, Miguel Ojeda, Boqun Feng,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Janne Grunau, Asahi Lina,
rust-for-linux, linux-kernel, linux-kbuild
On Sat, Feb 07, 2026 at 04:43:11PM +0000, Gary Guo wrote:
> On Sat Feb 7, 2026 at 3:22 PM GMT, Miguel Ojeda wrote:
> > On Sat, Feb 7, 2026 at 3:44 PM Gary Guo <gary@kernel.org> wrote:
> >>
> >> So, fix this by remap all absolute paths to srctree to relative path
> >> instead.
> >
> > In case it matters to Kbuild, we had a relatively recent revert
> > related to this flag:
> >
> > dbdffaf50ff9 ("kbuild, rust: use -fremap-path-prefix to make paths relative")
> > 8cf5b3f83614 ("Revert "kbuild, rust: use -fremap-path-prefix to make
> > paths relative"")
> >
> > https://lore.kernel.org/rust-for-linux/20250511-kbuild-revert-file-prefix-map-v1-0-9ba640c8411e@weissschuh.net/
>
> Ah, that explains why I recall we had this flag in Kbuild but can only find the
> filter-out directives now. I missed the revert email.
>
> I am not convinced that the ability to launch debugger outside source
> directory overweights the benefit of not leaking absolute paths and making
> builds reproducible.
>
> The reverting cover letter says "As there is no simple or uniform way to
> specify the source directory explicitly" which is clearly not the case as you
> can just invoke the debugger in a different working directory... GDB also
> provides a way to provide source directory search path:
> https://sourceware.org/gdb/current/onlinedocs/gdb.html/Source-Path.html.
> Similarly, LLDB provides `settings set target.source-map`:
> https://lldb.llvm.org/use/map.html#remap-source-file-pathnames-for-the-debug-session
>
> I think we should revert the revert, then.
For what it's worth, the C side revert also mentions that it broke
'objdump -S' [1] and working with GCOV data [2], so it seems like it is
not just debuggers that have a hard time with that loss of information.
Maybe those do not matter for Rust code or developers though.
[1] https://lore.kernel.org/aBEttQH4kimHFScx@intel.com/
[2] https://lore.kernel.org/edc50aa7-0740-4942-8c15-96f12f2acc7e@kernel.org/
Cheers,
Nathan
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] rust: build: remap path to avoid absolute path
2026-02-07 22:05 ` Nathan Chancellor
@ 2026-02-07 22:59 ` Gary Guo
2026-02-08 11:03 ` Miguel Ojeda
0 siblings, 1 reply; 6+ messages in thread
From: Gary Guo @ 2026-02-07 22:59 UTC (permalink / raw)
To: Nathan Chancellor, Gary Guo
Cc: Miguel Ojeda, Nicolas Schier, Miguel Ojeda, Boqun Feng,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Janne Grunau, Asahi Lina,
rust-for-linux, linux-kernel, linux-kbuild
On Sat Feb 7, 2026 at 10:05 PM GMT, Nathan Chancellor wrote:
> On Sat, Feb 07, 2026 at 04:43:11PM +0000, Gary Guo wrote:
>> On Sat Feb 7, 2026 at 3:22 PM GMT, Miguel Ojeda wrote:
>> > On Sat, Feb 7, 2026 at 3:44 PM Gary Guo <gary@kernel.org> wrote:
>> >>
>> >> So, fix this by remap all absolute paths to srctree to relative path
>> >> instead.
>> >
>> > In case it matters to Kbuild, we had a relatively recent revert
>> > related to this flag:
>> >
>> > dbdffaf50ff9 ("kbuild, rust: use -fremap-path-prefix to make paths relative")
>> > 8cf5b3f83614 ("Revert "kbuild, rust: use -fremap-path-prefix to make
>> > paths relative"")
>> >
>> > https://lore.kernel.org/rust-for-linux/20250511-kbuild-revert-file-prefix-map-v1-0-9ba640c8411e@weissschuh.net/
>>
>> Ah, that explains why I recall we had this flag in Kbuild but can only find the
>> filter-out directives now. I missed the revert email.
>>
>> I am not convinced that the ability to launch debugger outside source
>> directory overweights the benefit of not leaking absolute paths and making
>> builds reproducible.
>>
>> The reverting cover letter says "As there is no simple or uniform way to
>> specify the source directory explicitly" which is clearly not the case as you
>> can just invoke the debugger in a different working directory... GDB also
>> provides a way to provide source directory search path:
>> https://sourceware.org/gdb/current/onlinedocs/gdb.html/Source-Path.html.
>> Similarly, LLDB provides `settings set target.source-map`:
>> https://lldb.llvm.org/use/map.html#remap-source-file-pathnames-for-the-debug-session
>>
>> I think we should revert the revert, then.
>
> For what it's worth, the C side revert also mentions that it broke
> 'objdump -S' [1] and working with GCOV data [2], so it seems like it is
> not just debuggers that have a hard time with that loss of information.
> Maybe those do not matter for Rust code or developers though.
>
> [1] https://lore.kernel.org/aBEttQH4kimHFScx@intel.com/
> [2] https://lore.kernel.org/edc50aa7-0740-4942-8c15-96f12f2acc7e@kernel.org/
Hi Nathan, thanks for the background. I tested that objdump will indeed fail to
find files with Rust `--remap-path-prefix` (even inside correct directory) and
that's indeed problematic (objdump has an `-I` to add search path but it will
only use the file stem and not the full path).
The best path forward is then perhaps to use `-Zremap-path-scope=macro` to limit
the remap to Rust macros (this include `#[track_caller]`). The debug info will
still have non-reproducible parts in it, but at least the ones ended up in
.rodata will be remapped. This flag is going to be stable in Rust 1.95, but is
available unstably for a while, so we can start using it in the kernel already.
I can confirm that objdump is working fine when the remap-path-scope is limited
to macro (default is macro + debuginfo + coverage).
Unfortunately, using remap-path-scope does not give the expected result in older
Rust compiler versions, so the issue reports that I linked will not be resolved
with it. It looks like remap-path-scope is working as intended only since
https://github.com/rust-lang/rust/pull/149709, so Rust 1.94+ (I haven't
double-checked the exact Rust version, but in latest nightly Rust, the remap is
working as intended).
Best,
Gary
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] rust: build: remap path to avoid absolute path
2026-02-07 22:59 ` Gary Guo
@ 2026-02-08 11:03 ` Miguel Ojeda
0 siblings, 0 replies; 6+ messages in thread
From: Miguel Ojeda @ 2026-02-08 11:03 UTC (permalink / raw)
To: Gary Guo
Cc: Nathan Chancellor, Nicolas Schier, Miguel Ojeda, Boqun Feng,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Janne Grunau, Asahi Lina,
rust-for-linux, linux-kernel, linux-kbuild
On Sat, Feb 7, 2026 at 11:59 PM Gary Guo <gary@garyguo.net> wrote:
>
> Unfortunately, using remap-path-scope does not give the expected result in older
> Rust compiler versions, so the issue reports that I linked will not be resolved
> with it. It looks like remap-path-scope is working as intended only since
> https://github.com/rust-lang/rust/pull/149709, so Rust 1.94+ (I haven't
> double-checked the exact Rust version, but in latest nightly Rust, the remap is
> working as intended).
Linked the stabilization and noted the fix 1.94 PR that we likely need
and this thread in the `-Zremap-path-scope` entry in
https://github.com/Rust-for-Linux/linux/issues/2.
And since it is now stabilized, moved to
https://github.com/Rust-for-Linux/linux/issues/1223, which I just had
to create due to GitHub's 64k limit on issue text...
Cheers,
Miguel
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-02-08 11:04 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-07 14:43 [PATCH] rust: build: remap path to avoid absolute path Gary Guo
2026-02-07 15:22 ` Miguel Ojeda
2026-02-07 16:43 ` Gary Guo
2026-02-07 22:05 ` Nathan Chancellor
2026-02-07 22:59 ` Gary Guo
2026-02-08 11:03 ` Miguel Ojeda
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox