Fix handling of +whole-archive native link modifier.
This commit is contained in:
parent
dbb0fe9d80
commit
522f9757f6
2 changed files with 36 additions and 10 deletions
|
@ -36,6 +36,7 @@ use regex::Regex;
|
||||||
use tempfile::Builder as TempFileBuilder;
|
use tempfile::Builder as TempFileBuilder;
|
||||||
|
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
|
use std::lazy::OnceCell;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::{ExitStatus, Output, Stdio};
|
use std::process::{ExitStatus, Output, Stdio};
|
||||||
use std::{ascii, char, env, fmt, fs, io, mem, str};
|
use std::{ascii, char, env, fmt, fs, io, mem, str};
|
||||||
|
@ -2001,7 +2002,7 @@ fn add_local_native_libraries(
|
||||||
let relevant_libs =
|
let relevant_libs =
|
||||||
codegen_results.crate_info.used_libraries.iter().filter(|l| relevant_lib(sess, l));
|
codegen_results.crate_info.used_libraries.iter().filter(|l| relevant_lib(sess, l));
|
||||||
|
|
||||||
let search_path = archive_search_paths(sess);
|
let search_path = OnceCell::new();
|
||||||
let mut last = (NativeLibKind::Unspecified, None);
|
let mut last = (NativeLibKind::Unspecified, None);
|
||||||
for lib in relevant_libs {
|
for lib in relevant_libs {
|
||||||
let name = match lib.name {
|
let name = match lib.name {
|
||||||
|
@ -2023,7 +2024,11 @@ fn add_local_native_libraries(
|
||||||
}
|
}
|
||||||
NativeLibKind::Static { bundle: None | Some(true), .. }
|
NativeLibKind::Static { bundle: None | Some(true), .. }
|
||||||
| NativeLibKind::Static { whole_archive: Some(true), .. } => {
|
| NativeLibKind::Static { whole_archive: Some(true), .. } => {
|
||||||
cmd.link_whole_staticlib(name, verbatim, &search_path);
|
cmd.link_whole_staticlib(
|
||||||
|
name,
|
||||||
|
verbatim,
|
||||||
|
&search_path.get_or_init(|| archive_search_paths(sess)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
NativeLibKind::Static { .. } => cmd.link_staticlib(name, verbatim),
|
NativeLibKind::Static { .. } => cmd.link_staticlib(name, verbatim),
|
||||||
NativeLibKind::RawDylib => {
|
NativeLibKind::RawDylib => {
|
||||||
|
@ -2116,6 +2121,7 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut compiler_builtins = None;
|
let mut compiler_builtins = None;
|
||||||
|
let search_path = OnceCell::new();
|
||||||
|
|
||||||
for &cnum in deps.iter() {
|
for &cnum in deps.iter() {
|
||||||
if group_start == Some(cnum) {
|
if group_start == Some(cnum) {
|
||||||
|
@ -2149,16 +2155,35 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
|
||||||
// external build system already has the native dependencies defined, and it
|
// external build system already has the native dependencies defined, and it
|
||||||
// will provide them to the linker itself.
|
// will provide them to the linker itself.
|
||||||
if sess.opts.debugging_opts.link_native_libraries {
|
if sess.opts.debugging_opts.link_native_libraries {
|
||||||
// Skip if this library is the same as the last.
|
|
||||||
let mut last = None;
|
let mut last = None;
|
||||||
for lib in &codegen_results.crate_info.native_libraries[&cnum] {
|
for lib in &codegen_results.crate_info.native_libraries[&cnum] {
|
||||||
if lib.name.is_some()
|
if !relevant_lib(sess, lib) {
|
||||||
&& relevant_lib(sess, lib)
|
// Skip libraries if they are disabled by `#[link(cfg=...)]`
|
||||||
&& matches!(lib.kind, NativeLibKind::Static { bundle: Some(false), .. })
|
continue;
|
||||||
&& last != lib.name
|
}
|
||||||
{
|
|
||||||
cmd.link_staticlib(lib.name.unwrap(), lib.verbatim.unwrap_or(false));
|
// Skip if this library is the same as the last.
|
||||||
last = lib.name;
|
if last == lib.name {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(static_lib_name) = lib.name {
|
||||||
|
if let NativeLibKind::Static { bundle: Some(false), whole_archive } =
|
||||||
|
lib.kind
|
||||||
|
{
|
||||||
|
let verbatim = lib.verbatim.unwrap_or(false);
|
||||||
|
if whole_archive == Some(true) {
|
||||||
|
cmd.link_whole_staticlib(
|
||||||
|
static_lib_name,
|
||||||
|
verbatim,
|
||||||
|
search_path.get_or_init(|| archive_search_paths(sess)),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
cmd.link_staticlib(static_lib_name, verbatim);
|
||||||
|
}
|
||||||
|
|
||||||
|
last = lib.name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#![feature(box_patterns)]
|
#![feature(box_patterns)]
|
||||||
#![feature(try_blocks)]
|
#![feature(try_blocks)]
|
||||||
#![feature(in_band_lifetimes)]
|
#![feature(in_band_lifetimes)]
|
||||||
|
#![feature(once_cell)]
|
||||||
#![feature(nll)]
|
#![feature(nll)]
|
||||||
#![feature(associated_type_bounds)]
|
#![feature(associated_type_bounds)]
|
||||||
#![recursion_limit = "256"]
|
#![recursion_limit = "256"]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue