-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Use the relative sysroot path in the linker command line to specify sysroot rlibs #112597
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
FWIW I considered putting the |
This comment has been minimized.
This comment has been minimized.
@@ -329,7 +329,8 @@ impl<'a> GccLinker<'a> { | |||
// the right `-Wl,-install_name` with an `@rpath` in it. | |||
if self.sess.opts.cg.rpath || self.sess.opts.unstable_opts.osx_rpath_install_name { | |||
let mut rpath = OsString::from("@rpath/"); | |||
rpath.push(out_filename.file_name().unwrap()); | |||
let mapping = self.sess.opts.file_path_mapping(); | |||
rpath.push(mapping.map_prefix(out_filename).0.file_name().unwrap()); |
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 is already just the filename and not the full path, so -Zremap-cwd-prefix
doesn't have any effect and I'm not sure --remap-path-prefix
is supposed to allow remapping individual files as opposed to directories. It probably doesn't break anythinf though.
@@ -461,19 +466,19 @@ impl<'a> Linker for GccLinker<'a> { | |||
} | |||
fn link_rlib(&mut self, lib: &Path) { | |||
self.hint_static(); | |||
self.cmd.arg(lib); | |||
self.cmd.arg(self.sess.opts.file_path_mapping().map_prefix(lib).0.as_ref()); |
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.
If the remap is anything other than turning an absolute path into a relative path that still resolves to the same absolute path given the working directory of rustc this will break linking as the linker actually needs to read the file at this path. So for example remapping /path/to/rust_source
to /rustc/$hash
as is done by rust's CI will be broken.
This is the reason for the CI failure.
I can take the review for this. |
linker.rs doesn't look like the right place to do this. |
Ah ok so there's 2 issues here which I will address. Thanks for the feedback so far.
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
When the `--sysroot` is specified as relative to the current working directory, the sysroot's rlibs should also be specified as relative paths. Otherwise, the current working directory ends up in the absolute paths, and in the linker command line. And the entire linker command line appears in the PDB file generated by the MSVC linker. When adding an rlib to the linker command line, if the rlib's canonical path is in the sysroot's canonical path, then use the current sysroot path + filename instead of the full absolute path to the rlib. This means that when `--sysroot=foo` is specified, the linker command line will contain `foo/rustlib/target/lib/lib*.rlib` instead of the full absolute path to the same. This addresses rust-lang#112586
PTAL this is now done in link.rs and just rehomes rlib paths in the linker command line that are into the sysroot to use the actual sysroot path instead of the full absolute path. |
We'll also need to take care of |
Oh, can the stdlib crates be dylibs? |
Yes, libstd.so and libtest.so exist. There are some (minor) limitations around their use though. |
Like for rlibs, the paths on the linker command line need to be relative paths if the sysroot was specified by the user to be a relative path. Dylibs put the path in /LIBPATH instead of into the file path of the library itself, so we rehome the libpath and adjust the rehoming function to be able to support both use cases, rlibs and dylibs.
Done for add_dynamic_crate() now as well. |
Thanks, @danakj! This looks good to me. The next beta branch is still a while off, so we should find out in time if it has any unintended side effects. @bors r+ rollup=never When we fix the issue with the object file in |
☀️ Test successful - checks-actions |
Finished benchmarking commit (99b3346): comparison URL. Overall result: ❌ regressions - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
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: 648.963s -> 646.331s (-0.41%) |
This addresses #112586