Skip to content

Move NativeLib::filename to the rmeta-link archive member#156735

Open
mehdiakiki wants to merge 1 commit into
rust-lang:mainfrom
mehdiakiki:fix/rlib-digest
Open

Move NativeLib::filename to the rmeta-link archive member#156735
mehdiakiki wants to merge 1 commit into
rust-lang:mainfrom
mehdiakiki:fix/rlib-digest

Conversation

@mehdiakiki

@mehdiakiki mehdiakiki commented May 19, 2026

Copy link
Copy Markdown
Contributor

View all comments

Second PR in #138243
Moves NativeLib::filename out of rmeta into lib.rmeta-link archive member that was introduced in the first PR. Filename is a link time only data so requiring a full metadata decode should be avoided. It is stored as (name, filename) pairs keyed by name, the new MetadataLoader::get_rlib_native_lib_filenames patches it back on decode. Also bumped METADATA_VERSION from version 10 to 11. Added also new round trip test and existing bundled-libs tests still pass.

@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 May 19, 2026
@rustbot

rustbot commented May 19, 2026

Copy link
Copy Markdown
Collaborator

r? @dingxiangfei2009

rustbot has assigned @dingxiangfei2009.
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:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 19 candidates

@rustbot

This comment has been minimized.

@rustbot

rustbot commented May 19, 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.

@rust-log-analyzer

This comment has been minimized.

@mehdiakiki

Copy link
Copy Markdown
Contributor Author

r? @petrochenkov
cc @bjorn3

Comment thread tests/run-make/rlib-rmeta-link-native-lib-filenames/rmake.rs Outdated
Comment thread compiler/rustc_metadata/src/rmeta/mod.rs Outdated
Comment thread compiler/rustc_session/src/cstore.rs Outdated
Comment thread compiler/rustc_codegen_ssa/src/back/rmeta_link.rs Outdated
Comment thread compiler/rustc_codegen_ssa/src/back/link.rs Outdated
@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 19, 2026
@mehdiakiki

Copy link
Copy Markdown
Contributor Author

Started working on it today. Should have it ready soon.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@mehdiakiki mehdiakiki force-pushed the fix/rlib-digest branch 2 times, most recently from eb99ef8 to 7dba437 Compare May 30, 2026 01:20
@rust-log-analyzer

This comment has been minimized.

@mehdiakiki

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 30, 2026
tcx.native_libraries(cnum).iter().map(Into::into).collect();
let used_crate_source = tcx.used_crate_source(cnum);
info.native_libraries.insert(cnum, native_libs);
info.crate_name.insert(cnum, tcx.crate_name(cnum));

@petrochenkov petrochenkov Jun 1, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The changes remaining in this file look unnecessary.

View changes since the review

@petrochenkov

Copy link
Copy Markdown
Contributor

I don't like that rmeta_link::read_from_path does the work that is also done in other places in .add_archive(...) calls, but it would require a larger refactoring to not do it, so I don't want to block this PR on it.
(I'll finish reviewing tomorrow.)

read(&archive, archive_data, rlib_path)
}

pub fn read_from_path(target: &Target, path: &Path) -> Option<RmetaLink> {

@petrochenkov petrochenkov Jun 3, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you add a FIXME comment saying that this is mostly a copypaste of DefaultMetadataLoader::get_rlib_metadata?

View changes since the review

@petrochenkov

Copy link
Copy Markdown
Contributor

We are doing a lot of redundant work here, by calling both rmeta_link::read_from_path and find_bundled_library repeatedly.
This all needs to be rewritten properly.

Although if it doesn't show perf regressions on regular code not using bundled native libs, then it's probably tolerable, and the rewrite can happen later.
@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 3, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jun 3, 2026
Move NativeLib::filename to the rmeta-link archive member
@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 3, 2026
@petrochenkov

Copy link
Copy Markdown
Contributor

This all needs to be rewritten properly.

We need something similar to CStore but local to link.rs and loading link metadata entries for crates on demand.
And the same thing for native libraries (only filenames atm) as well.

@rust-bors

rust-bors Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 7894972 (7894972d636d0fdd9341b6f4bbaa9ec76818073f, parent: 53509ca37e3b507887607c2f4a7f23bd4838f099)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (7894972): comparison URL.

Overall result: ❌ regressions - please read:

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.5% [0.5%, 0.5%] 1
Regressions ❌
(secondary)
0.6% [0.2%, 1.7%] 12
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.5% [0.5%, 0.5%] 1

Max RSS (memory usage)

Results (primary 8.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
8.0% [8.0%, 8.0%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 8.0% [8.0%, 8.0%] 1

Cycles

Results (secondary 3.5%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.5% [2.5%, 4.7%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 509.672s -> 510.294s (0.12%)
Artifact size: 400.72 MiB -> 400.70 MiB (-0.01%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jun 3, 2026
@petrochenkov

Copy link
Copy Markdown
Contributor

Some regressions on linking-heavy workloads like large-workspace.

@mehdiakiki

Copy link
Copy Markdown
Contributor Author

read_from_path opens and parses the rlib 2+ times per crate and this happens even for crates that don't have that that bundled native libs. I guess since this regression is happening for regular code we need to fix it right now. Only read for a filename when needed i.e. upstream crate linked statically and contains bundled native libs. This will reduce reads to just one instead of many right now. Is this ok to try now or should I do the loader like you suggested directly in this PR?

@petrochenkov

Copy link
Copy Markdown
Contributor

I won't have time to look until next week.
If you do the cstore analogue, could you do it in a separate PR? It would be useful for the existing rmeta-link already, even without native_lib_filenames.

@mehdiakiki

Copy link
Copy Markdown
Contributor Author

@petrochenkov sure will do.

@rustbot

rustbot commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

⚠️ Warning ⚠️

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 perf-regression Performance regression. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

7 participants