Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c00992b

Browse files
committedFeb 5, 2024
Auto merge of rust-lang#120060 - saethlin:mir-opt-bless-targets, r=wesleywiser
Use the same mir-opt bless targets on all platforms This undoes some of the implementation in rust-lang#119035, but not the effect. Sorry for the churn, I've learned a lot about how all this works over the past few weeks. The objective here is to make `x test mir-opt --bless` use the same set of targets on all platforms. It didn't do that from the start because bootstrap assumes that a target linker is available, so the availability of cross-linkers is how we ended up with `MIR_OPT_BLESS_TARGET_MAPPING` and poor support for blessing mir-opt tests from Aarch64 MacOS. This PR corrects that. So I've adjusted the bless targets for mir-opt tests, as well as tweaked some of the logic in bootstrap about linker configuration so that we don't try to access the cache of cc/linker configuration when doing the mir-opt builds. While working on that I realized that if I swapped from the `cargo rustc -p std` strategy to `cargo check` on the sysroot, I could use the existing code for check builds to bypass some linker logic. Sweet. But just doing that doesn't work, because then mir-opt tests complain that they can't find an rlib for any of the standard library crates. That happens because nearly all the mir-opt tests are attempting to build `CrateType::Executable`. We already have all the MIR required for mir-opt tests from the rmeta files, but since rustc think we're trying to build an executable it demands we have access to all the upstream monomorphizations that only exist in rlibs, not the meta files in a MIR-only sysroot. So to fix that, I've swapped all the mir-opt tests be passed `--crate-type=rlib`. That works, but leaves us with a few broken mir-opt tests which I've blessed or fixed up; we also lose MIR for some functions so I added `-Clink-dead-code` to paper over that. The inlining changes are because changing the crate-type perturbs the hashes that are compared here to sometimes let us do inlining even in a possibly-recursive call: https://github.com/rust-lang/rust/blob/4cb17b4e78e0540e49d2da884cc621a6bf6f47fa/compiler/rustc_mir_transform/src/inline.rs#L332-L341
2 parents ea37e80 + 815d312 commit c00992b

15 files changed

+224
-267
lines changed
 

‎src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,20 @@ impl Std {
9797
is_for_mir_opt_tests: false,
9898
}
9999
}
100+
101+
fn copy_extra_objects(
102+
&self,
103+
builder: &Builder<'_>,
104+
compiler: &Compiler,
105+
target: TargetSelection,
106+
) -> Vec<(PathBuf, DependencyType)> {
107+
let mut deps = Vec::new();
108+
if !self.is_for_mir_opt_tests {
109+
deps.extend(copy_third_party_objects(builder, &compiler, target));
110+
deps.extend(copy_self_contained_objects(builder, &compiler, target));
111+
}
112+
deps
113+
}
100114
}
101115

102116
impl Step for Std {
@@ -159,8 +173,7 @@ impl Step for Std {
159173
{
160174
builder.info("WARNING: Using a potentially old libstd. This may not behave well.");
161175

162-
copy_third_party_objects(builder, &compiler, target);
163-
copy_self_contained_objects(builder, &compiler, target);
176+
self.copy_extra_objects(builder, &compiler, target);
164177

165178
builder.ensure(StdLink::from_std(self, compiler));
166179
return;
@@ -193,15 +206,13 @@ impl Step for Std {
193206

194207
// Even if we're not building std this stage, the new sysroot must
195208
// still contain the third party objects needed by various targets.
196-
copy_third_party_objects(builder, &compiler, target);
197-
copy_self_contained_objects(builder, &compiler, target);
209+
self.copy_extra_objects(builder, &compiler, target);
198210

199211
builder.ensure(StdLink::from_std(self, compiler_to_use));
200212
return;
201213
}
202214

203-
target_deps.extend(copy_third_party_objects(builder, &compiler, target));
204-
target_deps.extend(copy_self_contained_objects(builder, &compiler, target));
215+
target_deps.extend(self.copy_extra_objects(builder, &compiler, target));
205216

206217
// The LLD wrappers and `rust-lld` are self-contained linking components that can be
207218
// necessary to link the stdlib on some targets. We'll also need to copy these binaries to
@@ -222,9 +233,12 @@ impl Step for Std {
222233
}
223234
}
224235

236+
// We build a sysroot for mir-opt tests using the same trick that Miri does: A check build
237+
// with -Zalways-encode-mir. This frees us from the need to have a target linker, and the
238+
// fact that this is a check build integrates nicely with run_cargo.
225239
let mut cargo = if self.is_for_mir_opt_tests {
226-
let mut cargo = builder.cargo(compiler, Mode::Std, SourceType::InTree, target, "rustc");
227-
cargo.arg("-p").arg("std").arg("--crate-type=lib");
240+
let mut cargo = builder.cargo(compiler, Mode::Std, SourceType::InTree, target, "check");
241+
cargo.rustflag("-Zalways-encode-mir");
228242
std_cargo(builder, target, compiler.stage, &mut cargo);
229243
cargo
230244
} else {
@@ -257,7 +271,7 @@ impl Step for Std {
257271
vec![],
258272
&libstd_stamp(builder, compiler, target),
259273
target_deps,
260-
false,
274+
self.is_for_mir_opt_tests, // is_check
261275
false,
262276
);
263277

‎src/bootstrap/src/core/build_steps/test.rs

Lines changed: 37 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use crate::core::builder::{Builder, Compiler, Kind, RunConfig, ShouldRun, Step};
2525
use crate::core::config::flags::get_completion;
2626
use crate::core::config::flags::Subcommand;
2727
use crate::core::config::TargetSelection;
28-
use crate::utils;
2928
use crate::utils::cache::{Interned, INTERNER};
3029
use crate::utils::exec::BootstrapCommand;
3130
use crate::utils::helpers::{
@@ -38,23 +37,6 @@ use crate::{envify, CLang, DocTests, GitRepo, Mode};
3837

3938
const ADB_TEST_DIR: &str = "/data/local/tmp/work";
4039

41-
// mir-opt tests have different variants depending on whether a target is 32bit or 64bit, and
42-
// blessing them requires blessing with each target. To aid developers, when blessing the mir-opt
43-
// test suite the corresponding target of the opposite pointer size is also blessed.
44-
//
45-
// This array serves as the known mappings between 32bit and 64bit targets. If you're developing on
46-
// a target where a target with the opposite pointer size exists, feel free to add it here.
47-
const MIR_OPT_BLESS_TARGET_MAPPING: &[(&str, &str)] = &[
48-
// (32bit, 64bit)
49-
("i686-unknown-linux-gnu", "x86_64-unknown-linux-gnu"),
50-
("i686-unknown-linux-musl", "x86_64-unknown-linux-musl"),
51-
("i686-pc-windows-msvc", "x86_64-pc-windows-msvc"),
52-
("i686-pc-windows-gnu", "x86_64-pc-windows-gnu"),
53-
// ARM Macs don't have a corresponding 32-bit target that they can (easily)
54-
// build for, so there is no entry for "aarch64-apple-darwin" here.
55-
// Likewise, i686 for macOS is no longer possible to build.
56-
];
57-
5840
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
5941
pub struct CrateBootstrap {
6042
path: Interned<PathBuf>,
@@ -1487,46 +1469,18 @@ impl Step for MirOpt {
14871469
})
14881470
};
14891471

1490-
// We use custom logic to bless the mir-opt suite: mir-opt tests have multiple variants
1491-
// (32bit vs 64bit, and panic=abort vs panic=unwind), and all of them needs to be blessed.
1492-
// When blessing, we try best-effort to also bless the other variants, to aid developers.
14931472
if builder.config.cmd.bless() {
1494-
let targets = MIR_OPT_BLESS_TARGET_MAPPING
1495-
.iter()
1496-
.filter(|(target_32bit, target_64bit)| {
1497-
*target_32bit == &*self.target.triple || *target_64bit == &*self.target.triple
1498-
})
1499-
.next()
1500-
.map(|(target_32bit, target_64bit)| {
1501-
let target_32bit = TargetSelection::from_user(target_32bit);
1502-
let target_64bit = TargetSelection::from_user(target_64bit);
1503-
1504-
// Running compiletest requires a C compiler to be available, but it might not
1505-
// have been detected by bootstrap if the target we're testing wasn't in the
1506-
// --target flags.
1507-
if !builder.cc.borrow().contains_key(&target_32bit) {
1508-
utils::cc_detect::find_target(builder, target_32bit);
1509-
}
1510-
if !builder.cc.borrow().contains_key(&target_64bit) {
1511-
utils::cc_detect::find_target(builder, target_64bit);
1512-
}
1473+
// All that we really need to do is cover all combinations of 32/64-bit and unwind/abort,
1474+
// but while we're at it we might as well flex our cross-compilation support. This
1475+
// selection covers all our tier 1 operating systems and architectures using only tier
1476+
// 1 targets.
15131477

1514-
vec![target_32bit, target_64bit]
1515-
})
1516-
.unwrap_or_else(|| {
1517-
eprintln!(
1518-
"\
1519-
Note that not all variants of mir-opt tests are going to be blessed, as no mapping between
1520-
a 32bit and a 64bit target was found for {target}.
1521-
You can add that mapping by changing MIR_OPT_BLESS_TARGET_MAPPING in src/bootstrap/test.rs",
1522-
target = self.target,
1523-
);
1524-
vec![self.target]
1525-
});
1526-
1527-
for target in targets {
1528-
run(target);
1478+
for target in ["aarch64-unknown-linux-gnu", "i686-pc-windows-msvc"] {
1479+
run(TargetSelection::from_user(target));
1480+
}
15291481

1482+
for target in ["x86_64-apple-darwin", "i686-unknown-linux-musl"] {
1483+
let target = TargetSelection::from_user(target);
15301484
let panic_abort_target = builder.ensure(MirOptPanicAbortSyntheticTarget {
15311485
compiler: self.compiler,
15321486
base: target,
@@ -1616,27 +1570,27 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
16161570
.ensure(dist::DebuggerScripts { sysroot: builder.sysroot(compiler), host: target });
16171571
}
16181572

1619-
if suite == "mir-opt" {
1620-
builder.ensure(compile::Std::new_for_mir_opt_tests(compiler, target));
1621-
} else {
1622-
builder.ensure(compile::Std::new(compiler, target));
1623-
}
1573+
// Also provide `rust_test_helpers` for the host.
1574+
builder.ensure(TestHelpers { target: compiler.host });
16241575

16251576
// ensure that `libproc_macro` is available on the host.
16261577
builder.ensure(compile::Std::new(compiler, compiler.host));
16271578

1628-
// Also provide `rust_test_helpers` for the host.
1629-
builder.ensure(TestHelpers { target: compiler.host });
1630-
16311579
// As well as the target, except for plain wasm32, which can't build it
16321580
if suite != "mir-opt" && !target.contains("wasm") && !target.contains("emscripten") {
16331581
builder.ensure(TestHelpers { target });
16341582
}
16351583

1636-
builder.ensure(RemoteCopyLibs { compiler, target });
1637-
16381584
let mut cmd = builder.tool_cmd(Tool::Compiletest);
16391585

1586+
if suite == "mir-opt" {
1587+
builder.ensure(compile::Std::new_for_mir_opt_tests(compiler, target));
1588+
} else {
1589+
builder.ensure(compile::Std::new(compiler, target));
1590+
}
1591+
1592+
builder.ensure(RemoteCopyLibs { compiler, target });
1593+
16401594
// compiletest currently has... a lot of arguments, so let's just pass all
16411595
// of them!
16421596

@@ -1745,11 +1699,13 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
17451699
flags.push(format!("-Cdebuginfo={}", builder.config.rust_debuginfo_level_tests));
17461700
flags.extend(builder.config.cmd.rustc_args().iter().map(|s| s.to_string()));
17471701

1748-
if let Some(linker) = builder.linker(target) {
1749-
cmd.arg("--target-linker").arg(linker);
1750-
}
1751-
if let Some(linker) = builder.linker(compiler.host) {
1752-
cmd.arg("--host-linker").arg(linker);
1702+
if suite != "mir-opt" {
1703+
if let Some(linker) = builder.linker(target) {
1704+
cmd.arg("--target-linker").arg(linker);
1705+
}
1706+
if let Some(linker) = builder.linker(compiler.host) {
1707+
cmd.arg("--host-linker").arg(linker);
1708+
}
17531709
}
17541710

17551711
let mut hostflags = flags.clone();
@@ -1936,15 +1892,17 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
19361892
cmd.arg("--remote-test-client").arg(builder.tool_exe(Tool::RemoteTestClient));
19371893
}
19381894

1939-
// Running a C compiler on MSVC requires a few env vars to be set, to be
1940-
// sure to set them here.
1941-
//
1942-
// Note that if we encounter `PATH` we make sure to append to our own `PATH`
1943-
// rather than stomp over it.
1944-
if !builder.config.dry_run() && target.is_msvc() {
1945-
for &(ref k, ref v) in builder.cc.borrow()[&target].env() {
1946-
if k != "PATH" {
1947-
cmd.env(k, v);
1895+
if suite != "mir-opt" {
1896+
// Running a C compiler on MSVC requires a few env vars to be set, to be
1897+
// sure to set them here.
1898+
//
1899+
// Note that if we encounter `PATH` we make sure to append to our own `PATH`
1900+
// rather than stomp over it.
1901+
if !builder.config.dry_run() && target.is_msvc() {
1902+
for &(ref k, ref v) in builder.cc.borrow()[&target].env() {
1903+
if k != "PATH" {
1904+
cmd.env(k, v);
1905+
}
19481906
}
19491907
}
19501908
}

‎src/bootstrap/src/core/builder.rs

Lines changed: 139 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,76 +1646,12 @@ impl<'a> Builder<'a> {
16461646
cargo.env("RUSTC_WRAPPER_REAL", existing_wrapper);
16471647
}
16481648

1649-
// Dealing with rpath here is a little special, so let's go into some
1650-
// detail. First off, `-rpath` is a linker option on Unix platforms
1651-
// which adds to the runtime dynamic loader path when looking for
1652-
// dynamic libraries. We use this by default on Unix platforms to ensure
1653-
// that our nightlies behave the same on Windows, that is they work out
1654-
// of the box. This can be disabled by setting `rpath = false` in `[rust]`
1655-
// table of `config.toml`
1656-
//
1657-
// Ok, so the astute might be wondering "why isn't `-C rpath` used
1658-
// here?" and that is indeed a good question to ask. This codegen
1659-
// option is the compiler's current interface to generating an rpath.
1660-
// Unfortunately it doesn't quite suffice for us. The flag currently
1661-
// takes no value as an argument, so the compiler calculates what it
1662-
// should pass to the linker as `-rpath`. This unfortunately is based on
1663-
// the **compile time** directory structure which when building with
1664-
// Cargo will be very different than the runtime directory structure.
1665-
//
1666-
// All that's a really long winded way of saying that if we use
1667-
// `-Crpath` then the executables generated have the wrong rpath of
1668-
// something like `$ORIGIN/deps` when in fact the way we distribute
1669-
// rustc requires the rpath to be `$ORIGIN/../lib`.
1670-
//
1671-
// So, all in all, to set up the correct rpath we pass the linker
1672-
// argument manually via `-C link-args=-Wl,-rpath,...`. Plus isn't it
1673-
// fun to pass a flag to a tool to pass a flag to pass a flag to a tool
1674-
// to change a flag in a binary?
1675-
if self.config.rpath_enabled(target) && helpers::use_host_linker(target) {
1676-
let libdir = self.sysroot_libdir_relative(compiler).to_str().unwrap();
1677-
let rpath = if target.contains("apple") {
1678-
// Note that we need to take one extra step on macOS to also pass
1679-
// `-Wl,-instal_name,@rpath/...` to get things to work right. To
1680-
// do that we pass a weird flag to the compiler to get it to do
1681-
// so. Note that this is definitely a hack, and we should likely
1682-
// flesh out rpath support more fully in the future.
1683-
rustflags.arg("-Zosx-rpath-install-name");
1684-
Some(format!("-Wl,-rpath,@loader_path/../{libdir}"))
1685-
} else if !target.is_windows() && !target.contains("aix") && !target.contains("xous") {
1686-
rustflags.arg("-Clink-args=-Wl,-z,origin");
1687-
Some(format!("-Wl,-rpath,$ORIGIN/../{libdir}"))
1688-
} else {
1689-
None
1690-
};
1691-
if let Some(rpath) = rpath {
1692-
rustflags.arg(&format!("-Clink-args={rpath}"));
1693-
}
1694-
}
1695-
16961649
cargo.env(profile_var("STRIP"), self.config.rust_strip.to_string());
16971650

16981651
if let Some(stack_protector) = &self.config.rust_stack_protector {
16991652
rustflags.arg(&format!("-Zstack-protector={stack_protector}"));
17001653
}
17011654

1702-
for arg in linker_args(self, compiler.host, LldThreads::Yes) {
1703-
hostflags.arg(&arg);
1704-
}
1705-
1706-
if let Some(target_linker) = self.linker(target) {
1707-
let target = crate::envify(&target.triple);
1708-
cargo.env(&format!("CARGO_TARGET_{target}_LINKER"), target_linker);
1709-
}
1710-
// We want to set -Clinker using Cargo, therefore we only call `linker_flags` and not
1711-
// `linker_args` here.
1712-
for flag in linker_flags(self, target, LldThreads::Yes) {
1713-
rustflags.arg(&flag);
1714-
}
1715-
for arg in linker_args(self, target, LldThreads::Yes) {
1716-
rustdocflags.arg(&arg);
1717-
}
1718-
17191655
if !(["build", "check", "clippy", "fix", "rustc"].contains(&cmd)) && want_rustdoc {
17201656
cargo.env("RUSTDOC_LIBDIR", self.rustc_libdir(compiler));
17211657
}
@@ -1731,10 +1667,6 @@ impl<'a> Builder<'a> {
17311667
if let Some(opt_level) = &self.config.rust_optimize.get_opt_level() {
17321668
cargo.env(profile_var("OPT_LEVEL"), opt_level);
17331669
}
1734-
if !self.config.dry_run() && self.cc.borrow()[&target].args().iter().any(|arg| arg == "-gz")
1735-
{
1736-
rustflags.arg("-Clink-arg=-gz");
1737-
}
17381670
cargo.env(
17391671
profile_var("DEBUG_ASSERTIONS"),
17401672
if mode == Mode::Std {
@@ -1940,55 +1872,15 @@ impl<'a> Builder<'a> {
19401872
rustflags.arg("-Wrustc::internal");
19411873
}
19421874

1943-
// Throughout the build Cargo can execute a number of build scripts
1944-
// compiling C/C++ code and we need to pass compilers, archivers, flags, etc
1945-
// obtained previously to those build scripts.
1946-
// Build scripts use either the `cc` crate or `configure/make` so we pass
1947-
// the options through environment variables that are fetched and understood by both.
1948-
//
1949-
// FIXME: the guard against msvc shouldn't need to be here
1950-
if target.is_msvc() {
1951-
if let Some(ref cl) = self.config.llvm_clang_cl {
1952-
cargo.env("CC", cl).env("CXX", cl);
1953-
}
1954-
} else {
1955-
let ccache = self.config.ccache.as_ref();
1956-
let ccacheify = |s: &Path| {
1957-
let ccache = match ccache {
1958-
Some(ref s) => s,
1959-
None => return s.display().to_string(),
1960-
};
1961-
// FIXME: the cc-rs crate only recognizes the literal strings
1962-
// `ccache` and `sccache` when doing caching compilations, so we
1963-
// mirror that here. It should probably be fixed upstream to
1964-
// accept a new env var or otherwise work with custom ccache
1965-
// vars.
1966-
match &ccache[..] {
1967-
"ccache" | "sccache" => format!("{} {}", ccache, s.display()),
1968-
_ => s.display().to_string(),
1969-
}
1970-
};
1971-
let triple_underscored = target.triple.replace("-", "_");
1972-
let cc = ccacheify(&self.cc(target));
1973-
cargo.env(format!("CC_{triple_underscored}"), &cc);
1974-
1975-
let cflags = self.cflags(target, GitRepo::Rustc, CLang::C).join(" ");
1976-
cargo.env(format!("CFLAGS_{triple_underscored}"), &cflags);
1977-
1978-
if let Some(ar) = self.ar(target) {
1979-
let ranlib = format!("{} s", ar.display());
1980-
cargo
1981-
.env(format!("AR_{triple_underscored}"), ar)
1982-
.env(format!("RANLIB_{triple_underscored}"), ranlib);
1983-
}
1984-
1985-
if let Ok(cxx) = self.cxx(target) {
1986-
let cxx = ccacheify(&cxx);
1987-
let cxxflags = self.cflags(target, GitRepo::Rustc, CLang::Cxx).join(" ");
1988-
cargo
1989-
.env(format!("CXX_{triple_underscored}"), &cxx)
1990-
.env(format!("CXXFLAGS_{triple_underscored}"), cxxflags);
1991-
}
1875+
if cmd != "check" {
1876+
self.configure_linker(
1877+
compiler,
1878+
target,
1879+
&mut cargo,
1880+
&mut rustflags,
1881+
&mut rustdocflags,
1882+
&mut hostflags,
1883+
);
19921884
}
19931885

19941886
// If Control Flow Guard is enabled, pass the `control-flow-guard` flag to rustc
@@ -2142,6 +2034,136 @@ impl<'a> Builder<'a> {
21422034
Cargo { command: cargo, rustflags, rustdocflags, hostflags, allow_features }
21432035
}
21442036

2037+
fn configure_linker(
2038+
&self,
2039+
compiler: Compiler,
2040+
target: TargetSelection,
2041+
cargo: &mut Command,
2042+
rustflags: &mut Rustflags,
2043+
rustdocflags: &mut Rustflags,
2044+
hostflags: &mut HostFlags,
2045+
) {
2046+
// Dealing with rpath here is a little special, so let's go into some
2047+
// detail. First off, `-rpath` is a linker option on Unix platforms
2048+
// which adds to the runtime dynamic loader path when looking for
2049+
// dynamic libraries. We use this by default on Unix platforms to ensure
2050+
// that our nightlies behave the same on Windows, that is they work out
2051+
// of the box. This can be disabled by setting `rpath = false` in `[rust]`
2052+
// table of `config.toml`
2053+
//
2054+
// Ok, so the astute might be wondering "why isn't `-C rpath` used
2055+
// here?" and that is indeed a good question to ask. This codegen
2056+
// option is the compiler's current interface to generating an rpath.
2057+
// Unfortunately it doesn't quite suffice for us. The flag currently
2058+
// takes no value as an argument, so the compiler calculates what it
2059+
// should pass to the linker as `-rpath`. This unfortunately is based on
2060+
// the **compile time** directory structure which when building with
2061+
// Cargo will be very different than the runtime directory structure.
2062+
//
2063+
// All that's a really long winded way of saying that if we use
2064+
// `-Crpath` then the executables generated have the wrong rpath of
2065+
// something like `$ORIGIN/deps` when in fact the way we distribute
2066+
// rustc requires the rpath to be `$ORIGIN/../lib`.
2067+
//
2068+
// So, all in all, to set up the correct rpath we pass the linker
2069+
// argument manually via `-C link-args=-Wl,-rpath,...`. Plus isn't it
2070+
// fun to pass a flag to a tool to pass a flag to pass a flag to a tool
2071+
// to change a flag in a binary?
2072+
if self.config.rpath_enabled(target) && helpers::use_host_linker(target) {
2073+
let libdir = self.sysroot_libdir_relative(compiler).to_str().unwrap();
2074+
let rpath = if target.contains("apple") {
2075+
// Note that we need to take one extra step on macOS to also pass
2076+
// `-Wl,-instal_name,@rpath/...` to get things to work right. To
2077+
// do that we pass a weird flag to the compiler to get it to do
2078+
// so. Note that this is definitely a hack, and we should likely
2079+
// flesh out rpath support more fully in the future.
2080+
rustflags.arg("-Zosx-rpath-install-name");
2081+
Some(format!("-Wl,-rpath,@loader_path/../{libdir}"))
2082+
} else if !target.is_windows() && !target.contains("aix") && !target.contains("xous") {
2083+
rustflags.arg("-Clink-args=-Wl,-z,origin");
2084+
Some(format!("-Wl,-rpath,$ORIGIN/../{libdir}"))
2085+
} else {
2086+
None
2087+
};
2088+
if let Some(rpath) = rpath {
2089+
rustflags.arg(&format!("-Clink-args={rpath}"));
2090+
}
2091+
}
2092+
2093+
for arg in linker_args(self, compiler.host, LldThreads::Yes) {
2094+
hostflags.arg(&arg);
2095+
}
2096+
2097+
if let Some(target_linker) = self.linker(target) {
2098+
let target = crate::envify(&target.triple);
2099+
cargo.env(&format!("CARGO_TARGET_{target}_LINKER"), target_linker);
2100+
}
2101+
// We want to set -Clinker using Cargo, therefore we only call `linker_flags` and not
2102+
// `linker_args` here.
2103+
for flag in linker_flags(self, target, LldThreads::Yes) {
2104+
rustflags.arg(&flag);
2105+
}
2106+
for arg in linker_args(self, target, LldThreads::Yes) {
2107+
rustdocflags.arg(&arg);
2108+
}
2109+
2110+
if !self.config.dry_run() && self.cc.borrow()[&target].args().iter().any(|arg| arg == "-gz")
2111+
{
2112+
rustflags.arg("-Clink-arg=-gz");
2113+
}
2114+
2115+
// Throughout the build Cargo can execute a number of build scripts
2116+
// compiling C/C++ code and we need to pass compilers, archivers, flags, etc
2117+
// obtained previously to those build scripts.
2118+
// Build scripts use either the `cc` crate or `configure/make` so we pass
2119+
// the options through environment variables that are fetched and understood by both.
2120+
//
2121+
// FIXME: the guard against msvc shouldn't need to be here
2122+
if target.is_msvc() {
2123+
if let Some(ref cl) = self.config.llvm_clang_cl {
2124+
cargo.env("CC", cl).env("CXX", cl);
2125+
}
2126+
} else {
2127+
let ccache = self.config.ccache.as_ref();
2128+
let ccacheify = |s: &Path| {
2129+
let ccache = match ccache {
2130+
Some(ref s) => s,
2131+
None => return s.display().to_string(),
2132+
};
2133+
// FIXME: the cc-rs crate only recognizes the literal strings
2134+
// `ccache` and `sccache` when doing caching compilations, so we
2135+
// mirror that here. It should probably be fixed upstream to
2136+
// accept a new env var or otherwise work with custom ccache
2137+
// vars.
2138+
match &ccache[..] {
2139+
"ccache" | "sccache" => format!("{} {}", ccache, s.display()),
2140+
_ => s.display().to_string(),
2141+
}
2142+
};
2143+
let triple_underscored = target.triple.replace("-", "_");
2144+
let cc = ccacheify(&self.cc(target));
2145+
cargo.env(format!("CC_{triple_underscored}"), &cc);
2146+
2147+
let cflags = self.cflags(target, GitRepo::Rustc, CLang::C).join(" ");
2148+
cargo.env(format!("CFLAGS_{triple_underscored}"), &cflags);
2149+
2150+
if let Some(ar) = self.ar(target) {
2151+
let ranlib = format!("{} s", ar.display());
2152+
cargo
2153+
.env(format!("AR_{triple_underscored}"), ar)
2154+
.env(format!("RANLIB_{triple_underscored}"), ranlib);
2155+
}
2156+
2157+
if let Ok(cxx) = self.cxx(target) {
2158+
let cxx = ccacheify(&cxx);
2159+
let cxxflags = self.cflags(target, GitRepo::Rustc, CLang::Cxx).join(" ");
2160+
cargo
2161+
.env(format!("CXX_{triple_underscored}"), &cxx)
2162+
.env(format!("CXXFLAGS_{triple_underscored}"), cxxflags);
2163+
}
2164+
}
2165+
}
2166+
21452167
/// Ensure that a given step is built, returning its output. This will
21462168
/// cache the step, so it is safe (and good!) to call this as often as
21472169
/// needed to ensure that all dependencies are built.

‎src/tools/compiletest/src/runtest.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2467,6 +2467,7 @@ impl<'test> TestCx<'test> {
24672467
"-Zvalidate-mir",
24682468
"-Zlint-mir",
24692469
"-Zdump-mir-exclude-pass-number",
2470+
"--crate-type=rlib",
24702471
]);
24712472
if let Some(pass) = &self.props.mir_unit_test {
24722473
rustc.args(&["-Zmir-opt-level=0", &format!("-Zmir-enable-passes=+{}", pass)]);

‎tests/mir-opt/fn_ptr_shim.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// (as only `FnDef` and `FnPtr` callees are allowed in MIR).
66

77
// EMIT_MIR core.ops-function-Fn-call.AddMovesForPackedDrops.before.mir
8-
fn main() {
8+
pub fn main() {
99
call(noop as fn());
1010
}
1111

‎tests/mir-opt/inline/cycle.g.Inline.panic-abort.diff

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,16 @@
44
fn g() -> () {
55
let mut _0: ();
66
let _1: ();
7-
+ let mut _2: fn() {main};
8-
+ scope 1 (inlined f::<fn() {main}>) {
9-
+ debug g => _2;
10-
+ let mut _3: &fn() {main};
11-
+ let _4: ();
12-
+ }
137

148
bb0: {
159
StorageLive(_1);
16-
- _1 = f::<fn() {main}>(main) -> [return: bb1, unwind unreachable];
17-
+ StorageLive(_2);
18-
+ _2 = main;
19-
+ StorageLive(_4);
20-
+ StorageLive(_3);
21-
+ _3 = &_2;
22-
+ _4 = <fn() {main} as Fn<()>>::call(move _3, const ()) -> [return: bb2, unwind unreachable];
10+
_1 = f::<fn() {main}>(main) -> [return: bb1, unwind unreachable];
2311
}
2412

2513
bb1: {
26-
+ StorageDead(_4);
27-
+ StorageDead(_2);
2814
StorageDead(_1);
2915
_0 = const ();
3016
return;
31-
+ }
32-
+
33-
+ bb2: {
34-
+ StorageDead(_3);
35-
+ drop(_2) -> [return: bb1, unwind unreachable];
3617
}
3718
}
3819

‎tests/mir-opt/inline/cycle.g.Inline.panic-unwind.diff

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,16 @@
44
fn g() -> () {
55
let mut _0: ();
66
let _1: ();
7-
+ let mut _2: fn() {main};
8-
+ scope 1 (inlined f::<fn() {main}>) {
9-
+ debug g => _2;
10-
+ let mut _3: &fn() {main};
11-
+ let _4: ();
12-
+ }
137

148
bb0: {
159
StorageLive(_1);
16-
- _1 = f::<fn() {main}>(main) -> [return: bb1, unwind continue];
17-
+ StorageLive(_2);
18-
+ _2 = main;
19-
+ StorageLive(_4);
20-
+ StorageLive(_3);
21-
+ _3 = &_2;
22-
+ _4 = <fn() {main} as Fn<()>>::call(move _3, const ()) -> [return: bb2, unwind: bb3];
10+
_1 = f::<fn() {main}>(main) -> [return: bb1, unwind continue];
2311
}
2412

2513
bb1: {
26-
+ StorageDead(_4);
27-
+ StorageDead(_2);
2814
StorageDead(_1);
2915
_0 = const ();
3016
return;
31-
+ }
32-
+
33-
+ bb2: {
34-
+ StorageDead(_3);
35-
+ drop(_2) -> [return: bb1, unwind continue];
36-
+ }
37-
+
38-
+ bb3 (cleanup): {
39-
+ drop(_2) -> [return: bb4, unwind terminate(cleanup)];
40-
+ }
41-
+
42-
+ bb4 (cleanup): {
43-
+ resume;
4417
}
4518
}
4619

‎tests/mir-opt/inline/cycle.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ fn f(g: impl Fn()) {
1313
#[inline(always)]
1414
fn g() {
1515
// CHECK-LABEL: fn g(
16-
// CHECK-NOT: inlined
17-
// CHECK: (inlined f::<fn() {main}>)
18-
// CHECK-NOT: inlined
16+
// CHECK-NOT: (inlined f::<fn() {main}>)
1917
f(main);
2018
}
2119

‎tests/mir-opt/inline/inline_cycle_generic.main.Inline.panic-abort.diff

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@
77
+ scope 1 (inlined <C as Call>::call) {
88
+ scope 2 (inlined <B<A> as Call>::call) {
99
+ scope 3 (inlined <A as Call>::call) {
10+
+ scope 4 (inlined <B<C> as Call>::call) {
11+
+ scope 5 (inlined <C as Call>::call) {
12+
+ }
13+
+ }
1014
+ }
1115
+ }
1216
+ }
1317

1418
bb0: {
1519
StorageLive(_1);
1620
- _1 = <C as Call>::call() -> [return: bb1, unwind unreachable];
17-
+ _1 = <B<C> as Call>::call() -> [return: bb1, unwind unreachable];
21+
+ _1 = <B<A> as Call>::call() -> [return: bb1, unwind unreachable];
1822
}
1923

2024
bb1: {

‎tests/mir-opt/inline/inline_cycle_generic.main.Inline.panic-unwind.diff

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@
77
+ scope 1 (inlined <C as Call>::call) {
88
+ scope 2 (inlined <B<A> as Call>::call) {
99
+ scope 3 (inlined <A as Call>::call) {
10+
+ scope 4 (inlined <B<C> as Call>::call) {
11+
+ scope 5 (inlined <C as Call>::call) {
12+
+ }
13+
+ }
1014
+ }
1115
+ }
1216
+ }
1317

1418
bb0: {
1519
StorageLive(_1);
1620
- _1 = <C as Call>::call() -> [return: bb1, unwind continue];
17-
+ _1 = <B<C> as Call>::call() -> [return: bb1, unwind continue];
21+
+ _1 = <B<A> as Call>::call() -> [return: bb1, unwind continue];
1822
}
1923

2024
bb1: {

‎tests/mir-opt/issue_99325.main.built.after.32bit.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// MIR for `main` after built
22

33
| User Type Annotations
4-
| 0: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[22bb]::function_with_bytes), UserArgs { args: [&*b"AAAA"], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:13:16: 13:46, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
5-
| 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[22bb]::function_with_bytes), UserArgs { args: [UnevaluatedConst { def: DefId(0:8 ~ issue_99325[22bb]::main::{constant#1}), args: [] }: &ReStatic [u8; 4_usize]], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:14:16: 14:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
4+
| 0: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [&*b"AAAA"], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:13:16: 13:46, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
5+
| 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [UnevaluatedConst { def: DefId(0:8 ~ issue_99325[d56d]::main::{constant#1}), args: [] }: &ReStatic [u8; 4_usize]], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:14:16: 14:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
66
|
77
fn main() -> () {
88
let mut _0: ();

‎tests/mir-opt/issue_99325.main.built.after.64bit.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// MIR for `main` after built
22

33
| User Type Annotations
4-
| 0: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[22bb]::function_with_bytes), UserArgs { args: [&*b"AAAA"], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:13:16: 13:46, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
5-
| 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[22bb]::function_with_bytes), UserArgs { args: [UnevaluatedConst { def: DefId(0:8 ~ issue_99325[22bb]::main::{constant#1}), args: [] }: &ReStatic [u8; 4_usize]], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:14:16: 14:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
4+
| 0: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [&*b"AAAA"], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:13:16: 13:46, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
5+
| 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [UnevaluatedConst { def: DefId(0:8 ~ issue_99325[d56d]::main::{constant#1}), args: [] }: &ReStatic [u8; 4_usize]], user_self_ty: None }), max_universe: U0, variables: [] }, span: $DIR/issue_99325.rs:14:16: 14:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
66
|
77
fn main() -> () {
88
let mut _0: ();

‎tests/mir-opt/retag.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl Drop for Test {
2828

2929
// EMIT_MIR retag.main.SimplifyCfg-elaborate-drops.after.mir
3030
// EMIT_MIR retag.main-{closure#0}.SimplifyCfg-elaborate-drops.after.mir
31-
fn main() {
31+
pub fn main() {
3232
let mut x = 0;
3333
{
3434
let v = Test(0).foo(&mut x); // just making sure we do not panic when there is a tuple struct ctor

‎tests/mir-opt/slice_drop_shim.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// skip-filecheck
2-
// compile-flags: -Zmir-opt-level=0
3-
2+
// compile-flags: -Zmir-opt-level=0 -Clink-dead-code
3+
// mir-opt tests are always built as rlibs so that they seamlessly cross-compile,
4+
// so this test only produces MIR for the drop_in_place we're looking for
5+
// if we use -Clink-dead-code.
46

57
// EMIT_MIR core.ptr-drop_in_place.[String].AddMovesForPackedDrops.before.mir
68
fn main() {

‎tests/mir-opt/unusual_item_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ enum E {
2323
V = 5,
2424
}
2525

26-
fn main() {
26+
pub fn main() {
2727
let f = Test::X as fn(usize) -> Test;
2828
// EMIT_MIR core.ptr-drop_in_place.Vec_i32_.AddMovesForPackedDrops.before.mir
2929
let v = Vec::<i32>::new();

0 commit comments

Comments
 (0)
This repository has been archived.