Skip to content

Commit

Permalink
Add appropriate LLVM module flags for debug info.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
comex committed Jan 28, 2014
1 parent 760ddb3 commit ea7b20d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/librustc/lib/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1493,6 +1493,11 @@ pub mod llvm {
Dialect: c_uint)
-> ValueRef;

pub static LLVMRustDebugMetadataVersion: u32;

pub fn LLVMRustAddModuleFlag(M: ModuleRef,
name: *c_char,
value: u32);

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

Expand Down
16 changes: 15 additions & 1 deletion src/librustc/middle/trans/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ use std::ptr;
use std::sync::atomics;
use std::vec;
use syntax::codemap::{Span, Pos};
use syntax::{ast, codemap, ast_util, ast_map, opt_vec};
use syntax::{abi, ast, codemap, ast_util, ast_map, opt_vec};
use syntax::parse::token;
use syntax::parse::token::special_idents;

Expand Down Expand Up @@ -263,6 +263,20 @@ pub fn finalize(cx: @CrateContext) {
unsafe {
llvm::LLVMDIBuilderFinalize(DIB(cx));
llvm::LLVMDIBuilderDispose(DIB(cx));
// Debuginfo generation in LLVM by default uses a higher
// version of dwarf than OS X currently understands. We can
// instruct LLVM to emit an older version of dwarf, however,
// for OS X to understand. For more info see #11352
// This can be overridden using --llvm-opts -dwarf-version,N.
if cx.sess.targ_cfg.os == abi::OsMacos {
"Dwarf Version".with_c_str(
|s| llvm::LLVMRustAddModuleFlag(cx.llmod, s, 2));
}

// Prevent bitcode readers from deleting the debug info.
"Debug Info Version".with_c_str(
|s| llvm::LLVMRustAddModuleFlag(cx.llmod, s,
llvm::LLVMRustDebugMetadataVersion));
};
}

Expand Down
8 changes: 8 additions & 0 deletions src/rustllvm/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ DIT unwrapDI(LLVMValueRef ref) {
return DIT(ref ? unwrap<MDNode>(ref) : NULL);
}

extern "C" const uint32_t LLVMRustDebugMetadataVersion = DEBUG_METADATA_VERSION;

extern "C" void LLVMRustAddModuleFlag(LLVMModuleRef M,
const char *name,
uint32_t value) {
unwrap(M)->addModuleFlag(Module::Warning, name, value);
}

extern "C" DIBuilderRef LLVMDIBuilderCreate(LLVMModuleRef M) {
return new DIBuilder(*unwrap(M));
}
Expand Down

5 comments on commit ea7b20d

@bors
Copy link
Contributor

@bors bors commented on ea7b20d Jan 28, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at comex@ea7b20d

@bors
Copy link
Contributor

@bors bors commented on ea7b20d Jan 28, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging comex/rust/11352 = ea7b20d into auto

@bors
Copy link
Contributor

@bors bors commented on ea7b20d Jan 28, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comex/rust/11352 = ea7b20d merged ok, testing candidate = b3d10f4

@bors
Copy link
Contributor

@bors bors commented on ea7b20d Jan 28, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on ea7b20d Jan 28, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = b3d10f4

Please sign in to comment.