diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-11-05 23:43:56 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-05 23:43:56 +0100 |
| commit | 8dee3e978a712bf6ed377473352edfc13f5e235c (patch) | |
| tree | 53296661b00d148e2f575031491c5518b12758ea | |
| parent | efa5af96a1ab626047feb70f54b1cfce0d4a2d36 (diff) | |
| parent | f745467cd99cdcb62151c3b0c90f5467e7adfe69 (diff) | |
| download | rust-8dee3e978a712bf6ed377473352edfc13f5e235c.tar.gz rust-8dee3e978a712bf6ed377473352edfc13f5e235c.zip | |
Rollup merge of #131405 - davidtwco:hardcoded-strip-macos, r=jieyouxu,albertlarsan68
bootstrap/codegen_ssa: ship llvm-strip and use it for -Cstrip Fixes #131206. - Includes `llvm-strip` (a symlink to `llvm-objcopy`) in the compiler dist artifact so that it can be used for `-Cstrip` instead of the system tooling. - Uses `llvm-strip` instead of `/usr/bin/strip` for macOS. macOS needs a specific linker and the system one is preferred, hence #130781 but that doesn't work when cross-compiling, so use the `llvm-strip` utility instead. cc #123151
| -rw-r--r-- | compiler/rustc_codegen_ssa/messages.ftl | 2 | ||||
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/link.rs | 22 | ||||
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/errors.rs | 4 | ||||
| -rw-r--r-- | src/bootstrap/src/core/build_steps/compile.rs | 11 | ||||
| -rw-r--r-- | src/bootstrap/src/core/build_steps/dist.rs | 14 | ||||
| -rw-r--r-- | src/bootstrap/src/core/builder/mod.rs | 5 |
6 files changed, 47 insertions, 11 deletions
diff --git a/compiler/rustc_codegen_ssa/messages.ftl b/compiler/rustc_codegen_ssa/messages.ftl index 719ea0b5ba4..62db3d5a98c 100644 --- a/compiler/rustc_codegen_ssa/messages.ftl +++ b/compiler/rustc_codegen_ssa/messages.ftl @@ -2,6 +2,8 @@ codegen_ssa_L4Bender_exporting_symbols_unimplemented = exporting symbols not imp codegen_ssa_add_native_library = failed to add native library {$library_path}: {$error} +codegen_ssa_aix_strip_not_used = using host's `strip` binary to cross-compile to AIX which is not guaranteed to work + codegen_ssa_apple_deployment_target_invalid = failed to parse deployment target specified in {$env_var}: {$error} diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 39ff00baf6d..44581cfa64b 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -1085,9 +1085,7 @@ fn link_natively( let strip = sess.opts.cg.strip; if sess.target.is_like_osx { - // Use system `strip` when running on host macOS. - // <https://github.com/rust-lang/rust/pull/130781> - let stripcmd = if cfg!(target_os = "macos") { "/usr/bin/strip" } else { "strip" }; + let stripcmd = "rust-objcopy"; match (strip, crate_type) { (Strip::Debuginfo, _) => { strip_symbols_with_external_utility(sess, stripcmd, out_filename, Some("-S")) @@ -1103,11 +1101,14 @@ fn link_natively( } } - if sess.target.os == "illumos" { + if sess.target.is_like_solaris { // Many illumos systems will have both the native 'strip' utility and // the GNU one. Use the native version explicitly and do not rely on // what's in the path. - let stripcmd = "/usr/bin/strip"; + // + // If cross-compiling and there is not a native version, then use + // `llvm-strip` and hope. + let stripcmd = if !sess.host.is_like_solaris { "rust-objcopy" } else { "/usr/bin/strip" }; match strip { // Always preserve the symbol table (-x). Strip::Debuginfo => { @@ -1120,6 +1121,10 @@ fn link_natively( } if sess.target.is_like_aix { + // `llvm-strip` doesn't work for AIX - their strip must be used. + if !sess.host.is_like_aix { + sess.dcx().emit_warn(errors::AixStripNotUsed); + } let stripcmd = "/usr/bin/strip"; match strip { Strip::Debuginfo => { @@ -1147,6 +1152,13 @@ fn strip_symbols_with_external_utility( if let Some(option) = option { cmd.arg(option); } + + let mut new_path = sess.get_tools_search_paths(false); + if let Some(path) = env::var_os("PATH") { + new_path.extend(env::split_paths(&path)); + } + cmd.env("PATH", env::join_paths(new_path).unwrap()); + let prog = cmd.arg(out_filename).output(); match prog { Ok(prog) => { diff --git a/compiler/rustc_codegen_ssa/src/errors.rs b/compiler/rustc_codegen_ssa/src/errors.rs index a22a58ef3d7..f93cb52ea3e 100644 --- a/compiler/rustc_codegen_ssa/src/errors.rs +++ b/compiler/rustc_codegen_ssa/src/errors.rs @@ -1110,3 +1110,7 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for TargetFeatureDisableOrEnable<'_ diag } } + +#[derive(Diagnostic)] +#[diag(codegen_ssa_aix_strip_not_used)] +pub(crate) struct AixStripNotUsed; diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index 9ddcde7eb2c..3394f2a84a0 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -219,8 +219,7 @@ impl Step for Std { .join(compiler.host) .join("bin"); if src_sysroot_bin.exists() { - let target_sysroot_bin = - builder.sysroot_target_libdir(compiler, target).parent().unwrap().join("bin"); + let target_sysroot_bin = builder.sysroot_target_bindir(compiler, target); t!(fs::create_dir_all(&target_sysroot_bin)); builder.cp_link_r(&src_sysroot_bin, &target_sysroot_bin); } @@ -1977,6 +1976,14 @@ impl Step for Assemble { } } + { + // `llvm-strip` is used by rustc, which is actually just a symlink to `llvm-objcopy`, + // so copy and rename `llvm-objcopy`. + let src_exe = exe("llvm-objcopy", target_compiler.host); + let dst_exe = exe("rust-objcopy", target_compiler.host); + builder.copy_link(&libdir_bin.join(src_exe), &libdir_bin.join(dst_exe)); + } + // In addition to `rust-lld` also install `wasm-component-ld` when // LLD is enabled. This is a relatively small binary that primarily // delegates to the `rust-lld` binary for linking and then runs diff --git a/src/bootstrap/src/core/build_steps/dist.rs b/src/bootstrap/src/core/build_steps/dist.rs index 759e720c208..c022285211f 100644 --- a/src/bootstrap/src/core/build_steps/dist.rs +++ b/src/bootstrap/src/core/build_steps/dist.rs @@ -459,8 +459,7 @@ impl Step for Rustc { // Copy over lld if it's there if builder.config.lld_enabled { - let src_dir = - builder.sysroot_target_libdir(compiler, host).parent().unwrap().join("bin"); + let src_dir = builder.sysroot_target_bindir(compiler, host); let rust_lld = exe("rust-lld", compiler.host); builder.copy_link(&src_dir.join(&rust_lld), &dst_dir.join(&rust_lld)); let self_contained_lld_src_dir = src_dir.join("gcc-ld"); @@ -474,9 +473,16 @@ impl Step for Rustc { ); } } + + { + let src_dir = builder.sysroot_target_bindir(compiler, host); + let llvm_objcopy = exe("llvm-objcopy", compiler.host); + let rust_objcopy = exe("rust-objcopy", compiler.host); + builder.copy_link(&src_dir.join(&llvm_objcopy), &dst_dir.join(&rust_objcopy)); + } + if builder.tool_enabled("wasm-component-ld") { - let src_dir = - builder.sysroot_target_libdir(compiler, host).parent().unwrap().join("bin"); + let src_dir = builder.sysroot_target_bindir(compiler, host); let ld = exe("wasm-component-ld", compiler.host); builder.copy_link(&src_dir.join(&ld), &dst_dir.join(&ld)); } diff --git a/src/bootstrap/src/core/builder/mod.rs b/src/bootstrap/src/core/builder/mod.rs index 19472bac4af..f1b3cf6da13 100644 --- a/src/bootstrap/src/core/builder/mod.rs +++ b/src/bootstrap/src/core/builder/mod.rs @@ -1161,6 +1161,11 @@ impl<'a> Builder<'a> { self.ensure(compile::Sysroot::new(compiler)) } + /// Returns the bindir for a compiler's sysroot. + pub fn sysroot_target_bindir(&self, compiler: Compiler, target: TargetSelection) -> PathBuf { + self.sysroot_target_libdir(compiler, target).parent().unwrap().join("bin") + } + /// Returns the libdir where the standard library and other artifacts are /// found for a compiler's sysroot. pub fn sysroot_target_libdir(&self, compiler: Compiler, target: TargetSelection) -> PathBuf { |
