From 6c472e5e1449b6c2e420ca696319cd26ddb5be81 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 29 Jul 2014 20:46:19 +0000 Subject: [PATCH] gold plugin: Fix handling of corrupted bitcode files. We should still claim them and tell gold about the error. llvm-svn: 214214 --- llvm/test/tools/gold/Inputs/invalid.bc | Bin 0 -> 272 bytes llvm/test/tools/gold/invalid.ll | 7 +++++++ llvm/tools/gold/gold-plugin.cpp | 5 +++-- 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 llvm/test/tools/gold/Inputs/invalid.bc create mode 100644 llvm/test/tools/gold/invalid.ll diff --git a/llvm/test/tools/gold/Inputs/invalid.bc b/llvm/test/tools/gold/Inputs/invalid.bc new file mode 100644 index 0000000000000000000000000000000000000000..2e7ca8d2e10568ed273c45e438bd47e58f80285c GIT binary patch literal 272 zcmZ>AK5&nLhk?P7fq{X$Nr8b0NDBcmd!zD1#}h1`Yyw7>lNeigR9QJB!e zoF;KQu?QH6Sa3*qav8a(cyLWnR6Y{az$2+xq{4oJLm+9zf)x(OJ}?5!=~Q4~-~iG_ zN*o*tDXlER3QJmm#N(EQ6GVi38hW@}SbPM4@|6+{4DvwQn4>}F$U~Vl5k}h%XN#7@ zJx&eml@;v8GYWa0G4Q_?;QP|RXUyXycj%z(xrH)m2CQIZ&C+L>ZBIDc_AuL?spu&w zV6Wz2uk>gyC}6KDU@og@FHmTgJR`{WW&+LBqJ_PU?3mlQXrzmqnQT9-x J9MEnM001S&N?!l~ literal 0 HcmV?d00001 diff --git a/llvm/test/tools/gold/invalid.ll b/llvm/test/tools/gold/invalid.ll new file mode 100644 index 0000000..8db7644 --- /dev/null +++ b/llvm/test/tools/gold/invalid.ll @@ -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 diff --git a/llvm/tools/gold/gold-plugin.cpp b/llvm/tools/gold/gold-plugin.cpp index 8c30ba2..d428c69 100644 --- a/llvm/tools/gold/gold-plugin.cpp +++ b/llvm/tools/gold/gold-plugin.cpp @@ -291,6 +291,8 @@ static ld_plugin_status claim_file_hook(const ld_plugin_input_file *file, 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(const ld_plugin_input_file *file, (*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(); -- 2.7.4