Skip to content

Commit 0c10c68

Browse files
committed
Disable generating split-stack code
Allows to compile for archs which do not have (or have limited) segmented stack support like embedded.
1 parent d730ae2 commit 0c10c68

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

src/librustc/middle/trans/base.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,12 @@ impl<'a> Drop for StatRecorder<'a> {
172172
}
173173

174174
// only use this for foreign function ABIs and glue, use `decl_rust_fn` for Rust functions
175-
fn decl_fn(llmod: ModuleRef, name: &str, cc: lib::llvm::CallConv,
175+
fn decl_fn(ccx: &CrateContext, name: &str, cc: lib::llvm::CallConv,
176176
ty: Type, output: ty::t) -> ValueRef {
177177

178178
let llfn: ValueRef = name.with_c_str(|buf| {
179179
unsafe {
180-
llvm::LLVMGetOrInsertFunction(llmod, buf, ty.to_ref())
180+
llvm::LLVMGetOrInsertFunction(ccx.llmod, buf, ty.to_ref())
181181
}
182182
});
183183

@@ -196,17 +196,20 @@ fn decl_fn(llmod: ModuleRef, name: &str, cc: lib::llvm::CallConv,
196196
lib::llvm::SetFunctionCallConv(llfn, cc);
197197
// Function addresses in Rust are never significant, allowing functions to be merged.
198198
lib::llvm::SetUnnamedAddr(llfn, true);
199-
set_split_stack(llfn);
199+
200+
if ccx.is_split_stack_supported() {
201+
set_split_stack(llfn);
202+
}
200203

201204
llfn
202205
}
203206

204207
// only use this for foreign function ABIs and glue, use `decl_rust_fn` for Rust functions
205-
pub fn decl_cdecl_fn(llmod: ModuleRef,
208+
pub fn decl_cdecl_fn(ccx: &CrateContext,
206209
name: &str,
207210
ty: Type,
208211
output: ty::t) -> ValueRef {
209-
decl_fn(llmod, name, lib::llvm::CCallConv, ty, output)
212+
decl_fn(ccx, name, lib::llvm::CCallConv, ty, output)
210213
}
211214

212215
// only use this for foreign function ABIs and glue, use `get_extern_rust_fn` for Rust functions
@@ -221,7 +224,7 @@ pub fn get_extern_fn(ccx: &CrateContext,
221224
Some(n) => return *n,
222225
None => {}
223226
}
224-
let f = decl_fn(ccx.llmod, name, cc, ty, output);
227+
let f = decl_fn(ccx, name, cc, ty, output);
225228
externs.insert(name.to_string(), f);
226229
f
227230
}
@@ -250,7 +253,7 @@ pub fn decl_rust_fn(ccx: &CrateContext, fn_ty: ty::t, name: &str) -> ValueRef {
250253
};
251254

252255
let llfty = type_of_rust_fn(ccx, has_env, inputs.as_slice(), output);
253-
let llfn = decl_fn(ccx.llmod, name, lib::llvm::CCallConv, llfty, output);
256+
let llfn = decl_fn(ccx, name, lib::llvm::CCallConv, llfty, output);
254257
let attrs = get_fn_llvm_attributes(ccx, fn_ty);
255258
for &(idx, attr) in attrs.iter() {
256259
unsafe {
@@ -1877,7 +1880,7 @@ pub fn register_fn_llvmty(ccx: &CrateContext,
18771880
llfty: Type) -> ValueRef {
18781881
debug!("register_fn_llvmty id={} sym={}", node_id, sym);
18791882

1880-
let llfn = decl_fn(ccx.llmod, sym.as_slice(), cc, llfty, ty::mk_nil());
1883+
let llfn = decl_fn(ccx, sym.as_slice(), cc, llfty, ty::mk_nil());
18811884
finish_register_fn(ccx, sp, sym, node_id, llfn);
18821885
llfn
18831886
}
@@ -1909,7 +1912,7 @@ pub fn create_entry_wrapper(ccx: &CrateContext,
19091912
let llfty = Type::func([ccx.int_type, Type::i8p(ccx).ptr_to()],
19101913
&ccx.int_type);
19111914

1912-
let llfn = decl_cdecl_fn(ccx.llmod, "main", llfty, ty::mk_nil());
1915+
let llfn = decl_cdecl_fn(ccx, "main", llfty, ty::mk_nil());
19131916
let llbb = "top".with_c_str(|buf| {
19141917
unsafe {
19151918
llvm::LLVMAppendBasicBlockInContext(ccx.llcx, llfn, buf)

src/librustc/middle/trans/context.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
1211
use driver::config::NoDebugInfo;
1312
use driver::session::Session;
1413
use lib::llvm::{ContextRef, ModuleRef, ValueRef};
@@ -32,6 +31,7 @@ use std::c_str::ToCStr;
3231
use std::ptr;
3332
use std::rc::Rc;
3433
use std::collections::{HashMap, HashSet};
34+
use syntax::abi;
3535
use syntax::ast;
3636
use syntax::parse::token::InternedString;
3737

@@ -273,20 +273,32 @@ impl CrateContext {
273273
None => fail!()
274274
}
275275
}
276+
277+
// Although there is an experimental implementation of LLVM which
278+
// supports SS on armv7 it wasn't approved by Apple, see:
279+
// http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20140505/216350.html
280+
// It looks like it might be never accepted to upstream LLVM.
281+
//
282+
// So far the decision was to disable them in default builds
283+
// but it could be enabled (with patched LLVM)
284+
pub fn is_split_stack_supported(&self) -> bool {
285+
let ref cfg = self.sess().targ_cfg;
286+
cfg.os != abi::OsiOS || cfg.arch != abi::Arm
287+
}
276288
}
277289

278290
fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option<ValueRef> {
279291
macro_rules! ifn (
280292
($name:expr fn() -> $ret:expr) => (
281293
if *key == $name {
282-
let f = base::decl_cdecl_fn(ccx.llmod, $name, Type::func([], &$ret), ty::mk_nil());
294+
let f = base::decl_cdecl_fn(ccx, $name, Type::func([], &$ret), ty::mk_nil());
283295
ccx.intrinsics.borrow_mut().insert($name, f.clone());
284296
return Some(f);
285297
}
286298
);
287299
($name:expr fn($($arg:expr),*) -> $ret:expr) => (
288300
if *key == $name {
289-
let f = base::decl_cdecl_fn(ccx.llmod, $name,
301+
let f = base::decl_cdecl_fn(ccx, $name,
290302
Type::func([$($arg),*], &$ret), ty::mk_nil());
291303
ccx.intrinsics.borrow_mut().insert($name, f.clone());
292304
return Some(f);
@@ -418,7 +430,7 @@ fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option<ValueRef
418430
// The `if key == $name` is already in ifn!
419431
ifn!($name fn($($arg),*) -> $ret);
420432
} else if *key == $name {
421-
let f = base::decl_cdecl_fn(ccx.llmod, stringify!($cname),
433+
let f = base::decl_cdecl_fn(ccx, stringify!($cname),
422434
Type::func([$($arg),*], &$ret),
423435
ty::mk_nil());
424436
ccx.intrinsics.borrow_mut().insert($name, f.clone());

src/librustc/middle/trans/glue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ fn declare_generic_glue(ccx: &CrateContext, t: ty::t, llfnty: Type,
462462
t,
463463
format!("glue_{}", name).as_slice());
464464
debug!("{} is for type {}", fn_nm, ppaux::ty_to_str(ccx.tcx(), t));
465-
let llfn = decl_cdecl_fn(ccx.llmod, fn_nm.as_slice(), llfnty, ty::mk_nil());
465+
let llfn = decl_cdecl_fn(ccx, fn_nm.as_slice(), llfnty, ty::mk_nil());
466466
note_unique_llvm_symbol(ccx, fn_nm);
467467
return llfn;
468468
}

0 commit comments

Comments
 (0)