Skip to content

Commit

Permalink
Rollup merge of rust-lang#48786 - nagisa:fp, r=nikomatsakis
Browse files Browse the repository at this point in the history
Add force-frame-pointer flag to allow control of frame pointer ommision

Rebase of rust-lang#47152 plus some changes suggested by rust-lang#48785.

Fixes rust-lang#11906

r? @nikomatsakis
  • Loading branch information
kennytm authored Mar 21, 2018
2 parents dc1e7a5 + 7188f41 commit 0a75a74
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,8 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
2 = full debug info with variable and type information"),
opt_level: Option<String> = (None, parse_opt_string, [TRACKED],
"optimize with possible levels 0-3, s, or z"),
force_frame_pointers: Option<bool> = (None, parse_opt_bool, [TRACKED],
"force use of the frame pointers"),
debug_assertions: Option<bool> = (None, parse_opt_bool, [TRACKED],
"explicitly enable the cfg(debug_assertions) directive"),
inline_threshold: Option<usize> = (None, parse_opt_uint, [TRACKED],
Expand Down Expand Up @@ -2892,6 +2894,10 @@ mod tests {
opts.cg.debuginfo = Some(0xba5eba11);
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());

opts = reference.clone();
opts.cg.force_frame_pointers = Some(false);
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());

opts = reference.clone();
opts.cg.debug_assertions = Some(true);
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
Expand Down
9 changes: 6 additions & 3 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use lint::builtin::BuiltinLintDiagnostics;
use middle::allocator::AllocatorKind;
use middle::dependency_format;
use session::search_paths::PathKind;
use session::config::{DebugInfoLevel, OutputType};
use session::config::{OutputType};
use ty::tls;
use util::nodemap::{FxHashMap, FxHashSet};
use util::common::{duration_to_secs_str, ErrorReported};
Expand Down Expand Up @@ -676,8 +676,11 @@ impl Session {
}

pub fn must_not_eliminate_frame_pointers(&self) -> bool {
self.opts.debuginfo != DebugInfoLevel::NoDebugInfo
|| !self.target.target.options.eliminate_frame_pointer
if let Some(x) = self.opts.cg.force_frame_pointers {
x
} else {
!self.target.target.options.eliminate_frame_pointer
}
}

/// Returns the symbol name for the registrar function,
Expand Down
2 changes: 0 additions & 2 deletions src/librustc_trans/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ pub fn naked(val: ValueRef, is_naked: bool) {
}

pub fn set_frame_pointer_elimination(cx: &CodegenCx, llfn: ValueRef) {
// FIXME: #11906: Omitting frame pointers breaks retrieving the value of a
// parameter.
if cx.sess().must_not_eliminate_frame_pointers() {
llvm::AddFunctionAttrStringValue(
llfn, llvm::AttributePlace::Function,
Expand Down
16 changes: 16 additions & 0 deletions src/test/codegen/force-frame-pointers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//
// compile-flags: -C no-prepopulate-passes -C force-frame-pointers=y

#![crate_type="lib"]

// CHECK: attributes #{{.*}} "no-frame-pointer-elim"="true"
pub fn foo() {}

0 comments on commit 0a75a74

Please sign in to comment.