Skip to content

debuginfo: Instruct MSVC linker to generate PDB file if debuginfo is enabled #26993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/librustc_trans/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,9 @@ fn link_args(cmd: &mut Linker,
// Pass optimization flags down to the linker.
cmd.optimize();

// Pass debuginfo flags down to the linker.
cmd.debuginfo();

// We want to prevent the compiler from accidentally leaking in any system
// libraries, so we explicitly ask gcc to not link to any libraries by
// default. Note that this does not happen for windows because windows pulls
Expand Down
21 changes: 21 additions & 0 deletions src/librustc_trans/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::fs;
use back::archive;
use session::Session;
use session::config;
use session::config::DebugInfoLevel::{NoDebugInfo, LimitedDebugInfo, FullDebugInfo};

/// Linker abstraction used by back::link to build up the command to invoke a
/// linker.
Expand All @@ -39,6 +40,7 @@ pub trait Linker {
fn gc_sections(&mut self, is_dylib: bool);
fn position_independent_executable(&mut self);
fn optimize(&mut self);
fn debuginfo(&mut self);
fn no_default_libraries(&mut self);
fn build_dylib(&mut self, out_filename: &Path);
fn args(&mut self, args: &[String]);
Expand Down Expand Up @@ -143,6 +145,10 @@ impl<'a> Linker for GnuLinker<'a> {
}
}

fn debuginfo(&mut self) {
// Don't do anything special here for GNU-style linkers.
}

fn no_default_libraries(&mut self) {
// Unfortunately right now passing -nodefaultlibs to gcc on windows
// doesn't work so hot (in terms of native dependencies). This if
Expand Down Expand Up @@ -265,6 +271,21 @@ impl<'a> Linker for MsvcLinker<'a> {
fn optimize(&mut self) {
// Needs more investigation of `/OPT` arguments
}

fn debuginfo(&mut self) {
match self.sess.opts.debuginfo {
NoDebugInfo => {
// Do nothing if debuginfo is disabled
},
LimitedDebugInfo |
FullDebugInfo => {
// This will cause the Microsoft linker to generate a PDB file
// from the CodeView line tables in the object files.
self.cmd.arg("/DEBUG");
}
}
}

fn whole_archives(&mut self) {
// hints not supported?
}
Expand Down