about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-05-01 04:43:28 +0000
committerbors <bors@rust-lang.org>2020-05-01 04:43:28 +0000
commitbd0bacc694d7d8175804bb6f690cb846bfa4a9ee (patch)
tree00ae7009ee2783df2617735b566351860148b2d2 /src
parente94eaa6dce468928b4e1326b2f0054f3075681ff (diff)
parent1686f5c68cc4503e5d2cbd22289302877aefb96c (diff)
downloadrust-bd0bacc694d7d8175804bb6f690cb846bfa4a9ee.tar.gz
rust-bd0bacc694d7d8175804bb6f690cb846bfa4a9ee.zip
Auto merge of #71623 - petrochenkov:localink, r=estebank
Disable localization for all linkers

We previously disabled non-English output from `link.exe` due to encoding issues (#35785).

In https://github.com/rust-lang/rust/pull/70740 it was pointed out that it also prevents correct inspection of the linker output, which we have to do occasionally.

So this PR disables localization for all linkers.
Diffstat (limited to 'src')
-rw-r--r--src/librustc_codegen_ssa/back/link.rs4
-rw-r--r--src/librustc_codegen_ssa/back/linker.rs13
-rw-r--r--src/librustc_target/spec/msvc_base.rs4
3 files changed, 16 insertions, 5 deletions
diff --git a/src/librustc_codegen_ssa/back/link.rs b/src/librustc_codegen_ssa/back/link.rs
index 9f85105a266..12cd58924ae 100644
--- a/src/librustc_codegen_ssa/back/link.rs
+++ b/src/librustc_codegen_ssa/back/link.rs
@@ -16,7 +16,7 @@ use rustc_target::spec::{LinkerFlavor, LldFlavor, PanicStrategy, RelocModel, Rel
 
 use super::archive::ArchiveBuilder;
 use super::command::Command;
-use super::linker::Linker;
+use super::linker::{self, Linker};
 use super::rpath::{self, RPathConfig};
 use crate::{looks_like_rust_object_file, CodegenResults, CrateInfo, METADATA_FILENAME};
 
@@ -480,6 +480,8 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
         target_cpu,
     );
 
+    linker::disable_localization(&mut cmd);
+
     for &(ref k, ref v) in &sess.target.target.options.link_env {
         cmd.env(k, v);
     }
diff --git a/src/librustc_codegen_ssa/back/linker.rs b/src/librustc_codegen_ssa/back/linker.rs
index 5a911fcdc7d..7c89fdfbe1b 100644
--- a/src/librustc_codegen_ssa/back/linker.rs
+++ b/src/librustc_codegen_ssa/back/linker.rs
@@ -19,6 +19,19 @@ use rustc_session::Session;
 use rustc_span::symbol::Symbol;
 use rustc_target::spec::{LinkerFlavor, LldFlavor};
 
+/// Disables non-English messages from localized linkers.
+/// Such messages may cause issues with text encoding on Windows (#35785)
+/// and prevent inspection of linker output in case of errors, which we occasionally do.
+/// This should be acceptable because other messages from rustc are in English anyway,
+/// and may also be desirable to improve searchability of the linker diagnostics.
+pub fn disable_localization(linker: &mut Command) {
+    // No harm in setting both env vars simultaneously.
+    // Unix-style linkers.
+    linker.env("LC_ALL", "C");
+    // MSVC's `link.exe`.
+    linker.env("VSLANG", "1033");
+}
+
 /// For all the linkers we support, and information they might
 /// need out of the shared crate context before we get rid of it.
 #[derive(RustcEncodable, RustcDecodable)]
diff --git a/src/librustc_target/spec/msvc_base.rs b/src/librustc_target/spec/msvc_base.rs
index 817a322a9e4..f57ef87cf12 100644
--- a/src/librustc_target/spec/msvc_base.rs
+++ b/src/librustc_target/spec/msvc_base.rs
@@ -21,10 +21,6 @@ pub fn opts() -> TargetOptions {
         executables: true,
         is_like_windows: true,
         is_like_msvc: true,
-        // set VSLANG to 1033 can prevent link.exe from using
-        // language packs, and avoid generating Non-UTF-8 error
-        // messages if a link error occurred.
-        link_env: vec![("VSLANG".to_string(), "1033".to_string())],
         lld_flavor: LldFlavor::Link,
         pre_link_args,
         abi_return_struct_as_int: true,