Skip to content

Commit 62730f2

Browse files
committed
Auto merge of rust-lang#120304 - fmease:rollup-h8gaxdp, r=fmease
Rollup of 8 pull requests Successful merges: - rust-lang#119305 (Add `AsyncFn` family of traits) - rust-lang#119389 (Provide more context on recursive `impl` evaluation overflow) - rust-lang#120062 (llvm: change data layout bug to an error and make it trigger more) - rust-lang#120099 (linker: Refactor library linking methods in `trait Linker`) - rust-lang#120201 (Bump some deps with syn 1.0 dependencies) - rust-lang#120230 (Assert that a single scope is passed to `for_scope`) - rust-lang#120278 (Remove --fatal-warnings on wasm targets) - rust-lang#120292 (coverage: Dismantle `Instrumentor` and flatten span refinement) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7ffc697 + bc241fd commit 62730f2

File tree

39 files changed

+1159
-641
lines changed

39 files changed

+1159
-641
lines changed

Cargo.lock

+16-36
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,9 @@ dependencies = [
373373

374374
[[package]]
375375
name = "byteorder"
376-
version = "1.4.3"
376+
version = "1.5.0"
377377
source = "registry+https://github.com/rust-lang/crates.io-index"
378-
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
378+
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
379379

380380
[[package]]
381381
name = "bytes"
@@ -2587,9 +2587,9 @@ checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
25872587

25882588
[[package]]
25892589
name = "object"
2590-
version = "0.32.1"
2590+
version = "0.32.2"
25912591
source = "registry+https://github.com/rust-lang/crates.io-index"
2592-
checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0"
2592+
checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441"
25932593
dependencies = [
25942594
"compiler_builtins",
25952595
"crc32fast",
@@ -4788,12 +4788,12 @@ checksum = "4f3208ce4d8448b3f3e7d168a73f5e0c43a61e32930de3bceeccedb388b6bf06"
47884788

47894789
[[package]]
47904790
name = "ruzstd"
4791-
version = "0.4.0"
4791+
version = "0.5.0"
47924792
source = "registry+https://github.com/rust-lang/crates.io-index"
4793-
checksum = "ac3ffab8f9715a0d455df4bbb9d21e91135aab3cd3ca187af0cd0c3c3f868fdc"
4793+
checksum = "58c4eb8a81997cf040a091d1f7e1938aeab6749d3a0dfa73af43cdc32393483d"
47944794
dependencies = [
47954795
"byteorder",
4796-
"thiserror-core",
4796+
"derive_more",
47974797
"twox-hash",
47984798
]
47994799

@@ -5356,26 +5356,6 @@ dependencies = [
53565356
"thiserror-impl",
53575357
]
53585358

5359-
[[package]]
5360-
name = "thiserror-core"
5361-
version = "1.0.38"
5362-
source = "registry+https://github.com/rust-lang/crates.io-index"
5363-
checksum = "0d97345f6437bb2004cd58819d8a9ef8e36cdd7661c2abc4bbde0a7c40d9f497"
5364-
dependencies = [
5365-
"thiserror-core-impl",
5366-
]
5367-
5368-
[[package]]
5369-
name = "thiserror-core-impl"
5370-
version = "1.0.38"
5371-
source = "registry+https://github.com/rust-lang/crates.io-index"
5372-
checksum = "10ac1c5050e43014d16b2f94d0d2ce79e65ffdd8b38d8048f9c8f6a8a6da62ac"
5373-
dependencies = [
5374-
"proc-macro2",
5375-
"quote",
5376-
"syn 1.0.109",
5377-
]
5378-
53795359
[[package]]
53805360
name = "thiserror-impl"
53815361
version = "1.0.47"
@@ -5748,28 +5728,28 @@ dependencies = [
57485728

57495729
[[package]]
57505730
name = "unic-langid"
5751-
version = "0.9.1"
5731+
version = "0.9.4"
57525732
source = "registry+https://github.com/rust-lang/crates.io-index"
5753-
checksum = "398f9ad7239db44fd0f80fe068d12ff22d78354080332a5077dc6f52f14dcf2f"
5733+
checksum = "238722e6d794ed130f91f4ea33e01fcff4f188d92337a21297892521c72df516"
57545734
dependencies = [
57555735
"unic-langid-impl",
57565736
"unic-langid-macros",
57575737
]
57585738

57595739
[[package]]
57605740
name = "unic-langid-impl"
5761-
version = "0.9.1"
5741+
version = "0.9.4"
57625742
source = "registry+https://github.com/rust-lang/crates.io-index"
5763-
checksum = "e35bfd2f2b8796545b55d7d3fd3e89a0613f68a0d1c8bc28cb7ff96b411a35ff"
5743+
checksum = "4bd55a2063fdea4ef1f8633243a7b0524cbeef1905ae04c31a1c9b9775c55bc6"
57645744
dependencies = [
57655745
"tinystr",
57665746
]
57675747

57685748
[[package]]
57695749
name = "unic-langid-macros"
5770-
version = "0.9.1"
5750+
version = "0.9.4"
57715751
source = "registry+https://github.com/rust-lang/crates.io-index"
5772-
checksum = "055e618bf694161ffff0466d95cef3e1a5edc59f6ba1888e97801f2b4ebdc4fe"
5752+
checksum = "5c854cefb82ff2816410ce606acbad1b3af065140907b29be9229040752b83ec"
57735753
dependencies = [
57745754
"proc-macro-hack",
57755755
"tinystr",
@@ -5779,13 +5759,13 @@ dependencies = [
57795759

57805760
[[package]]
57815761
name = "unic-langid-macros-impl"
5782-
version = "0.9.1"
5762+
version = "0.9.4"
57835763
source = "registry+https://github.com/rust-lang/crates.io-index"
5784-
checksum = "1f5cdec05b907f4e2f6843f4354f4ce6a5bebe1a56df320a49134944477ce4d8"
5764+
checksum = "fea2a4c80deb4fb3ca51f66b5e2dd91e3642bbce52234bcf22e41668281208e4"
57855765
dependencies = [
57865766
"proc-macro-hack",
57875767
"quote",
5788-
"syn 1.0.109",
5768+
"syn 2.0.32",
57895769
"unic-langid-impl",
57905770
]
57915771

compiler/rustc_codegen_llvm/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ codegen_llvm_lto_dylib = lto cannot be used for `dylib` crate type without `-Zdy
3939
4040
codegen_llvm_lto_proc_macro = lto cannot be used for `proc-macro` crate type without `-Zdylib-lto`
4141
42+
codegen_llvm_mismatch_data_layout =
43+
data-layout for target `{$rustc_target}`, `{$rustc_layout}`, differs from LLVM target's `{$llvm_target}` default layout, `{$llvm_layout}`
44+
4245
codegen_llvm_missing_features =
4346
add the missing features in a `target_feature` attribute
4447

compiler/rustc_codegen_llvm/src/context.rs

+9-29
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use rustc_target::spec::{HasTargetSpec, RelocModel, Target, TlsModel};
3434
use smallvec::SmallVec;
3535

3636
use libc::c_uint;
37+
use std::borrow::Borrow;
3738
use std::cell::{Cell, RefCell};
3839
use std::ffi::CStr;
3940
use std::str;
@@ -155,42 +156,21 @@ pub unsafe fn create_module<'ll>(
155156
}
156157

157158
// Ensure the data-layout values hardcoded remain the defaults.
158-
if sess.target.is_builtin {
159-
// tm is disposed by its drop impl
159+
{
160160
let tm = crate::back::write::create_informational_target_machine(tcx.sess);
161161
llvm::LLVMRustSetDataLayoutFromTargetMachine(llmod, &tm);
162162

163163
let llvm_data_layout = llvm::LLVMGetDataLayoutStr(llmod);
164164
let llvm_data_layout = str::from_utf8(CStr::from_ptr(llvm_data_layout).to_bytes())
165165
.expect("got a non-UTF8 data-layout from LLVM");
166166

167-
// Unfortunately LLVM target specs change over time, and right now we
168-
// don't have proper support to work with any more than one
169-
// `data_layout` than the one that is in the rust-lang/rust repo. If
170-
// this compiler is configured against a custom LLVM, we may have a
171-
// differing data layout, even though we should update our own to use
172-
// that one.
173-
//
174-
// As an interim hack, if CFG_LLVM_ROOT is not an empty string then we
175-
// disable this check entirely as we may be configured with something
176-
// that has a different target layout.
177-
//
178-
// Unsure if this will actually cause breakage when rustc is configured
179-
// as such.
180-
//
181-
// FIXME(#34960)
182-
let cfg_llvm_root = option_env!("CFG_LLVM_ROOT").unwrap_or("");
183-
let custom_llvm_used = !cfg_llvm_root.trim().is_empty();
184-
185-
if !custom_llvm_used && target_data_layout != llvm_data_layout {
186-
bug!(
187-
"data-layout for target `{rustc_target}`, `{rustc_layout}`, \
188-
differs from LLVM target's `{llvm_target}` default layout, `{llvm_layout}`",
189-
rustc_target = sess.opts.target_triple,
190-
rustc_layout = target_data_layout,
191-
llvm_target = sess.target.llvm_target,
192-
llvm_layout = llvm_data_layout
193-
);
167+
if target_data_layout != llvm_data_layout {
168+
tcx.dcx().emit_err(crate::errors::MismatchedDataLayout {
169+
rustc_target: sess.opts.target_triple.to_string().as_str(),
170+
rustc_layout: target_data_layout.as_str(),
171+
llvm_target: sess.target.llvm_target.borrow(),
172+
llvm_layout: llvm_data_layout,
173+
});
194174
}
195175
}
196176

compiler/rustc_codegen_llvm/src/errors.rs

+9
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,12 @@ pub(crate) struct CopyBitcode {
244244
pub struct UnknownCompression {
245245
pub algorithm: &'static str,
246246
}
247+
248+
#[derive(Diagnostic)]
249+
#[diag(codegen_llvm_mismatch_data_layout)]
250+
pub struct MismatchedDataLayout<'a> {
251+
pub rustc_target: &'a str,
252+
pub rustc_layout: &'a str,
253+
pub llvm_target: &'a str,
254+
pub llvm_layout: &'a str,
255+
}

compiler/rustc_codegen_ssa/src/back/link.rs

+36-28
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ use std::path::{Path, PathBuf};
5252
use std::process::{ExitStatus, Output, Stdio};
5353
use std::{env, fmt, fs, io, mem, str};
5454

55+
#[derive(Default)]
56+
pub struct SearchPaths(OnceCell<Vec<PathBuf>>);
57+
58+
impl SearchPaths {
59+
pub(super) fn get(&self, sess: &Session) -> &[PathBuf] {
60+
self.0.get_or_init(|| archive_search_paths(sess))
61+
}
62+
}
63+
5564
pub fn ensure_removed(dcx: &DiagCtxt, path: &Path) {
5665
if let Err(e) = fs::remove_file(path) {
5766
if e.kind() != io::ErrorKind::NotFound {
@@ -1265,15 +1274,15 @@ fn link_sanitizer_runtime(
12651274
let path = find_sanitizer_runtime(sess, &filename);
12661275
let rpath = path.to_str().expect("non-utf8 component in path");
12671276
linker.args(&["-Wl,-rpath", "-Xlinker", rpath]);
1268-
linker.link_dylib(&filename, false, true);
1277+
linker.link_dylib_by_name(&filename, false, true);
12691278
} else if sess.target.is_like_msvc && flavor == LinkerFlavor::Msvc(Lld::No) && name == "asan" {
12701279
// MSVC provides the `/INFERASANLIBS` argument to automatically find the
12711280
// compatible ASAN library.
12721281
linker.arg("/INFERASANLIBS");
12731282
} else {
12741283
let filename = format!("librustc{channel}_rt.{name}.a");
12751284
let path = find_sanitizer_runtime(sess, &filename).join(&filename);
1276-
linker.link_whole_rlib(&path);
1285+
linker.link_staticlib_by_path(&path, true);
12771286
}
12781287
}
12791288

@@ -2445,7 +2454,7 @@ fn add_native_libs_from_crate(
24452454
archive_builder_builder: &dyn ArchiveBuilderBuilder,
24462455
codegen_results: &CodegenResults,
24472456
tmpdir: &Path,
2448-
search_paths: &OnceCell<Vec<PathBuf>>,
2457+
search_paths: &SearchPaths,
24492458
bundled_libs: &FxHashSet<Symbol>,
24502459
cnum: CrateNum,
24512460
link_static: bool,
@@ -2505,46 +2514,34 @@ fn add_native_libs_from_crate(
25052514
if let Some(filename) = lib.filename {
25062515
// If rlib contains native libs as archives, they are unpacked to tmpdir.
25072516
let path = tmpdir.join(filename.as_str());
2508-
if whole_archive {
2509-
cmd.link_whole_rlib(&path);
2510-
} else {
2511-
cmd.link_rlib(&path);
2512-
}
2517+
cmd.link_staticlib_by_path(&path, whole_archive);
25132518
}
25142519
} else {
2515-
if whole_archive {
2516-
cmd.link_whole_staticlib(
2517-
name,
2518-
verbatim,
2519-
search_paths.get_or_init(|| archive_search_paths(sess)),
2520-
);
2521-
} else {
2522-
cmd.link_staticlib(name, verbatim)
2523-
}
2520+
cmd.link_staticlib_by_name(name, verbatim, whole_archive, search_paths);
25242521
}
25252522
}
25262523
}
25272524
NativeLibKind::Dylib { as_needed } => {
25282525
if link_dynamic {
2529-
cmd.link_dylib(name, verbatim, as_needed.unwrap_or(true))
2526+
cmd.link_dylib_by_name(name, verbatim, as_needed.unwrap_or(true))
25302527
}
25312528
}
25322529
NativeLibKind::Unspecified => {
25332530
// If we are generating a static binary, prefer static library when the
25342531
// link kind is unspecified.
25352532
if !link_output_kind.can_link_dylib() && !sess.target.crt_static_allows_dylibs {
25362533
if link_static {
2537-
cmd.link_staticlib(name, verbatim)
2534+
cmd.link_staticlib_by_name(name, verbatim, false, search_paths);
25382535
}
25392536
} else {
25402537
if link_dynamic {
2541-
cmd.link_dylib(name, verbatim, true);
2538+
cmd.link_dylib_by_name(name, verbatim, true);
25422539
}
25432540
}
25442541
}
25452542
NativeLibKind::Framework { as_needed } => {
25462543
if link_dynamic {
2547-
cmd.link_framework(name, as_needed.unwrap_or(true))
2544+
cmd.link_framework_by_name(name, verbatim, as_needed.unwrap_or(true))
25482545
}
25492546
}
25502547
NativeLibKind::RawDylib => {
@@ -2581,7 +2578,7 @@ fn add_local_native_libraries(
25812578
}
25822579
}
25832580

2584-
let search_paths = OnceCell::new();
2581+
let search_paths = SearchPaths::default();
25852582
// All static and dynamic native library dependencies are linked to the local crate.
25862583
let link_static = true;
25872584
let link_dynamic = true;
@@ -2623,7 +2620,7 @@ fn add_upstream_rust_crates<'a>(
26232620
.find(|(ty, _)| *ty == crate_type)
26242621
.expect("failed to find crate type in dependency format list");
26252622

2626-
let search_paths = OnceCell::new();
2623+
let search_paths = SearchPaths::default();
26272624
for &cnum in &codegen_results.crate_info.used_crates {
26282625
// We may not pass all crates through to the linker. Some crates may appear statically in
26292626
// an existing dylib, meaning we'll pick up all the symbols from the dylib.
@@ -2698,7 +2695,7 @@ fn add_upstream_native_libraries(
26982695
tmpdir: &Path,
26992696
link_output_kind: LinkOutputKind,
27002697
) {
2701-
let search_path = OnceCell::new();
2698+
let search_paths = SearchPaths::default();
27022699
for &cnum in &codegen_results.crate_info.used_crates {
27032700
// Static libraries are not linked here, they are linked in `add_upstream_rust_crates`.
27042701
// FIXME: Merge this function to `add_upstream_rust_crates` so that all native libraries
@@ -2720,7 +2717,7 @@ fn add_upstream_native_libraries(
27202717
archive_builder_builder,
27212718
codegen_results,
27222719
tmpdir,
2723-
&search_path,
2720+
&search_paths,
27242721
&Default::default(),
27252722
cnum,
27262723
link_static,
@@ -2791,7 +2788,7 @@ fn add_static_crate<'a>(
27912788
} else {
27922789
fix_windows_verbatim_for_gcc(path)
27932790
};
2794-
cmd.link_rlib(&rlib_path);
2791+
cmd.link_staticlib_by_path(&rlib_path, false);
27952792
};
27962793

27972794
if !are_upstream_rust_objects_already_included(sess)
@@ -2859,13 +2856,24 @@ fn add_dynamic_crate(cmd: &mut dyn Linker, sess: &Session, cratepath: &Path) {
28592856
// Just need to tell the linker about where the library lives and
28602857
// what its name is
28612858
let parent = cratepath.parent();
2859+
// When producing a dll, the MSVC linker may not actually emit a
2860+
// `foo.lib` file if the dll doesn't actually export any symbols, so we
2861+
// check to see if the file is there and just omit linking to it if it's
2862+
// not present.
2863+
if sess.target.is_like_msvc && !cratepath.with_extension("dll.lib").exists() {
2864+
return;
2865+
}
28622866
if let Some(dir) = parent {
28632867
cmd.include_path(&rehome_sysroot_lib_dir(sess, dir));
28642868
}
2865-
let stem = cratepath.file_stem().unwrap().to_str().unwrap();
2869+
// "<dir>/name.dll -> name.dll" on windows-msvc
2870+
// "<dir>/name.dll -> name" on windows-gnu
2871+
// "<dir>/libname.<ext> -> name" elsewhere
2872+
let stem = if sess.target.is_like_msvc { cratepath.file_name() } else { cratepath.file_stem() };
2873+
let stem = stem.unwrap().to_str().unwrap();
28662874
// Convert library file-stem into a cc -l argument.
28672875
let prefix = if stem.starts_with("lib") && !sess.target.is_like_windows { 3 } else { 0 };
2868-
cmd.link_rust_dylib(&stem[prefix..], parent.unwrap_or_else(|| Path::new("")));
2876+
cmd.link_dylib_by_name(&stem[prefix..], false, true);
28692877
}
28702878

28712879
fn relevant_lib(sess: &Session, lib: &NativeLib) -> bool {

0 commit comments

Comments
 (0)