Skip to content

allow overriding frame pointer defaults #441

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
Sep 13, 2019
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
31 changes: 31 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ pub struct Build {
out_dir: Option<PathBuf>,
opt_level: Option<String>,
debug: Option<bool>,
force_frame_pointer: Option<bool>,
env: Vec<(OsString, OsString)>,
compiler: Option<PathBuf>,
archiver: Option<PathBuf>,
Expand Down Expand Up @@ -209,8 +210,17 @@ impl ToolFamily {
}
ToolFamily::Gnu | ToolFamily::Clang => {
cmd.push_cc_arg("-g".into());
}
}
}

/// What the flag to force frame pointers.
fn add_force_frame_pointer(&self, cmd: &mut Tool) {
match *self {
ToolFamily::Gnu | ToolFamily::Clang => {
cmd.push_cc_arg("-fno-omit-frame-pointer".into());
}
_ => (),
}
}

Expand Down Expand Up @@ -286,6 +296,7 @@ impl Build {
out_dir: None,
opt_level: None,
debug: None,
force_frame_pointer: None,
env: Vec::new(),
compiler: None,
archiver: None,
Expand Down Expand Up @@ -758,6 +769,17 @@ impl Build {
self
}

/// Configures whether the compiler will emit instructions to store
/// frame pointers during codegen.
///
/// This option is automatically enabled when debug information is emitted.
/// Otherwise the target platform compiler's default will be used.
/// You can use this option to force a specific setting.
pub fn force_frame_pointer(&mut self, force: bool) -> &mut Build {
self.force_frame_pointer = Some(force);
self
}

/// Configures the output directory where all object files and static
/// libraries will be located.
///
Expand Down Expand Up @@ -1348,6 +1370,11 @@ impl Build {
family.add_debug_flags(cmd);
}

if self.get_force_frame_pointer() {
let family = cmd.family;
family.add_force_frame_pointer(cmd);
}

// Target flags
match cmd.family {
ToolFamily::Clang => {
Expand Down Expand Up @@ -2227,6 +2254,10 @@ impl Build {
})
}

fn get_force_frame_pointer(&self) -> bool {
self.force_frame_pointer.unwrap_or_else(|| self.get_debug())
}

fn get_out_dir(&self) -> Result<PathBuf, Error> {
match self.out_dir.clone() {
Some(p) => Ok(p),
Expand Down
32 changes: 31 additions & 1 deletion tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,40 @@ fn gnu_opt_level_s() {
}

#[test]
fn gnu_debug() {
fn gnu_debug_fp_auto() {
let test = Test::gnu();
test.gcc().debug(true).file("foo.c").compile("foo");
test.cmd(0).must_have("-g");
test.cmd(0).must_have("-fno-omit-frame-pointer");
}

#[test]
fn gnu_debug_fp() {
let test = Test::gnu();
test.gcc().debug(true).file("foo.c").compile("foo");
test.cmd(0).must_have("-g");
test.cmd(0).must_have("-fno-omit-frame-pointer");
}

#[test]
fn gnu_debug_nofp() {
let test = Test::gnu();
test.gcc()
.debug(true)
.force_frame_pointer(false)
.file("foo.c")
.compile("foo");
test.cmd(0).must_have("-g");
test.cmd(0).must_not_have("-fno-omit-frame-pointer");

let test = Test::gnu();
test.gcc()
.force_frame_pointer(false)
.debug(true)
.file("foo.c")
.compile("foo");
test.cmd(0).must_have("-g");
test.cmd(0).must_not_have("-fno-omit-frame-pointer");
}

#[test]
Expand Down