Skip to content

Commit 451cf7c

Browse files
authored
Rollup merge of rust-lang#49904 - michaelwoerister:no-debug-attr, r=alexcrichton
Work around LLVM debuginfo problem in librustc_driver. Works around a problem (rust-lang#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 28bf5a3 + f1610ae commit 451cf7c

File tree

5 files changed

+28
-10
lines changed

5 files changed

+28
-10
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

+11-7
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,16 @@ 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") {
215-
return FunctionDebugContext::FunctionWithoutDebugInfo;
216-
}
214+
let def_id = if let InstanceDef::Item(def_id) = instance.def {
215+
def_id
216+
} else {
217+
return FunctionDebugContext::FunctionWithoutDebugInfo;
218+
};
219+
220+
if cx.tcx.trans_fn_attrs(def_id).flags.contains(TransFnAttrFlags::NO_DEBUG) {
221+
return FunctionDebugContext::FunctionWithoutDebugInfo;
217222
}
218223

219-
let containing_scope = get_containing_scope(cx, instance);
220224
let span = mir.span;
221225

222226
// This can be the case for functions inlined from another crate
@@ -225,7 +229,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
225229
return FunctionDebugContext::FunctionWithoutDebugInfo;
226230
}
227231

228-
let def_id = instance.def_id();
232+
let containing_scope = get_containing_scope(cx, instance);
229233
let loc = span_start(cx, span);
230234
let file_metadata = file_metadata(cx, &loc.file.name, def_id.krate);
231235

src/librustc_typeck/collect.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1790,6 +1790,8 @@ fn trans_fn_attrs<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: DefId) -> TransFnAt
17901790
trans_fn_attrs.flags |= TransFnAttrFlags::NO_MANGLE;
17911791
} else if attr.check_name("rustc_std_internal_symbol") {
17921792
trans_fn_attrs.flags |= TransFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL;
1793+
} else if attr.check_name("no_debug") {
1794+
trans_fn_attrs.flags |= TransFnAttrFlags::NO_DEBUG;
17931795
} else if attr.check_name("inline") {
17941796
trans_fn_attrs.inline = attrs.iter().fold(InlineAttr::None, |ia, attr| {
17951797
if attr.path != "inline" {

0 commit comments

Comments
 (0)