Skip to content

Commit ea7b20d

Browse files
committed
Add appropriate LLVM module flags for debug info.
Set "Dwarf Version" to 2 on OS X to avoid toolchain incompatibility, and set "Debug Info Version" to prevent debug info from being stripped from bitcode. Fixes #11352.
1 parent 760ddb3 commit ea7b20d

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

src/librustc/lib/llvm.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,11 @@ pub mod llvm {
14931493
Dialect: c_uint)
14941494
-> ValueRef;
14951495

1496+
pub static LLVMRustDebugMetadataVersion: u32;
1497+
1498+
pub fn LLVMRustAddModuleFlag(M: ModuleRef,
1499+
name: *c_char,
1500+
value: u32);
14961501

14971502
pub fn LLVMDIBuilderCreate(M: ModuleRef) -> DIBuilderRef;
14981503

src/librustc/middle/trans/debuginfo.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ use std::ptr;
149149
use std::sync::atomics;
150150
use std::vec;
151151
use syntax::codemap::{Span, Pos};
152-
use syntax::{ast, codemap, ast_util, ast_map, opt_vec};
152+
use syntax::{abi, ast, codemap, ast_util, ast_map, opt_vec};
153153
use syntax::parse::token;
154154
use syntax::parse::token::special_idents;
155155

@@ -263,6 +263,20 @@ pub fn finalize(cx: @CrateContext) {
263263
unsafe {
264264
llvm::LLVMDIBuilderFinalize(DIB(cx));
265265
llvm::LLVMDIBuilderDispose(DIB(cx));
266+
// Debuginfo generation in LLVM by default uses a higher
267+
// version of dwarf than OS X currently understands. We can
268+
// instruct LLVM to emit an older version of dwarf, however,
269+
// for OS X to understand. For more info see #11352
270+
// This can be overridden using --llvm-opts -dwarf-version,N.
271+
if cx.sess.targ_cfg.os == abi::OsMacos {
272+
"Dwarf Version".with_c_str(
273+
|s| llvm::LLVMRustAddModuleFlag(cx.llmod, s, 2));
274+
}
275+
276+
// Prevent bitcode readers from deleting the debug info.
277+
"Debug Info Version".with_c_str(
278+
|s| llvm::LLVMRustAddModuleFlag(cx.llmod, s,
279+
llvm::LLVMRustDebugMetadataVersion));
266280
};
267281
}
268282

src/rustllvm/RustWrapper.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@ DIT unwrapDI(LLVMValueRef ref) {
156156
return DIT(ref ? unwrap<MDNode>(ref) : NULL);
157157
}
158158

159+
extern "C" const uint32_t LLVMRustDebugMetadataVersion = DEBUG_METADATA_VERSION;
160+
161+
extern "C" void LLVMRustAddModuleFlag(LLVMModuleRef M,
162+
const char *name,
163+
uint32_t value) {
164+
unwrap(M)->addModuleFlag(Module::Warning, name, value);
165+
}
166+
159167
extern "C" DIBuilderRef LLVMDIBuilderCreate(LLVMModuleRef M) {
160168
return new DIBuilder(*unwrap(M));
161169
}

0 commit comments

Comments
 (0)