[lld] r266504 - [LTO] Don't crash on a BitcodeFile without DataLayout.

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 15 18:33:33 PDT 2016


Author: davide
Date: Fri Apr 15 20:33:33 2016
New Revision: 266504

URL: http://llvm.org/viewvc/llvm-project?rev=266504&view=rev
Log:
[LTO] Don't crash on a BitcodeFile without DataLayout.

Emit an error instead.

Added:
    lld/trunk/test/ELF/lto/invalid-bitcode.ll
Modified:
    lld/trunk/ELF/LTO.cpp

Modified: lld/trunk/ELF/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LTO.cpp?rev=266504&r1=266503&r2=266504&view=diff
==============================================================================
--- lld/trunk/ELF/LTO.cpp (original)
+++ lld/trunk/ELF/LTO.cpp Fri Apr 15 20:33:33 2016
@@ -82,6 +82,8 @@ void BitcodeCompiler::add(BitcodeFile &F
   ArrayRef<SymbolBody *> Bodies = F.getSymbols();
 
   Module &M = Obj->getModule();
+  if (M.getDataLayoutStr().empty())
+    fatal("invalid bitcode file: " + F.getName() + " has no datalayout");
 
   // If a symbol appears in @llvm.used, the linker is required
   // to treat the symbol as there is a reference to the symbol

Added: lld/trunk/test/ELF/lto/invalid-bitcode.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/invalid-bitcode.ll?rev=266504&view=auto
==============================================================================
--- lld/trunk/test/ELF/lto/invalid-bitcode.ll (added)
+++ lld/trunk/test/ELF/lto/invalid-bitcode.ll Fri Apr 15 20:33:33 2016
@@ -0,0 +1,12 @@
+; REQUIRES: x86
+; RUN: llvm-as %s -o %t.o
+; RUN: not ld.lld -m elf_x86_64 %t.o 2>&1 | FileCheck %s
+
+; CHECK: invalid bitcode file:
+
+; This bitcode file has no datalayout.
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @_start() {
+  ret void
+}




More information about the llvm-commits mailing list