Add rlib digest to identify Rust object files#154861
Add rlib digest to identify Rust object files#154861mehdiakiki wants to merge 1 commit intorust-lang:mainfrom
Conversation
|
r? @mati865 rustbot has assigned @mati865. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
4b32d99 to
d966fa8
Compare
|
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. |
|
Got too much on my plate already. @rustbot reroll |
| create_wrapper_file(sess, rlib_digest::SECTION.to_string(), &digest_data); | ||
| let digest_file = emit_wrapper_file(sess, &wrapper, tmpdir.as_ref(), rlib_digest::FILENAME); | ||
| ab.add_file(&digest_file); | ||
| } |
There was a problem hiding this comment.
Can this be added right after the crate metadata instead? That saves time iterating over the rlib at staticlib build time.
| pub(crate) fn read(rlib_path: &Path) -> Option<RlibDigest> { | ||
| let file = File::open(rlib_path).ok()?; | ||
| let mmap = unsafe { Mmap::map(file).ok()? }; | ||
| let archive = ArchiveFile::parse(&*mmap).ok()?; |
There was a problem hiding this comment.
Ideally this mmap would be combined with the one in add_archive.
| if lto { | ||
| let is_rust_object = match &digest { | ||
| Some(d) => d.rust_object_files.iter().any(|f| f == fname), | ||
| None => looks_like_rust_object_file(fname), |
There was a problem hiding this comment.
Why is this fallback necessary? Wouldn't all rlibs contain the digest?
|
|
||
| pub(crate) const FILENAME: &str = "lib.rlib-digest"; | ||
| pub(crate) const SECTION: &str = ".rlib-digest"; | ||
| const VERSION: u8 = 1; |
There was a problem hiding this comment.
This version is not necessary. By the time the linker code is reached, we already know that the rustc version as embedded in the crate metadata matches exactly.
This adds a metadata entry to
rlibarchives that lists which members are Rust object files instead of relying on the filename heuristic inlooks_like_rust_object.file. I also added a fallback to the old behavior forrlibsbuilt by older compilers.