-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Support the rustc metadata for AIX #107583
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Nilstrieb (or someone else) soon. Please see the contribution instructions for more information. |
Marking was waiting-on-author as it currently doesn't build and seems to require upstream changes in |
@@ -93,6 +101,27 @@ pub(super) fn search_for_section<'a>( | |||
.map_err(|e| format!("failed to read {} section in '{}': {}", section, path.display(), e)) | |||
} | |||
|
|||
pub(super) fn get_metadata_xcoff<'a>(path: &Path, data: &'a [u8]) -> Result<&'a [u8], String> { | |||
let buf = search_for_section(path, data, ".info")?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we know that the first entry in the .info
section is our metadata? Are we sure that rustc is the only source of data in .info
? According to the documentation, we should be using a symbol to locate it instead:
The n_name field is preserved by the binder. An application-defined unique name in this field can be used to filter access to only those comment section strings intended for the application.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some object files, multiple segments may contain sections with the same name. However as I know, with XCOFF there may be multiple sections with type info
, but their names must be different. Therefore, the ".info" section can be specific for metadata.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding is that .info
may contain multiple comments, and we need to use a symbol to locate the comment in .info
that rustc added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see.
We've added a symbol with value of 4, which specifies the offset in comment section, to refer to the rust metadata.
// Add a symbol referring to .info section.
// Storage class will be handled in object crate.
file.add_symbol(Symbol {
name: "info".into(),
value: 4,
size: 0,
kind: SymbolKind::Unknown,
scope: SymbolScope::Dynamic,
weak: false,
section: SymbolSection::Section(section),
flags: SymbolFlags::Xcoff { n_sclass : xcoff::C_INFO },
});
Do you mean that we should use the value in the symbol to locate the metadata instead of reading the first entry directly? In the meanwhile, we can change the name 'info' to 'rustc' to make the symbol be the identifier?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the documentation, yes.
// Add a symbol referring to .info section. | ||
// Storage class will be handled in object crate. | ||
file.add_symbol(Symbol { | ||
name: "info".into(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this should be the identifier that we use for section names in other formats (.rmeta
and .rustc
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the .rustc section the symbol has a unique name derived from the crate hash I believe.
name: "info".into(), | ||
value: 4, | ||
size: 0, | ||
kind: object::SymbolKind::Null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to SymbolKind::Unknown
and use SymbolFlags::Xcoff
to set this to C_INFO
.
b".info".to_vec(), | ||
SectionKind::Debug, | ||
); | ||
file.add_file_symbol(".file".into()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation says that .file
is used when there is a file auxiliary symbol. Ideally all handling of .file
would be internal to the object
crate, so here we would specify the actual file name we want.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@@ -60,16 +60,24 @@ impl MetadataLoader for DefaultMetadataLoader { | |||
let data = entry | |||
.data(data) | |||
.map_err(|e| format!("failed to parse rlib '{}': {}", path.display(), e))?; | |||
return search_for_section(path, data, ".rmeta"); | |||
if target.is_like_aix { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though xcoff is bound to AIX, I think checking the format is more precise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have format info in this function. While according to your comments, I changed such checks in fn create_wrapper_file()
and fn create_compressed_metadata_file()
. Thanks.
fn get_dylib_metadata(&self, _target: &Target, path: &Path) -> Result<MetadataRef, String> { | ||
load_metadata_with(path, |data| search_for_section(path, data, ".rustc")) | ||
fn get_dylib_metadata(&self, target: &Target, path: &Path) -> Result<MetadataRef, String> { | ||
if target.is_like_aix { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dito
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
let buf = search_for_section(path, data, ".info")?; | ||
let offset = file.symbol_address_by_name("rustc")?; | ||
// The first 4 bytes from offset are length field for rustc metadata. | ||
if offset + 4 >= buf.len() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be handled by object
crate. For AIX toolchain, a C_INFO
symbol's offset inside .info
section doesn't count the first 4-bytes length field. When reading the object file, we can set C_INFO
ObjectSymbol's address the offset into .info
section and the size can be initialized from the first 4-bytes length field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be handled by object crate.
I think it will be a little wired if we add an interface in https://github.com/gimli-rs/object/blob/master/src/read/traits.rs, which is specific for XCOFF platform.
This comment has been minimized.
This comment has been minimized.
9840671
to
dfcd17d
Compare
This comment has been minimized.
This comment has been minimized.
The PR is expected to pass CI checks after the release of the new version of Object crate https://github.com/gimli-rs/object which may include features of writing a XCOFF object file. |
Sorry I forgot to tell you. A new version was released a few days ago. |
hi @bjorn3, could you help to updates object to 0.31.0 for |
I posted PR to bump object in rust-lang/ar_archive_writer#6. And I see @philipc has one for thorin: rust-lang/thorin#24. |
/// From XCOFF's view, (2) creates a csect entry in the symbol table, the | ||
/// symbol created by (3) is a info symbol for the preceding csect. Thus | ||
/// two symbols are preserved during linking and we can use the second symbol | ||
/// to reference the metadata. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two kinds of object files created. One (create_wrapper_file
) is for use in rlibs and we do not want to preserve metadata in there. It is only wrapped in an rlib to prevent linkers from complaining about files that are not valid object files in archives. The other kind (create_compressed_metadata_file
) contains compressed metadata and is used for rust dylibs. This one should be preserved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AIX linker will abort if it finds lib.rmeta
is a valid XCOFF file but only has .info
section (no .bss
, .data
or .text
). Fortunately, we can just add a stub .text
section to make linker happy:
file.add_section(Vec::new(), b".text".to_vec(), SectionKind::Text);
This comment has been minimized.
This comment has been minimized.
|
library/std/Cargo.toml
Outdated
@@ -27,10 +27,10 @@ addr2line = { version = "0.19.0", optional = true, default-features = false } | |||
rustc-demangle = { version = "0.1.21", features = ['rustc-dep-of-std'] } | |||
miniz_oxide = { version = "0.6.0", optional = true, default-features = false } | |||
[dependencies.object] | |||
version = "0.30.0" | |||
version = "0.31.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it build without this change? backtrace-rs
doesn't have xcoff support yet anyway.
☔ The latest upstream changes (presumably #111001) made this pull request unmergeable. Please resolve the merge conflicts. |
This comment has been minimized.
This comment has been minimized.
|
a8dbb96
to
d7c51b6
Compare
This comment has been minimized.
This comment has been minimized.
d7c51b6
to
ab983c8
Compare
This comment has been minimized.
This comment has been minimized.
ab983c8
to
18fdca3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
@rustbot ready |
r? @bjorn3 |
@bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (7452822): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 646.615s -> 646.59s (-0.00%) |
Support the rustc metadata for rlibs and dylibs on AIX.
XCOFF is the object file format on AIX.