Skip to content

Commit 786e305

Browse files
committed
Auto merge of #49904 - michaelwoerister:no-debug-attr, r=alexcrichton
Work around LLVM debuginfo problem in librustc_driver. Works around a problem (#48910) with global variable debuginfo generation for `rustc_driver::get_trans::LOAD` by applying `#[no_debug]` to it (which just disables debuginfo generation for that variable). This way we can build the compiler with debuginfo again. Since the problem is also present in beta, this workaround might have to be backported. r? @alexcrichton
2 parents 9379bcd + 2814928 commit 786e305

File tree

5 files changed

+22
-7
lines changed

5 files changed

+22
-7
lines changed

src/librustc/hir/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2277,6 +2277,7 @@ bitflags! {
22772277
const NAKED = 0b0001_0000;
22782278
const NO_MANGLE = 0b0010_0000;
22792279
const RUSTC_STD_INTERNAL_SYMBOL = 0b0100_0000;
2280+
const NO_DEBUG = 0b1000_0000;
22802281
}
22812282
}
22822283

src/librustc_driver/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#![feature(slice_sort_by_cached_key)]
2626
#![feature(set_stdio)]
2727
#![feature(rustc_stack_internals)]
28+
#![feature(no_debug)]
2829

2930
extern crate arena;
3031
extern crate getopts;
@@ -230,6 +231,9 @@ fn load_backend_from_dylib(path: &Path) -> fn() -> Box<TransCrate> {
230231

231232
pub fn get_trans(sess: &Session) -> Box<TransCrate> {
232233
static INIT: Once = ONCE_INIT;
234+
235+
#[allow(deprecated)]
236+
#[no_debug]
233237
static mut LOAD: fn() -> Box<TransCrate> = || unreachable!();
234238

235239
INIT.call_once(|| {

src/librustc_trans/debuginfo/metadata.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use llvm::{self, ValueRef};
2323
use llvm::debuginfo::{DIType, DIFile, DIScope, DIDescriptor,
2424
DICompositeType, DILexicalBlock, DIFlags};
2525

26+
use rustc::hir::TransFnAttrFlags;
2627
use rustc::hir::def::CtorKind;
2728
use rustc::hir::def_id::{DefId, CrateNum, LOCAL_CRATE};
2829
use rustc::ty::fold::TypeVisitor;
@@ -41,7 +42,7 @@ use std::ffi::CString;
4142
use std::fmt::Write;
4243
use std::ptr;
4344
use std::path::{Path, PathBuf};
44-
use syntax::{ast, attr};
45+
use syntax::ast;
4546
use syntax::symbol::{Interner, InternedString, Symbol};
4647
use syntax_pos::{self, Span, FileName};
4748

@@ -1644,11 +1645,17 @@ pub fn create_global_var_metadata(cx: &CodegenCx,
16441645
}
16451646

16461647
let tcx = cx.tcx;
1647-
let no_mangle = attr::contains_name(&tcx.get_attrs(def_id), "no_mangle");
1648+
let attrs = tcx.trans_fn_attrs(def_id);
1649+
1650+
if attrs.flags.contains(TransFnAttrFlags::NO_DEBUG) {
1651+
return;
1652+
}
1653+
1654+
let no_mangle = attrs.flags.contains(TransFnAttrFlags::NO_MANGLE);
16481655
// We may want to remove the namespace scope if we're in an extern block, see:
16491656
// https://github.com/rust-lang/rust/pull/46457#issuecomment-351750952
16501657
let var_scope = get_namespace_for_item(cx, def_id);
1651-
let span = cx.tcx.def_span(def_id);
1658+
let span = tcx.def_span(def_id);
16521659

16531660
let (file_metadata, line_number) = if span != syntax_pos::DUMMY_SP {
16541661
let loc = span_start(cx, span);

src/librustc_trans/debuginfo/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ use self::source_loc::InternalDebugLocation::{self, UnknownLocation};
2323
use llvm;
2424
use llvm::{ModuleRef, ContextRef, ValueRef};
2525
use llvm::debuginfo::{DIFile, DIType, DIScope, DIBuilderRef, DISubprogram, DIArray, DIFlags};
26+
use rustc::hir::TransFnAttrFlags;
2627
use rustc::hir::def_id::{DefId, CrateNum};
2728
use rustc::ty::subst::Substs;
2829

2930
use abi::Abi;
3031
use common::CodegenCx;
3132
use builder::Builder;
3233
use monomorphize::Instance;
33-
use rustc::ty::{self, ParamEnv, Ty};
34+
use rustc::ty::{self, ParamEnv, Ty, InstanceDef};
3435
use rustc::mir;
3536
use rustc::session::config::{self, FullDebugInfo, LimitedDebugInfo, NoDebugInfo};
3637
use rustc::util::nodemap::{DefIdMap, FxHashMap, FxHashSet};
@@ -210,13 +211,12 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
210211
return FunctionDebugContext::DebugInfoDisabled;
211212
}
212213

213-
for attr in instance.def.attrs(cx.tcx).iter() {
214-
if attr.check_name("no_debug") {
214+
if let InstanceDef::Item(def_id) = instance.def {
215+
if cx.tcx.trans_fn_attrs(def_id).flags.contains(TransFnAttrFlags::NO_DEBUG) {
215216
return FunctionDebugContext::FunctionWithoutDebugInfo;
216217
}
217218
}
218219

219-
let containing_scope = get_containing_scope(cx, instance);
220220
let span = mir.span;
221221

222222
// This can be the case for functions inlined from another crate
@@ -226,6 +226,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
226226
}
227227

228228
let def_id = instance.def_id();
229+
let containing_scope = get_containing_scope(cx, instance);
229230
let loc = span_start(cx, span);
230231
let file_metadata = file_metadata(cx, &loc.file.name, def_id.krate);
231232

src/librustc_typeck/collect.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1825,6 +1825,8 @@ fn trans_fn_attrs<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: DefId) -> TransFnAt
18251825
trans_fn_attrs.flags |= TransFnAttrFlags::NO_MANGLE;
18261826
} else if attr.check_name("rustc_std_internal_symbol") {
18271827
trans_fn_attrs.flags |= TransFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL;
1828+
} else if attr.check_name("no_debug") {
1829+
trans_fn_attrs.flags |= TransFnAttrFlags::NO_DEBUG;
18281830
} else if attr.check_name("inline") {
18291831
trans_fn_attrs.inline = attrs.iter().fold(InlineAttr::None, |ia, attr| {
18301832
if attr.path != "inline" {

0 commit comments

Comments
 (0)