Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More shadow bugs/fixes #218

Merged
merged 3 commits into from
Dec 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions llvm/lib/Transforms/Yk/ShadowStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ class YkShadowStack : public ModulePass {
}
}
Builder.SetInsertPoint(&I);
auto AllocaSizeInBits = AI.getAllocationSizeInBits(DL);
if (!AllocaSizeInBits) {
auto AllocaSizeInBytes = AI.getAllocationSize(DL);
if (!AllocaSizeInBytes) {
// YKFIXME: Deal with functions where the stack size isn't know at
// compile time, e.g. when `alloca` is used.
Context.emitError("Unable to add shadow stack: function has "
Expand All @@ -153,7 +153,6 @@ class YkShadowStack : public ModulePass {
// Calculate this `AllocaInst`s size, aligning its pointer if
// necessary, and create a replacement pointer into the shadow
// stack.
size_t AllocaSize = *AllocaSizeInBits / sizeof(uintptr_t);
size_t Align = AI.getAlign().value();
Offset = int((Offset + (Align - 1)) / Align) * Align;
if (Offset == 0) {
Expand All @@ -168,11 +167,10 @@ class YkShadowStack : public ModulePass {
Int8Ty, SSPtr, {ConstantInt::get(Int32Ty, Offset)}, "",
cast<Instruction>(&AI));
Builder.SetInsertPoint(GEP);
Builder.CreateBitCast(GEP, AI.getAllocatedType()->getPointerTo());
cast<Value>(I).replaceAllUsesWith(GEP);
}
RemoveAllocas.push_back(cast<Instruction>(&AI));
Offset += AllocaSize;
Offset += *AllocaSizeInBytes;
} else if (isa<CallInst>(I)) {
// When we see a call, we need make space for a new stack frame. We
// do this by simply adjusting the pointer stored in the global
Expand Down Expand Up @@ -228,6 +226,11 @@ class YkShadowStack : public ModulePass {
Builder.CreateStore(GEP, GShadowStackPtr);
Builder.SetInsertPoint(I.getNextNonDebugInstruction());
Builder.CreateStore(SSPtr, GShadowStackPtr);
} else if (isa<CallBase>(I)) {
// FIXME: There are other call-like instructions (e.g. `invoke`,
// `callbr`) that we will need to think about when they arise.
Context.emitError("Unimplemented shadow stack allocation");
return false;
}
}
}
Expand Down
Loading