Skip to content

Commit bd0bacc

Browse files
committed
Auto merge of rust-lang#71623 - petrochenkov:localink, r=estebank
Disable localization for all linkers We previously disabled non-English output from `link.exe` due to encoding issues (rust-lang#35785). In rust-lang#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.
2 parents e94eaa6 + 1686f5c commit bd0bacc

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

src/librustc_codegen_ssa/back/link.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_target::spec::{LinkerFlavor, LldFlavor, PanicStrategy, RelocModel, Rel
1616

1717
use super::archive::ArchiveBuilder;
1818
use super::command::Command;
19-
use super::linker::Linker;
19+
use super::linker::{self, Linker};
2020
use super::rpath::{self, RPathConfig};
2121
use crate::{looks_like_rust_object_file, CodegenResults, CrateInfo, METADATA_FILENAME};
2222

@@ -480,6 +480,8 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
480480
target_cpu,
481481
);
482482

483+
linker::disable_localization(&mut cmd);
484+
483485
for &(ref k, ref v) in &sess.target.target.options.link_env {
484486
cmd.env(k, v);
485487
}

src/librustc_codegen_ssa/back/linker.rs

+13
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ use rustc_session::Session;
1919
use rustc_span::symbol::Symbol;
2020
use rustc_target::spec::{LinkerFlavor, LldFlavor};
2121

22+
/// Disables non-English messages from localized linkers.
23+
/// Such messages may cause issues with text encoding on Windows (#35785)
24+
/// and prevent inspection of linker output in case of errors, which we occasionally do.
25+
/// This should be acceptable because other messages from rustc are in English anyway,
26+
/// and may also be desirable to improve searchability of the linker diagnostics.
27+
pub fn disable_localization(linker: &mut Command) {
28+
// No harm in setting both env vars simultaneously.
29+
// Unix-style linkers.
30+
linker.env("LC_ALL", "C");
31+
// MSVC's `link.exe`.
32+
linker.env("VSLANG", "1033");
33+
}
34+
2235
/// For all the linkers we support, and information they might
2336
/// need out of the shared crate context before we get rid of it.
2437
#[derive(RustcEncodable, RustcDecodable)]

src/librustc_target/spec/msvc_base.rs

-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ pub fn opts() -> TargetOptions {
2121
executables: true,
2222
is_like_windows: true,
2323
is_like_msvc: true,
24-
// set VSLANG to 1033 can prevent link.exe from using
25-
// language packs, and avoid generating Non-UTF-8 error
26-
// messages if a link error occurred.
27-
link_env: vec![("VSLANG".to_string(), "1033".to_string())],
2824
lld_flavor: LldFlavor::Link,
2925
pre_link_args,
3026
abi_return_struct_as_int: true,

0 commit comments

Comments
 (0)