Skip to content

Commit e59bbe9

Browse files
committed
Fix setting the fixed stack segment attribute on LLVM functions
At the same time create a more robust wrapper to try to prevent this type of issue from cropping up in the future.
1 parent a9391d9 commit e59bbe9

File tree

2 files changed

+45
-63
lines changed

2 files changed

+45
-63
lines changed

src/librustc/lib/llvm.rs

+38-29
Original file line numberDiff line numberDiff line change
@@ -59,35 +59,35 @@ pub enum Linkage {
5959
}
6060

6161
pub enum Attribute {
62-
ZExtAttribute = 1,
63-
SExtAttribute = 2,
64-
NoReturnAttribute = 4,
65-
InRegAttribute = 8,
66-
StructRetAttribute = 16,
67-
NoUnwindAttribute = 32,
68-
NoAliasAttribute = 64,
69-
ByValAttribute = 128,
70-
NestAttribute = 256,
71-
ReadNoneAttribute = 512,
72-
ReadOnlyAttribute = 1024,
73-
NoInlineAttribute = 2048,
74-
AlwaysInlineAttribute = 4096,
75-
OptimizeForSizeAttribute = 8192,
76-
StackProtectAttribute = 16384,
77-
StackProtectReqAttribute = 32768,
78-
// 31 << 16
79-
AlignmentAttribute = 2031616,
80-
NoCaptureAttribute = 2097152,
81-
NoRedZoneAttribute = 4194304,
82-
NoImplicitFloatAttribute = 8388608,
83-
NakedAttribute = 16777216,
84-
InlineHintAttribute = 33554432,
85-
// 7 << 26
86-
StackAttribute = 469762048,
87-
ReturnsTwiceAttribute = 536870912,
88-
// 1 << 30
89-
UWTableAttribute = 1073741824,
90-
NonLazyBindAttribute = 2147483648,
62+
ZExtAttribute = 1 << 0,
63+
SExtAttribute = 1 << 1,
64+
NoReturnAttribute = 1 << 2,
65+
InRegAttribute = 1 << 3,
66+
StructRetAttribute = 1 << 4,
67+
NoUnwindAttribute = 1 << 5,
68+
NoAliasAttribute = 1 << 6,
69+
ByValAttribute = 1 << 7,
70+
NestAttribute = 1 << 8,
71+
ReadNoneAttribute = 1 << 9,
72+
ReadOnlyAttribute = 1 << 10,
73+
NoInlineAttribute = 1 << 11,
74+
AlwaysInlineAttribute = 1 << 12,
75+
OptimizeForSizeAttribute = 1 << 13,
76+
StackProtectAttribute = 1 << 14,
77+
StackProtectReqAttribute = 1 << 15,
78+
AlignmentAttribute = 31 << 16,
79+
NoCaptureAttribute = 1 << 21,
80+
NoRedZoneAttribute = 1 << 22,
81+
NoImplicitFloatAttribute = 1 << 23,
82+
NakedAttribute = 1 << 24,
83+
InlineHintAttribute = 1 << 25,
84+
StackAttribute = 7 << 26,
85+
ReturnsTwiceAttribute = 1 << 29,
86+
UWTableAttribute = 1 << 30,
87+
NonLazyBindAttribute = 1 << 31,
88+
89+
// Not added to LLVM yet, so may need to stay updated if LLVM changes.
90+
FixedStackSegment = 1 << 41,
9191
}
9292

9393
// enum for the LLVM IntPredicate type
@@ -2118,6 +2118,15 @@ pub fn ConstFCmp(Pred: RealPredicate, V1: ValueRef, V2: ValueRef) -> ValueRef {
21182118
llvm::LLVMConstFCmp(Pred as c_ushort, V1, V2)
21192119
}
21202120
}
2121+
2122+
pub fn SetFunctionAttribute(Fn: ValueRef, attr: Attribute) {
2123+
unsafe {
2124+
let attr = attr as u64;
2125+
let lower = attr & 0xffffffff;
2126+
let upper = (attr >> 32) & 0xffffffff;
2127+
llvm::LLVMAddFunctionAttr(Fn, lower as c_uint, upper as c_uint);
2128+
}
2129+
}
21212130
/* Memory-managed object interface to type handles. */
21222131

21232132
pub struct TypeNames {

src/librustc/middle/trans/base.rs

+7-34
Original file line numberDiff line numberDiff line change
@@ -379,46 +379,25 @@ pub fn get_tydesc(ccx: &mut CrateContext, t: ty::t) -> @mut tydesc_info {
379379
}
380380

381381
pub fn set_optimize_for_size(f: ValueRef) {
382-
unsafe {
383-
llvm::LLVMAddFunctionAttr(f,
384-
lib::llvm::OptimizeForSizeAttribute
385-
as c_uint,
386-
0);
387-
}
382+
lib::llvm::SetFunctionAttribute(f, lib::llvm::OptimizeForSizeAttribute)
388383
}
389384

390385
pub fn set_no_inline(f: ValueRef) {
391-
unsafe {
392-
llvm::LLVMAddFunctionAttr(f,
393-
lib::llvm::NoInlineAttribute as c_uint,
394-
0);
395-
}
386+
lib::llvm::SetFunctionAttribute(f, lib::llvm::NoInlineAttribute)
396387
}
397388

398389
pub fn set_no_unwind(f: ValueRef) {
399-
unsafe {
400-
llvm::LLVMAddFunctionAttr(f,
401-
lib::llvm::NoUnwindAttribute as c_uint,
402-
0);
403-
}
390+
lib::llvm::SetFunctionAttribute(f, lib::llvm::NoUnwindAttribute)
404391
}
405392

406393
// Tell LLVM to emit the information necessary to unwind the stack for the
407394
// function f.
408395
pub fn set_uwtable(f: ValueRef) {
409-
unsafe {
410-
llvm::LLVMAddFunctionAttr(f,
411-
lib::llvm::UWTableAttribute as c_uint,
412-
0);
413-
}
396+
lib::llvm::SetFunctionAttribute(f, lib::llvm::UWTableAttribute)
414397
}
415398

416399
pub fn set_inline_hint(f: ValueRef) {
417-
unsafe {
418-
llvm::LLVMAddFunctionAttr(f,
419-
lib::llvm::InlineHintAttribute as c_uint,
420-
0);
421-
}
400+
lib::llvm::SetFunctionAttribute(f, lib::llvm::InlineHintAttribute)
422401
}
423402

424403
pub fn set_inline_hint_if_appr(attrs: &[ast::attribute],
@@ -432,17 +411,11 @@ pub fn set_inline_hint_if_appr(attrs: &[ast::attribute],
432411
}
433412

434413
pub fn set_always_inline(f: ValueRef) {
435-
unsafe {
436-
llvm::LLVMAddFunctionAttr(f,
437-
lib::llvm::AlwaysInlineAttribute as c_uint,
438-
0);
439-
}
414+
lib::llvm::SetFunctionAttribute(f, lib::llvm::AlwaysInlineAttribute)
440415
}
441416

442417
pub fn set_fixed_stack_segment(f: ValueRef) {
443-
unsafe {
444-
llvm::LLVMAddFunctionAttr(f, 0, 1 << (39 - 32));
445-
}
418+
lib::llvm::SetFunctionAttribute(f, lib::llvm::FixedStackSegment)
446419
}
447420

448421
pub fn set_glue_inlining(f: ValueRef, t: ty::t) {

0 commit comments

Comments
 (0)