Skip to content

Commit b3d10f4

Browse files
committed
auto merge of #11864 : comex/rust/11352, r=alexcrichton
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.
2 parents a39be7c + ea7b20d commit b3d10f4

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

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

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)