1
- // ===- RexInsertEntry.cpp - code to perform entry insertion for Rex programs-===//
1
+ // ===- RexInsertEntry.cpp - performs entry insertion for Rex programs ---- -===//
2
2
//
3
3
// Part of the Inner-Unikernels project, based on the LLVM project under
4
4
// the Apache License v2.0 with LLVM Exceptions.
@@ -59,8 +59,8 @@ STATISTIC(NumInserted, "Number of entry function inserted");
59
59
// / Validate program sections, the put the function and program object
60
60
// / into appropriate sections
61
61
void RexEntryInsertion::validateAndFinalizeSection (Function *EntryFn,
62
- GlobalVariable *ProgObj,
63
- unsigned ProgType) const {
62
+ GlobalVariable *ProgObj,
63
+ unsigned ProgType) const {
64
64
// We want to strip the "inner_unikernel/" prefix
65
65
// strlen("rex/") = 4
66
66
EntryFn->setSection (ProgObj->getSection ().substr (4 ));
@@ -87,9 +87,9 @@ void RexEntryInsertion::validateAndFinalizeSection(Function *EntryFn,
87
87
88
88
// / Performs the actual insertion of the new function
89
89
Function *RexEntryInsertion::insertEntry (Module &M, FunctionCallee &ProgRun,
90
- GlobalVariable *ProgObj, Type *CtxPT,
91
- StringRef Name,
92
- unsigned ProgType ) const {
90
+ GlobalVariable *ProgObj, Type *CtxPT,
91
+ StringRef Name, unsigned ProgType ,
92
+ AttributeList Attrs ) const {
93
93
LLVMContext &C = M.getContext ();
94
94
95
95
// Argument and return type
@@ -98,7 +98,9 @@ Function *RexEntryInsertion::insertEntry(Module &M, FunctionCallee &ProgRun,
98
98
99
99
// Declare the function in module
100
100
FunctionType *EntryTy = FunctionType::get (EntryRetty, EntryArgTys, false );
101
- FunctionCallee Entry = M.getOrInsertFunction (Name, EntryTy, getRexFnAttr (C));
101
+ FunctionCallee Entry = M.getOrInsertFunction (
102
+ Name, EntryTy,
103
+ AttributeList::get (C, AttributeList::FunctionIndex, Attrs.getFnAttrs ()));
102
104
103
105
// Setup attributes
104
106
Function *EntryFn = cast<Function>(Entry.getCallee ());
@@ -145,7 +147,8 @@ AttributeList RexEntryInsertion::getRexFnAttr(LLVMContext &C) const {
145
147
.addFnAttribute (C, " probe-stack" , " __rust_probestack" )
146
148
.addFnAttribute (C, " target-cpu" , " x86-64" )
147
149
.addFnAttribute (C, " target-features" , TargetFeatureSs.str ())
148
- .addFnAttribute (C, " tune-cpu" , " generic" );
150
+ .addFnAttribute (C, " tune-cpu" , " generic" )
151
+ .addFnAttribute (C, " frame-pointer" , " all" );
149
152
return AS;
150
153
}
151
154
@@ -209,8 +212,10 @@ bool RexEntryInsertion::runOnModule(Module &M) const {
209
212
210
213
FunctionType *ProgRunTy =
211
214
FunctionType::get (ProgRunRetty, ProgRunArgTys, false );
212
- FunctionCallee ProgRun =
213
- M.getOrInsertFunction (ProgRunName, ProgRunTy, getRexFnAttr (C));
215
+ FunctionCallee ProgRun = M.getOrInsertFunction (
216
+ ProgRunName, ProgRunTy,
217
+ AttributeList::get (C, AttributeList::FunctionIndex,
218
+ Func->getAttributes ().getFnAttrs ()));
214
219
215
220
// name: &'a str
216
221
Constant *OP2 = CS->getOperand (2 );
@@ -229,7 +234,8 @@ bool RexEntryInsertion::runOnModule(Module &M) const {
229
234
NamedMD->addOperand (Node);
230
235
231
236
// Add the function using the extracted information above
232
- Function *EntryFunc = insertEntry (M, ProgRun, &G, CtxPT, ProgName, RTTI);
237
+ Function *EntryFunc = insertEntry (M, ProgRun, &G, CtxPT, ProgName, RTTI,
238
+ Func->getAttributes ());
233
239
UsedGV.push_back (EntryFunc);
234
240
235
241
// Transformation made
@@ -312,7 +318,7 @@ bool RexEntryInsertion::instrumentStack(Module &M, LLVMContext &C) const {
312
318
}
313
319
314
320
Function *RexEntryInsertion::createTimeoutHandler (Module &M,
315
- LLVMContext &C) const {
321
+ LLVMContext &C) const {
316
322
// Rust uses void return type for noreturn (i.e. the "!" return type)
317
323
FunctionType *TimeoutHandlerTy =
318
324
FunctionType::get (Type::getVoidTy (C), {}, false );
0 commit comments