@@ -13,6 +13,7 @@ use rustc_middle::ty::query::Providers;
13
13
use rustc_middle:: ty:: { self , TyCtxt } ;
14
14
use rustc_session:: config:: { OptLevel , SanitizerSet } ;
15
15
use rustc_session:: Session ;
16
+ use rustc_target:: spec:: StackProbeType ;
16
17
17
18
use crate :: attributes;
18
19
use crate :: llvm:: AttributePlace :: Function ;
@@ -98,12 +99,6 @@ fn set_instrument_function(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
98
99
}
99
100
100
101
fn set_probestack ( cx : & CodegenCx < ' ll , ' _ > , llfn : & ' ll Value ) {
101
- // Only use stack probes if the target specification indicates that we
102
- // should be using stack probes
103
- if !cx. sess ( ) . target . stack_probes {
104
- return ;
105
- }
106
-
107
102
// Currently stack probes seem somewhat incompatible with the address
108
103
// sanitizer and thread sanitizer. With asan we're already protected from
109
104
// stack overflow anyway so we don't really need stack probes regardless.
@@ -127,19 +122,31 @@ fn set_probestack(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
127
122
return ;
128
123
}
129
124
130
- llvm:: AddFunctionAttrStringValue (
131
- llfn,
132
- llvm:: AttributePlace :: Function ,
133
- const_cstr ! ( "probe-stack" ) ,
134
- if llvm_util:: get_version ( ) < ( 11 , 0 , 1 ) {
135
- // Flag our internal `__rust_probestack` function as the stack probe symbol.
136
- // This is defined in the `compiler-builtins` crate for each architecture.
137
- const_cstr ! ( "__rust_probestack" )
138
- } else {
139
- // On LLVM 11+, emit inline asm for stack probes instead of a function call.
140
- const_cstr ! ( "inline-asm" )
141
- } ,
142
- ) ;
125
+ let attr_value = match cx. sess ( ) . target . stack_probes {
126
+ StackProbeType :: None => None ,
127
+ // Request LLVM to generate the probes inline. If the given LLVM version does not support
128
+ // this, no probe is generated at all (even if the attribute is specified).
129
+ StackProbeType :: Inline => Some ( const_cstr ! ( "inline-asm" ) ) ,
130
+ // Flag our internal `__rust_probestack` function as the stack probe symbol.
131
+ // This is defined in the `compiler-builtins` crate for each architecture.
132
+ StackProbeType :: Call => Some ( const_cstr ! ( "__rust_probestack" ) ) ,
133
+ // Pick from the two above based on the LLVM version.
134
+ StackProbeType :: InlineOrCall { min_llvm_version_for_inline } => {
135
+ if llvm_util:: get_version ( ) < min_llvm_version_for_inline {
136
+ Some ( const_cstr ! ( "__rust_probestack" ) )
137
+ } else {
138
+ Some ( const_cstr ! ( "inline-asm" ) )
139
+ }
140
+ }
141
+ } ;
142
+ if let Some ( attr_value) = attr_value {
143
+ llvm:: AddFunctionAttrStringValue (
144
+ llfn,
145
+ llvm:: AttributePlace :: Function ,
146
+ const_cstr ! ( "probe-stack" ) ,
147
+ attr_value,
148
+ ) ;
149
+ }
143
150
}
144
151
145
152
pub fn llvm_target_features ( sess : & Session ) -> impl Iterator < Item = & str > {
0 commit comments