Skip to content

compiler-builtins: pass -fdebug-compilation-dir=. to fix S_OBJNAME reproducibility on Windows#157914

Open
paradoxicalguy wants to merge 3 commits into
rust-lang:mainfrom
paradoxicalguy:compiler-builtins-objname-reproducibility
Open

compiler-builtins: pass -fdebug-compilation-dir=. to fix S_OBJNAME reproducibility on Windows#157914
paradoxicalguy wants to merge 3 commits into
rust-lang:mainfrom
paradoxicalguy:compiler-builtins-objname-reproducibility

Conversation

@paradoxicalguy

@paradoxicalguy paradoxicalguy commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

View all comments

compiler_builtins.rlib differs between builds because clang-cl embeds the absolute object output path into the S_OBJNAME codeview record.
the path comes from cc-rs passing an absolute /Fo argument (derived from cargo's OUT_DIR) to addDebugObjectName(), which llvm then writes verbatim into .debug$S.
minimal repro:

clang-cl /c /Z7 t.c /Fo:a\t.obj  →  ObjectName: C:\...\a\t.obj
clang-cl /c /Z7 t.c /Fo:b\t.obj  →  ObjectName: C:\...\b\t.obj

-fdebug-compilation-dir=. makes S_OBJNAME emit a relative path instead.
needs CI verification on a windows dist job since local builds use cl.exe rather than the bundled clang-cl. this pr is only for testing

@rustbot

rustbot commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

compiler-builtins is developed in its own repository. If possible, consider making this change to rust-lang/compiler-builtins instead.

cc @tgross35

@rustbot rustbot added A-compiler-builtins Area: compiler-builtins (https://github.com/rust-lang/compiler-builtins) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jun 15, 2026
@rustbot

rustbot commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

r? @jieyouxu

rustbot has assigned @jieyouxu.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Fallback group: @Mark-Simulacrum, @jieyouxu
  • @Mark-Simulacrum, @jieyouxu expanded to Mark-Simulacrum, jieyouxu
  • Random selection from Mark-Simulacrum, jieyouxu

@rustbot

This comment has been minimized.

@rustbot

rustbot commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rustbot

rustbot commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

⚠️ Warning ⚠️

  • The following commits have merge commits (commits with multiple parents) in your changes. We have a no merge policy so these commits will need to be removed for this pull request to be merged.

    You can start a rebase with the following commands:

    $ # rebase
    $ git pull --rebase https://github.com/rust-lang/rust.git main
    $ git push --force-with-lease
    

@rustbot rustbot added has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 15, 2026
@paradoxicalguy

Copy link
Copy Markdown
Contributor Author

cc @bjorn3 @Urgau

Comment thread library/compiler-builtins/compiler-builtins/build.rs Outdated
@bjorn3

bjorn3 commented Jun 16, 2026

Copy link
Copy Markdown
Member

@bors try job=dist-x86_64-msvc

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jun 16, 2026
…oducibility, r=<try>

compiler-builtins: pass -fdebug-compilation-dir=. to fix S_OBJNAME reproducibility on Windows


try-job: dist-x86_64-msvc
@rust-bors

rust-bors Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 5383ff6 (5383ff6bb690cf094a2399cf3e129092120625b2, parent: 9d862dd2c17b2dc90e9f623bb9279a8c4090b311)

@paradoxicalguy

Copy link
Copy Markdown
Contributor Author

where can i download the x86_64-msvc artifact from this try build to extract ucmpti2.o and verify S_OBJNAME?

@bjorn3

bjorn3 commented Jun 16, 2026

Copy link
Copy Markdown
Member

You can use rustup-toolchain-install-master I think you can do something like rustup-toolchain-install-master 5383ff6bb690cf094a2399cf3e129092120625b2 --host x86_64-pc-windows-msvc and then check ~/.rustup/toolchain/5383ff6bb690cf094a2399cf3e129092120625b2/lib/rustlib/x86_64-pc-windows-msvc/lib/libcompiler_builtins-*.rlib Afterwards you can remove it again with rustup toolchain remove 5383ff6bb690cf094a2399cf3e129092120625b2 I think. Make sure that rustup-toolchain-install-master downloads the correct commit, by default or if you pass the commit hash at the wrong location it downloads for the top of the main branch.

@ChrisDenton

Copy link
Copy Markdown
Member

needs CI verification on a windows dist job since local builds use cl.exe rather than the bundled clang-cl. this pr is only for testing

IIRC you should be able to use something like --set target.x86_64-pc-windows-msvc.cc = "clang-cl.exe" to override the linker (or put the setting in your bootstrap.toml)

@paradoxicalguy

Copy link
Copy Markdown
Contributor Author

thanks to both of you, i checked in downloaded artifact, sadly patch didn't work,
but now i can test this locally with --set target.x86_64-pc-windows-msvc.cc = "clang-cl.exe" so that's good

@tgross35

Copy link
Copy Markdown
Contributor

Is this something that you can figure out by inspecting the object file? If so, you could create a PR to the compiler-builtins repo adding a failing test to https://github.com/rust-lang/compiler-builtins/blob/fb48f81544cf29e6ff7fb4468c8b2e1dacd42b79/crates/symbol-check/src/main.rs then messing around to see what flags get it to pass. Might be easier than repeating the try build process here.

Why does this only apply to Windows, though, and only compiler-builtins? I'd expect other platforms to get the same paths in their debug info.

@paradoxicalguy

Copy link
Copy Markdown
Contributor Author

(a) yes, i found the current problem by inspecting an object file, extracting ucmpti2.o and running llvm-readobj --codeview on it, shows S_OBJNAME containing absolute path. (it came empty on my local patch but comes absolute path on ci so i am missing something, maybe different bootstrap or some flags.)
(b) on elf, it only saves the filename and not the whole path, not resulting in non determinism.
while codeview's S_OBJNAME record was designed to store the full absolute object path, since windows debugging tools (visual studio, windbg) use it to locate the original .obj on disk.

@tgross35

@paradoxicalguy

paradoxicalguy commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

it works w build.flag("/clang:-object-file-name="); in compiler-builtins repo.

@paradoxicalguy

paradoxicalguy commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

repro_report.html

the objname issue is resolved when checked manually but compiler-builtins still comes as non-deterministic in the repro check run i did. archive still contains absolute build paths (e.g. the build-b/extra1/... path), so im investigating whether those are coming from archive member names / the archive string table.

@jieyouxu jieyouxu removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-compiler-builtins Area: compiler-builtins (https://github.com/rust-lang/compiler-builtins) has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants