@@ -12,7 +12,7 @@ use rustc_middle::ty::{self, TyCtxt};
12
12
use rustc_session:: config:: OptLevel ;
13
13
use rustc_session:: Session ;
14
14
use rustc_target:: spec:: abi:: Abi ;
15
- use rustc_target:: spec:: { SanitizerSet , StackProbeType } ;
15
+ use rustc_target:: spec:: { FramePointer , SanitizerSet , StackProbeType } ;
16
16
17
17
use crate :: attributes;
18
18
use crate :: llvm:: AttributePlace :: Function ;
@@ -69,15 +69,25 @@ fn naked(val: &'ll Value, is_naked: bool) {
69
69
Attribute :: Naked . toggle_llfn ( Function , val, is_naked) ;
70
70
}
71
71
72
- pub fn set_frame_pointer_elimination ( cx : & CodegenCx < ' ll , ' _ > , llfn : & ' ll Value ) {
73
- if cx. sess ( ) . must_not_eliminate_frame_pointers ( ) {
74
- llvm:: AddFunctionAttrStringValue (
75
- llfn,
76
- llvm:: AttributePlace :: Function ,
77
- cstr ! ( "frame-pointer" ) ,
78
- cstr ! ( "all" ) ,
79
- ) ;
72
+ pub fn set_frame_pointer_type ( cx : & CodegenCx < ' ll , ' _ > , llfn : & ' ll Value ) {
73
+ let mut fp = cx. sess ( ) . target . frame_pointer ;
74
+ // "mcount" function relies on stack pointer.
75
+ // See <https://sourceware.org/binutils/docs/gprof/Implementation.html>.
76
+ if cx. sess ( ) . instrument_mcount ( ) || matches ! ( cx. sess( ) . opts. cg. force_frame_pointers, Some ( true ) )
77
+ {
78
+ fp = FramePointer :: Always ;
80
79
}
80
+ let attr_value = match fp {
81
+ FramePointer :: Always => cstr ! ( "all" ) ,
82
+ FramePointer :: NonLeaf => cstr ! ( "non-leaf" ) ,
83
+ FramePointer :: MayOmit => return ,
84
+ } ;
85
+ llvm:: AddFunctionAttrStringValue (
86
+ llfn,
87
+ llvm:: AttributePlace :: Function ,
88
+ cstr ! ( "frame-pointer" ) ,
89
+ attr_value,
90
+ ) ;
81
91
}
82
92
83
93
/// Tell LLVM what instrument function to insert.
@@ -254,7 +264,7 @@ pub fn from_fn_attrs(cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value, instance: ty::
254
264
}
255
265
256
266
// FIXME: none of these three functions interact with source level attributes.
257
- set_frame_pointer_elimination ( cx, llfn) ;
267
+ set_frame_pointer_type ( cx, llfn) ;
258
268
set_instrument_function ( cx, llfn) ;
259
269
set_probestack ( cx, llfn) ;
260
270
0 commit comments