diff options
author | Mark Seaborn <mseaborn@chromium.org> | 2013-06-06 10:33:01 -0700 |
---|---|---|
committer | Mark Seaborn <mseaborn@chromium.org> | 2013-06-06 10:33:01 -0700 |
commit | bcbad3ce541bc70ab3383d3d77198ceb9e813b46 (patch) | |
tree | 0e259872032346feb3f4e5f2402588602a179d3d | |
parent | 37bdd9174a1cba17b369c8c1f561e70c458e0c13 (diff) |
PNaCl ABI: Strip out calling conventions from functions and calls
Always use the standard C calling conventions. Disallow "fastcc" etc.
BUG=https://code.google.com/p/nativeclient/issues/detail?id=2346
TEST=*.ll tests + PNaCl toolchain trybots
Review URL: https://codereview.chromium.org/16529004
-rw-r--r-- | lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp | 10 | ||||
-rw-r--r-- | lib/Analysis/NaCl/PNaClABIVerifyModule.cpp | 6 | ||||
-rw-r--r-- | lib/Transforms/NaCl/StripAttributes.cpp | 10 | ||||
-rw-r--r-- | test/NaCl/PNaClABI/abi-call-attributes.ll | 5 | ||||
-rw-r--r-- | test/NaCl/PNaClABI/global-attributes.ll | 5 | ||||
-rw-r--r-- | test/Transforms/NaCl/strip-attributes.ll | 4 |
6 files changed, 32 insertions, 8 deletions
diff --git a/lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp b/lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp index 167cad15d0..a59f6f6682 100644 --- a/lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp +++ b/lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp @@ -255,11 +255,14 @@ const char *PNaClABIVerifyFunctions::checkInstruction(const Instruction *Inst) { break; } - case Instruction::Call: - if (cast<CallInst>(Inst)->isInlineAsm()) + case Instruction::Call: { + const CallInst *Call = cast<CallInst>(Inst); + if (Call->isInlineAsm()) return "inline assembly"; - if (!cast<CallInst>(Inst)->getAttributes().isEmpty()) + if (!Call->getAttributes().isEmpty()) return "bad call attributes"; + if (Call->getCallingConv() != CallingConv::C) + return "bad calling convention"; // Intrinsic calls can have multiple pointer arguments and // metadata arguments, so handle them specially. @@ -281,6 +284,7 @@ const char *PNaClABIVerifyFunctions::checkInstruction(const Instruction *Inst) { if (!isNormalizedPtr(Inst->getOperand(PtrOperandIndex))) return "bad function callee operand"; break; + } case Instruction::Switch: { // SwitchInst represents switch cases using array and vector diff --git a/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp b/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp index 91f71c949c..477bc50ec9 100644 --- a/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp +++ b/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp @@ -383,6 +383,12 @@ bool PNaClABIVerifyModule::runOnModule(Module &M) { << "Function " << MI->getName() << " has disallowed attributes:" << getAttributesAsString(MI->getAttributes()) << "\n"; } + if (MI->getCallingConv() != CallingConv::C) { + Reporter->addError() + << "Function " << MI->getName() + << " has disallowed calling convention: " + << MI->getCallingConv() << "\n"; + } } checkGlobalValueCommon(MI); diff --git a/lib/Transforms/NaCl/StripAttributes.cpp b/lib/Transforms/NaCl/StripAttributes.cpp index f5ec0423b4..476c500756 100644 --- a/lib/Transforms/NaCl/StripAttributes.cpp +++ b/lib/Transforms/NaCl/StripAttributes.cpp @@ -8,12 +8,14 @@ //===----------------------------------------------------------------------===// // // This pass strips out attributes that are not supported by PNaCl's -// stable ABI. Currently, this strips out attributes from functions -// and function calls. +// stable ABI. Currently, this strips out: +// +// * Function and argument attributes from functions and function +// calls. +// * Calling conventions from functions and function calls. // // TODO(mseaborn): Strip out the following too: // -// * Calling conventions from functions and function calls. // * "nuw" and "nsw" arithmetic attributes. // * "align" attributes from integer memory accesses. // @@ -131,6 +133,7 @@ static void CheckAttributes(AttributeSet Attrs) { bool StripAttributes::runOnFunction(Function &Func) { CheckAttributes(Func.getAttributes()); Func.setAttributes(AttributeSet()); + Func.setCallingConv(CallingConv::C); for (Function::iterator BB = Func.begin(), E = Func.end(); BB != E; ++BB) { @@ -140,6 +143,7 @@ bool StripAttributes::runOnFunction(Function &Func) { if (Call) { CheckAttributes(Call.getAttributes()); Call.setAttributes(AttributeSet()); + Call.setCallingConv(CallingConv::C); } } } diff --git a/test/NaCl/PNaClABI/abi-call-attributes.ll b/test/NaCl/PNaClABI/abi-call-attributes.ll index 0e4de4610b..56c6a8c363 100644 --- a/test/NaCl/PNaClABI/abi-call-attributes.ll +++ b/test/NaCl/PNaClABI/abi-call-attributes.ll @@ -7,8 +7,13 @@ define void @func(i32 %arg) { define void @calls() { call void @func(i32 1) noreturn nounwind ; CHECK: disallowed: bad call attributes: call void @func(i32 1) # + call void @func(i32 inreg 1) ; CHECK-NEXT: disallowed: bad call attributes: call void @func(i32 inreg 1) + + call fastcc void @func(i32 1) +; CHECK-NEXT: disallowed: bad calling convention: call fastcc void @func(i32 1) + ret void } diff --git a/test/NaCl/PNaClABI/global-attributes.ll b/test/NaCl/PNaClABI/global-attributes.ll index 4b8d893acb..6697d9515c 100644 --- a/test/NaCl/PNaClABI/global-attributes.ll +++ b/test/NaCl/PNaClABI/global-attributes.ll @@ -27,6 +27,11 @@ define void @func_with_arg_attrs(i32 inreg zeroext) { ret void } +; CHECK-NEXT: Function func_with_callingconv has disallowed calling convention: 8 +define fastcc void @func_with_callingconv() { + ret void +} + ; CHECK-NEXT: Function func_with_section has disallowed "section" attribute define void @func_with_section() section ".some_section" { ret void diff --git a/test/Transforms/NaCl/strip-attributes.ll b/test/Transforms/NaCl/strip-attributes.ll index 53d8a30325..fda8c30f6b 100644 --- a/test/Transforms/NaCl/strip-attributes.ll +++ b/test/Transforms/NaCl/strip-attributes.ll @@ -1,12 +1,12 @@ ; RUN: opt -S -nacl-strip-attributes %s | FileCheck %s -define void @func_attrs(i32 inreg, i32 zeroext) noreturn nounwind readonly { +define fastcc void @func_attrs(i32 inreg, i32 zeroext) noreturn nounwind readonly { ret void } ; CHECK: define void @func_attrs(i32, i32) { define void @call_attrs() { - call void @func_attrs(i32 inreg 10, i32 zeroext 20) noreturn nounwind readonly + call fastcc void @func_attrs(i32 inreg 10, i32 zeroext 20) noreturn nounwind readonly ret void } ; CHECK: define void @call_attrs() |