Chromium Code Reviews| Index: lib/Analysis/NaCl/PNaClABIVerifyModule.cpp |
| diff --git a/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp b/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp |
| index efb40cf43a7d90747ae4ae081e47a468e8318c9b..8dff805c347fa84e5259a08a19e2e07425721146 100644 |
| --- a/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp |
| +++ b/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp |
| @@ -17,7 +17,9 @@ |
| #include "llvm/ADT/Twine.h" |
| #include "llvm/Analysis/NaCl.h" |
| #include "llvm/IR/DerivedTypes.h" |
| +#include "llvm/IR/Intrinsics.h" |
| #include "llvm/IR/Module.h" |
| +#include "llvm/Support/Debug.h" |
| #include "llvm/Support/raw_ostream.h" |
| #include "PNaClABITypeChecker.h" |
| @@ -28,8 +30,13 @@ cl::opt<bool> |
| PNaClABIAllowDebugMetadata("pnaclabi-allow-debug-metadata", |
| cl::desc("Allow debug metadata during PNaCl ABI verification."), |
| cl::init(false)); |
| + |
| } |
| +static cl::opt<bool> PNaClABIAllowIntrinsics("pnaclabi-allow-intrinsics", |
|
eliben
2013/05/07 15:27:40
Can we divide intrinsics into 3 groups:
1. Those
jvoung (off chromium)
2013/05/07 17:39:46
That sounds like a good breakdown.
I'll rename t
jvoung (off chromium)
2013/05/07 21:24:41
At the Tues meeting (an hour ago), there was some
|
| + cl::desc("Allow all LLVM intrinsics duing PNaCl ABI verification."), |
| + cl::init(true)); // TODO(jvoung): Make this false by default. |
| + |
| namespace { |
| // This pass should not touch function bodies, to stay streaming-friendly |
| class PNaClABIVerifyModule : public ModulePass { |
| @@ -55,6 +62,7 @@ class PNaClABIVerifyModule : public ModulePass { |
| virtual void print(raw_ostream &O, const Module *M) const; |
| private: |
| void CheckGlobalValueCommon(const GlobalValue *GV); |
| + bool IsWhitelistedIntrinsic(const Function* F, unsigned ID); |
| bool IsWhitelistedMetadata(const NamedMDNode *MD); |
| PNaClABITypeChecker TC; |
| PNaClABIErrorReporter *Reporter; |
| @@ -113,6 +121,38 @@ void PNaClABIVerifyModule::CheckGlobalValueCommon(const GlobalValue *GV) { |
| } |
| } |
| +bool PNaClABIVerifyModule::IsWhitelistedIntrinsic(const Function* F, |
| + unsigned ID) { |
| + switch(ID) { |
| + default: |
| + DEBUG(dbgs() << "Unknown intrinsic: " << F->getName() << "\n"); |
| + return PNaClABIAllowIntrinsics; |
| + case Intrinsic::not_intrinsic: return false; |
| + case Intrinsic::dbg_declare: |
| + case Intrinsic::dbg_value: |
| + case Intrinsic::frameaddress: // Likely only used for debugging? |
| + case Intrinsic::returnaddress: // Likely only used for debugging? |
| + return PNaClABIAllowDebugMetadata; |
| + case Intrinsic::invariant_end: |
| + case Intrinsic::invariant_start: |
| + case Intrinsic::lifetime_end: |
| + case Intrinsic::lifetime_start: |
| + case Intrinsic::memcpy: |
| + case Intrinsic::memmove: |
| + case Intrinsic::memset: |
| + case Intrinsic::nacl_read_tp: |
| + case Intrinsic::trap: |
| + return true; |
| + case Intrinsic::vacopy: |
| + case Intrinsic::vaend: |
| + case Intrinsic::vastart: |
| + // Var-args code is expanded out, so we shouldn't need va_arg intrinsics. |
| + // TODO(jvoung): Disallow this too. However, we need to strip |
| + // dead prototypes before this will work. |
| + return PNaClABIAllowDebugMetadata; |
| + } |
| +} |
| + |
| bool PNaClABIVerifyModule::IsWhitelistedMetadata(const NamedMDNode* MD) { |
| return MD->getName().startswith("llvm.dbg.") && PNaClABIAllowDebugMetadata; |
| } |
| @@ -153,6 +193,14 @@ bool PNaClABIVerifyModule::runOnModule(Module &M) { |
| } |
| for (Module::const_iterator MI = M.begin(), ME = M.end(); MI != ME; ++MI) { |
| + // Check intrinsics. |
| + if (MI->isIntrinsic()) { |
|
eliben
2013/05/07 15:27:40
Can an intrinsic be called without a declaration?
jvoung (off chromium)
2013/05/07 17:39:46
I don't think you can call intrinsics without a de
jvoung (off chromium)
2013/05/07 22:32:18
Ah yes, you mean we'd do something like "llc -disa
jvoung (off chromium)
2013/05/07 22:33:08
Err... not that you can't generate bad binary bitc
|
| + if (!IsWhitelistedIntrinsic(MI, MI->getIntrinsicID())) { |
| + Reporter->addError() << "Function " << MI->getName() |
| + << " is a disallowed LLVM intrinsic\n"; |
| + } |
| + } |
| + |
| // Check types of functions and their arguments |
| FunctionType *FT = MI->getFunctionType(); |
| if (!TC.isValidType(FT->getReturnType())) { |