From 493b683f79b95b6745bc59641b79da830b413bff Mon Sep 17 00:00:00 2001 From: Davide Italiano Date: Sat, 16 Apr 2016 01:33:33 +0000 Subject: [PATCH] [LTO] Don't crash on a BitcodeFile without DataLayout. Emit an error instead. llvm-svn: 266504 --- lld/ELF/LTO.cpp | 2 ++ lld/test/ELF/lto/invalid-bitcode.ll | 12 ++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 lld/test/ELF/lto/invalid-bitcode.ll diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp index a4ef9b6..6fe4e11 100644 --- a/lld/ELF/LTO.cpp +++ b/lld/ELF/LTO.cpp @@ -82,6 +82,8 @@ void BitcodeCompiler::add(BitcodeFile &F) { ArrayRef 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 diff --git a/lld/test/ELF/lto/invalid-bitcode.ll b/lld/test/ELF/lto/invalid-bitcode.ll new file mode 100644 index 0000000..eceffb1 --- /dev/null +++ b/lld/test/ELF/lto/invalid-bitcode.ll @@ -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 +} -- 2.7.4