diff options
author | Mark Seaborn <mseaborn@chromium.org> | 2013-04-01 09:33:02 -0700 |
---|---|---|
committer | Mark Seaborn <mseaborn@chromium.org> | 2013-04-01 09:33:02 -0700 |
commit | a6c4b28460c42bc9fbbdcefffb4aed603f07f068 (patch) | |
tree | 2dcc9c33b3e267c01e822130de5bdba3adc511cf | |
parent | cd93e1afec966dba60433f8df5f78f10ef217f93 (diff) |
PNaCl: Allow the ABI checker to be used from "opt"
This allows the ABI checker passes to be used in the same way as
LLVM's "-verify" pass. It allows the checker to be run between other
passes, and without launching pnacl-abicheck as a separate process (so
without the overhead of reading bitcode into memory again).
Make the ABI checker passes produce fatal errors by default, to match
"-verify". This is overridden for pnacl-abicheck's use.
BUG=https://code.google.com/p/nativeclient/issues/detail?id=2309
TEST=tested with pnacl-ld.py changes to use the ABI checker passes
Review URL: https://codereview.chromium.org/13323006
-rw-r--r-- | include/llvm/Analysis/NaCl.h | 14 | ||||
-rw-r--r-- | lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp | 1 | ||||
-rw-r--r-- | lib/Analysis/NaCl/PNaClABIVerifyModule.cpp | 2 | ||||
-rw-r--r-- | tools/opt/opt.cpp | 2 | ||||
-rw-r--r-- | tools/pnacl-abicheck/pnacl-abicheck.cpp | 1 |
5 files changed, 19 insertions, 1 deletions
diff --git a/include/llvm/Analysis/NaCl.h b/include/llvm/Analysis/NaCl.h index a8f2c9651e..722b4bd7a6 100644 --- a/include/llvm/Analysis/NaCl.h +++ b/include/llvm/Analysis/NaCl.h @@ -10,6 +10,7 @@ #ifndef LLVM_ANALYSIS_NACL_H #define LLVM_ANALYSIS_NACL_H +#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" #include <string> @@ -20,7 +21,8 @@ class ModulePass; class PNaClABIErrorReporter { public: - PNaClABIErrorReporter() : ErrorCount(0), Errors(ErrorString) {} + PNaClABIErrorReporter() : ErrorCount(0), Errors(ErrorString), + UseFatalErrors(true) {} // Return the number of verification errors from the last run. int getErrorCount() { return ErrorCount; } // Print the error messages to O @@ -40,10 +42,20 @@ class PNaClABIErrorReporter { Errors.flush(); ErrorString.clear(); } + void setNonFatal() { + UseFatalErrors = false; + } + void checkForFatalErrors() { + if (UseFatalErrors && ErrorCount != 0) { + printErrors(errs()); + report_fatal_error("PNaCl ABI verification failed"); + } + } private: int ErrorCount; std::string ErrorString; raw_string_ostream Errors; + bool UseFatalErrors; }; FunctionPass *createPNaClABIVerifyFunctionsPass(PNaClABIErrorReporter * Reporter); diff --git a/lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp b/lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp index 8404a4cafc..55269dc9fe 100644 --- a/lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp +++ b/lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp @@ -175,6 +175,7 @@ bool PNaClABIVerifyFunctions::runOnFunction(Function &F) { } } + Reporter->checkForFatalErrors(); return false; } diff --git a/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp b/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp index 660fa9f8fe..23699860b0 100644 --- a/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp +++ b/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp @@ -149,6 +149,8 @@ bool PNaClABIVerifyModule::runOnModule(Module &M) { } } } + + Reporter->checkForFatalErrors(); return false; } diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index 106da562c6..2998a047cf 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -584,6 +584,8 @@ int main(int argc, char **argv) { initializeExpandTlsConstantExprPass(Registry); initializeExpandVarArgsPass(Registry); initializeGlobalCleanupPass(Registry); + initializePNaClABIVerifyFunctionsPass(Registry); + initializePNaClABIVerifyModulePass(Registry); initializeResolveAliasesPass(Registry); initializeStripMetadataPass(Registry); // @LOCALMOD-END diff --git a/tools/pnacl-abicheck/pnacl-abicheck.cpp b/tools/pnacl-abicheck/pnacl-abicheck.cpp index 2fefd46c8b..8fdc545afb 100644 --- a/tools/pnacl-abicheck/pnacl-abicheck.cpp +++ b/tools/pnacl-abicheck/pnacl-abicheck.cpp @@ -55,6 +55,7 @@ int main(int argc, char **argv) { return 1; } PNaClABIErrorReporter ABIErrorReporter; + ABIErrorReporter.setNonFatal(); bool ErrorsFound = false; // Manually run the passes so we can tell the user which function had the // error. No need for a pass manager since it's just one pass. |