@@ -13,6 +13,7 @@ use rustc_middle::ty::query::Providers;
1313use rustc_middle:: ty:: { self , TyCtxt } ;
1414use rustc_session:: config:: { OptLevel , SanitizerSet } ;
1515use rustc_session:: Session ;
16+ use rustc_target:: spec:: StackProbeType ;
1617
1718use crate :: attributes;
1819use crate :: llvm:: AttributePlace :: Function ;
@@ -98,12 +99,6 @@ fn set_instrument_function(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
9899}
99100
100101fn 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-
107102 // Currently stack probes seem somewhat incompatible with the address
108103 // sanitizer and thread sanitizer. With asan we're already protected from
109104 // 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) {
127122 return ;
128123 }
129124
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+ }
143150}
144151
145152pub fn llvm_target_features ( sess : & Session ) -> impl Iterator < Item = & str > {
0 commit comments