[llvm] r214214 - gold plugin: Fix handling of corrupted bitcode files.

Rafael Espindola rafael.espindola at gmail.com
Tue Jul 29 13:46:19 PDT 2014


Author: rafael
Date: Tue Jul 29 15:46:19 2014
New Revision: 214214

URL: http://llvm.org/viewvc/llvm-project?rev=214214&view=rev
Log:
gold plugin: Fix handling of corrupted bitcode files.

We should still claim them and tell gold about the error.

Added:
    llvm/trunk/test/tools/gold/Inputs/
    llvm/trunk/test/tools/gold/Inputs/invalid.bc
    llvm/trunk/test/tools/gold/invalid.ll
Modified:
    llvm/trunk/tools/gold/gold-plugin.cpp

Added: llvm/trunk/test/tools/gold/Inputs/invalid.bc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/gold/Inputs/invalid.bc?rev=214214&view=auto
==============================================================================
Binary files llvm/trunk/test/tools/gold/Inputs/invalid.bc (added) and llvm/trunk/test/tools/gold/Inputs/invalid.bc Tue Jul 29 15:46:19 2014 differ

Added: llvm/trunk/test/tools/gold/invalid.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/gold/invalid.ll?rev=214214&view=auto
==============================================================================
--- llvm/trunk/test/tools/gold/invalid.ll (added)
+++ llvm/trunk/test/tools/gold/invalid.ll Tue Jul 29 15:46:19 2014
@@ -0,0 +1,7 @@
+; RUN: not ld -plugin %llvmshlibdir/LLVMgold.so \
+; RUN:    %p/Inputs/invalid.bc -o %t2 2>&1 | FileCheck %s
+
+; test that only one error gets printed
+
+; CHECK: error: LLVM gold plugin has failed to create LTO module: Malformed block
+; CHECK-NOT: error

Modified: llvm/trunk/tools/gold/gold-plugin.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/gold/gold-plugin.cpp?rev=214214&r1=214213&r2=214214&view=diff
==============================================================================
--- llvm/trunk/tools/gold/gold-plugin.cpp (original)
+++ llvm/trunk/tools/gold/gold-plugin.cpp Tue Jul 29 15:46:19 2014
@@ -291,6 +291,8 @@ static ld_plugin_status claim_file_hook(
   if (!LTOModule::isBitcodeFile(view, file->filesize))
     return LDPS_OK;
 
+  *claimed = 1;
+
   std::string Error;
   LTOModule *M =
       LTOModule::createFromBuffer(view, file->filesize, TargetOpts, Error);
@@ -298,10 +300,9 @@ static ld_plugin_status claim_file_hook(
     (*message)(LDPL_ERROR,
                "LLVM gold plugin has failed to create LTO module: %s",
                Error.c_str());
-    return LDPS_OK;
+    return LDPS_ERR;
   }
 
-  *claimed = 1;
   Modules.resize(Modules.size() + 1);
   claimed_file &cf = Modules.back();
 





More information about the llvm-commits mailing list