-
-
Notifications
You must be signed in to change notification settings - Fork 15k
Move NativeLib::filename to the rmeta-link archive member #156735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mehdiakiki
wants to merge
1
commit into
rust-lang:main
Choose a base branch
from
mehdiakiki:fix/rlib-digest
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,26 +2,34 @@ | |
| //! and potentially other data collected and used when building or linking a rlib. | ||
| //! See <https://github.com/rust-lang/rust/issues/138243>. | ||
|
|
||
| use std::fs::File; | ||
| use std::path::Path; | ||
|
|
||
| use object::read::archive::ArchiveFile; | ||
| use rustc_data_structures::memmap::Mmap; | ||
| use rustc_serialize::opaque::mem_encoder::MemEncoder; | ||
| use rustc_serialize::opaque::{MAGIC_END_BYTES, MemDecoder}; | ||
| use rustc_serialize::{Decodable, Encodable}; | ||
| use rustc_target::spec::Target; | ||
| use tracing::debug; | ||
|
|
||
| use super::metadata::search_for_section; | ||
| use super::metadata::{get_metadata_xcoff, search_for_section}; | ||
|
|
||
| pub(crate) const FILENAME: &str = "lib.rmeta-link"; | ||
| pub(crate) const SECTION: &str = ".rmeta-link"; | ||
|
|
||
| pub struct RmetaLink { | ||
| pub rust_object_files: Vec<String>, | ||
| /// Positionally aligned with `native_libraries` in regular metadata: index `i` is the | ||
| /// bundled filename for native library `i`, or `None` if that library needs no bundling. | ||
| pub native_lib_filenames: Vec<Option<String>>, | ||
| } | ||
|
|
||
| impl RmetaLink { | ||
| pub(crate) fn encode(&self) -> Vec<u8> { | ||
| let mut encoder = MemEncoder::new(); | ||
| self.rust_object_files.encode(&mut encoder); | ||
| self.native_lib_filenames.encode(&mut encoder); | ||
| let mut data = encoder.finish(); | ||
| data.extend_from_slice(MAGIC_END_BYTES); | ||
| data | ||
|
|
@@ -30,7 +38,8 @@ impl RmetaLink { | |
| pub(crate) fn decode(data: &[u8]) -> Option<RmetaLink> { | ||
| let mut decoder = MemDecoder::new(data, 0).ok()?; | ||
| let rust_object_files = Vec::<String>::decode(&mut decoder); | ||
| Some(RmetaLink { rust_object_files }) | ||
| let native_lib_filenames = Vec::<Option<String>>::decode(&mut decoder); | ||
| Some(RmetaLink { rust_object_files, native_lib_filenames }) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -54,3 +63,30 @@ pub fn read_from_data(archive_data: &[u8], rlib_path: &Path) -> Option<RmetaLink | |
| let archive = ArchiveFile::parse(archive_data).ok()?; | ||
| read(&archive, archive_data, rlib_path) | ||
| } | ||
|
|
||
| // FIXME: this is mostly a copy-paste of `DefaultMetadataLoader::get_rlib_metadata`. | ||
| pub fn read_from_path(target: &Target, path: &Path) -> Option<RmetaLink> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| let Ok(file) = File::open(path) else { | ||
| debug!("failed to open rlib for rmeta-link: {}", path.display()); | ||
| return None; | ||
| }; | ||
| let Ok(mmap) = (unsafe { Mmap::map(file) }) else { | ||
| debug!("failed to mmap rlib for rmeta-link: {}", path.display()); | ||
| return None; | ||
| }; | ||
|
|
||
| if target.is_like_aix { | ||
| let archive = ArchiveFile::parse(&*mmap).ok()?; | ||
| for entry in archive.members() { | ||
| let entry = entry.ok()?; | ||
| if entry.name() == FILENAME.as_bytes() { | ||
| let member_data = entry.data(&*mmap).ok()?; | ||
| let section_data = get_metadata_xcoff(path, member_data).ok()?; | ||
| return RmetaLink::decode(section_data); | ||
| } | ||
| } | ||
| return None; | ||
| } | ||
|
|
||
| read_from_data(&mmap, path) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.