From: Rafael Espindola Date: Tue, 29 Jul 2014 20:46:19 +0000 (+0000) Subject: gold plugin: Fix handling of corrupted bitcode files. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=df7568e9f3a38d9301e99c5ae3229b8622aa86fa;p=llvm gold plugin: Fix handling of corrupted bitcode files. We should still claim them and tell gold about the error. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@214214 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/tools/gold/Inputs/invalid.bc b/test/tools/gold/Inputs/invalid.bc new file mode 100644 index 00000000000..2e7ca8d2e10 Binary files /dev/null and b/test/tools/gold/Inputs/invalid.bc differ diff --git a/test/tools/gold/invalid.ll b/test/tools/gold/invalid.ll new file mode 100644 index 00000000000..8db76446a3d --- /dev/null +++ b/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/tools/gold/gold-plugin.cpp b/tools/gold/gold-plugin.cpp index 8c30ba2a428..d428c6910a8 100644 --- a/tools/gold/gold-plugin.cpp +++ b/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();