Skip to content

Commit

Permalink
Rollup merge of rust-lang#67748 - MaskRay:frame-pointer, r=rkruppe
Browse files Browse the repository at this point in the history
Use function attribute "frame-pointer" instead of "no-frame-pointer-elim"

LLVM 8 ([D56351](http://reviews.llvm.org/D56351)) introduced "frame-pointer". In LLVM 10 (D71863),
"no-frame-pointer-elim"/"no-frame-pointer-elim-non-leaf" will be
ignored.

-----

In the LLVM monorepo, run `git show origin/release/8.x:llvm/lib/CodeGen/TargetOptionsImpl.cpp` to see that `"frame-pointer"` is available since LLVM 8.
  • Loading branch information
Centril authored Dec 31, 2019
2 parents 3cca3c6 + b40dc30 commit 40579d1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
21 changes: 15 additions & 6 deletions src/librustc_codegen_llvm/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,21 @@ fn naked(val: &'ll Value, is_naked: bool) {

pub fn set_frame_pointer_elimination(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
if cx.sess().must_not_eliminate_frame_pointers() {
llvm::AddFunctionAttrStringValue(
llfn,
llvm::AttributePlace::Function,
const_cstr!("no-frame-pointer-elim"),
const_cstr!("true"),
);
if llvm_util::get_major_version() >= 8 {
llvm::AddFunctionAttrStringValue(
llfn,
llvm::AttributePlace::Function,
const_cstr!("frame-pointer"),
const_cstr!("all"),
);
} else {
llvm::AddFunctionAttrStringValue(
llfn,
llvm::AttributePlace::Function,
const_cstr!("no-frame-pointer-elim"),
const_cstr!("true"),
);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/codegen/force-frame-pointers.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// min-llvm-version 8.0
// compile-flags: -C no-prepopulate-passes -C force-frame-pointers=y

#![crate_type="lib"]

// CHECK: attributes #{{.*}} "no-frame-pointer-elim"="true"
// CHECK: attributes #{{.*}} "frame-pointer"="all"
pub fn foo() {}
3 changes: 2 additions & 1 deletion src/test/codegen/instrument-mcount.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// min-llvm-version 8.0
// ignore-tidy-linelength
// compile-flags: -Z instrument-mcount

#![crate_type = "lib"]

// CHECK: attributes #{{.*}} "instrument-function-entry-inlined"="{{.*}}mcount{{.*}}" "no-frame-pointer-elim"="true"
// CHECK: attributes #{{.*}} "frame-pointer"="all" "instrument-function-entry-inlined"="{{.*}}mcount{{.*}}"
pub fn foo() {}

0 comments on commit 40579d1

Please sign in to comment.