Skip to content

fix: non-deterministic temporary object paths in linker maps - #165971

Open
paradoxicalguy wants to merge 1 commit into
rust-lang:mainfrom
paradoxicalguy:fix-linker-map-determinism
Open

paradoxicalguy wants to merge 1 commit into
rust-lang:mainfrom
paradoxicalguy:fix-linker-map-determinism

Conversation

@paradoxicalguy

Copy link
Copy Markdown
Member

fixes #142989

rustc creates temporary rmeta.o and symbols.o files in randomly named directories, causing otherwise identical builds to produce different linker maps.

this gives both objects deterministic paths derived from the output filename. a per-output lock protects them during linking, and they're cleaned up afterward unless -C save-temps is enabled.
the lockfile is kept across builds to avoid races. feedback on a simpler approach is welcome.

testing:
added a run-make regression test comparing complete linker maps across repeated builds, verified identical GNU ld and LLD maps on AArch64 linux, tested concurrent linking (20 rounds), cleanup and -C save-temps

r? compiler

@rustbot rustbot added A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 14, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-cloud-vms
rust-cloud-vms Bot force-pushed the fix-linker-map-determinism branch 3 times, most recently from ad1882c to 57c0e63 Compare November 14, 2026 20:08
.fatal(format!("failed to initialize linker object directory: {e}"))
});

fs::rename(staging.path(), &objects_dir).unwrap_or_else(|e| {

@paradoxicalguy paradoxicalguy Nov 14, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one caveat here: fs::rename can replace an existing empty directory on unix. the lock prevents races between rustc invocations, but not with unrelated processes. would a no-replace rename be worth considering?

View changes since the review

@rust-log-analyzer

This comment has been minimized.

@rust-cloud-vms
rust-cloud-vms Bot force-pushed the fix-linker-map-determinism branch from 57c0e63 to ddd18e5 Compare November 14, 2026 20:54
@paradoxicalguy

Copy link
Copy Markdown
Member Author

adding ignore gcc backend

@rust-log-analyzer

This comment has been minimized.

// Both linker inputs have stable names, protected by the same per-output lock.
// The lockfile must not be removed: another invocation could otherwise lock a
// different inode while an earlier invocation still holds the original lock.
pub(super) struct StableLinkObjects {

@bjorn3 bjorn3 Nov 15, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should just follow the same filename derivation as regular object files. Then you don't need a dedicated file lock.

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that would simplify this :D, yes
but temp_path_for_cgu() includes an invocation-specific suffix, which would still appear in linker maps. is there another part of the regular object filename derivation you had in mind?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That problem also exists for regular object files referenced in the linker map and can be solved all at once later. And I believe the random suffix only applies to incr comp.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated this to use temp_path_for_cgu() for both objects, and removed the dedicated locking/directory code. related run-make tests pass locally. thanks for the suggestion

@rust-cloud-vms
rust-cloud-vms Bot force-pushed the fix-linker-map-determinism branch from ddd18e5 to 0c65b0b Compare November 15, 2026 08:41
@rust-log-analyzer

This comment has been minimized.

@rust-cloud-vms
rust-cloud-vms Bot force-pushed the fix-linker-map-determinism branch from 0c65b0b to 6238f9c Compare November 15, 2026 09:59

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

new non-determinism in linker maps introduced recently

5 participants