Skip to content

Commit 64fa14e

Browse files
Rollup merge of rust-lang#44626 - MaulingMonkey:lld-link-natvis-regression-fix, r=michaelwoerister
Skip passing /natvis to lld-link until supported. ### Overview Teaching rustc about MSVC's undocumented linker flag, /NATVIS, broke rustc's compatability with LLVM's `lld-link` frontend, as it does not recognize the flag. This pull request works around the problem by excluding `lld-link` by name. @retep998 discovered this regression. ### Possible Issues - Other linkers that try to be compatible with the MSVC linker flavor may also be broken and in need of workarounds. - Warning about the workaround may be overkill for a minor reduction in debug functionality. - Depending on how long this workaround sticks around, it may eventually be preferred to version check `lld-link` instead of assuming all versions are incompatible. ### Relevant issues * Broke in rust-lang#43221 Embed MSVC .natvis files into .pdbs and mangle debuginfo for &str, *T, and [T]. * LLVM patched in llvm-mirror/lld@27b9c42 to ignore the flag instead of erroring. r? @michaelwoerister
2 parents 6e6a474 + 995f0bd commit 64fa14e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/librustc_trans/back/linker.rs

+12
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,18 @@ impl<'a> Linker for MsvcLinker<'a> {
496496
let sysroot = self.sess.sysroot();
497497
let natvis_dir_path = sysroot.join("lib\\rustlib\\etc");
498498
if let Ok(natvis_dir) = fs::read_dir(&natvis_dir_path) {
499+
// LLVM 5.0.0's lld-link frontend doesn't yet recognize, and chokes
500+
// on, the /NATVIS:... flags. LLVM 6 (or earlier) should at worst ignore
501+
// them, eventually mooting this workaround, per this landed patch:
502+
// https://github.com/llvm-mirror/lld/commit/27b9c4285364d8d76bb43839daa100
503+
if let Some(ref linker_path) = self.sess.opts.cg.linker {
504+
if let Some(linker_name) = Path::new(&linker_path).file_stem() {
505+
if linker_name.to_str().unwrap().to_lowercase() == "lld-link" {
506+
self.sess.warn("not embedding natvis: lld-link may not support the flag");
507+
return;
508+
}
509+
}
510+
}
499511
for entry in natvis_dir {
500512
match entry {
501513
Ok(entry) => {

0 commit comments

Comments
 (0)