|
11 | 11 |
|
12 | 12 | use std::ffi::{CStr, CString};
|
13 | 13 |
|
| 14 | +use rustc::session::config::Sanitizer; |
| 15 | + |
14 | 16 | use llvm::{self, Attribute, ValueRef};
|
15 | 17 | use llvm::AttributePlace::Function;
|
16 | 18 | pub use syntax::attr::{self, InlineAttr};
|
17 | 19 | use syntax::ast;
|
18 | 20 | use context::CrateContext;
|
19 | 21 |
|
20 |
| - |
21 | 22 | /// Mark LLVM function to use provided inline heuristic.
|
22 | 23 | #[inline]
|
23 | 24 | pub fn inline(val: ValueRef, inline: InlineAttr) {
|
@@ -69,13 +70,36 @@ pub fn set_frame_pointer_elimination(ccx: &CrateContext, llfn: ValueRef) {
|
69 | 70 | }
|
70 | 71 | }
|
71 | 72 |
|
| 73 | +pub fn set_probestack(ccx: &CrateContext, llfn: ValueRef) { |
| 74 | + // Only use stack probes if the target specification indicates that we |
| 75 | + // should be using stack probes |
| 76 | + if !ccx.sess().target.target.options.stack_probes { |
| 77 | + return |
| 78 | + } |
| 79 | + |
| 80 | + // Currently stack probes seem somewhat incompatible with the address |
| 81 | + // sanitizer. With asan we're already protected from stack overflow anyway |
| 82 | + // so we don't really need stack probes regardless. |
| 83 | + match ccx.sess().opts.debugging_opts.sanitizer { |
| 84 | + Some(Sanitizer::Address) => return, |
| 85 | + _ => {} |
| 86 | + } |
| 87 | + |
| 88 | + // Flag our internal `__rust_probestack` function as the stack probe symbol. |
| 89 | + // This is defined in the `compiler-builtins` crate for each architecture. |
| 90 | + llvm::AddFunctionAttrStringValue( |
| 91 | + llfn, llvm::AttributePlace::Function, |
| 92 | + cstr("probe-stack\0"), cstr("__rust_probestack\0")); |
| 93 | +} |
| 94 | + |
72 | 95 | /// Composite function which sets LLVM attributes for function depending on its AST (#[attribute])
|
73 | 96 | /// attributes.
|
74 | 97 | pub fn from_fn_attrs(ccx: &CrateContext, attrs: &[ast::Attribute], llfn: ValueRef) {
|
75 | 98 | use syntax::attr::*;
|
76 | 99 | inline(llfn, find_inline_attr(Some(ccx.sess().diagnostic()), attrs));
|
77 | 100 |
|
78 | 101 | set_frame_pointer_elimination(ccx, llfn);
|
| 102 | + set_probestack(ccx, llfn); |
79 | 103 | let mut target_features = vec![];
|
80 | 104 | for attr in attrs {
|
81 | 105 | if attr.check_name("target_feature") {
|
|
0 commit comments