Don't accept unsuitable ELF files such as executables or core files.

Differential Revision: https://reviews.llvm.org/D42827

llvm-svn: 324041
This commit is contained in:
Rui Ueyama 2018-02-02 00:27:49 +00:00
parent 42bcdffd24
commit d0de239f70
4 changed files with 14 additions and 6 deletions

View File

@ -228,11 +228,15 @@ void LinkerDriver::addFile(StringRef Path, bool WithLOption) {
Files.push_back(
createSharedFile(MBRef, WithLOption ? path::filename(Path) : Path));
return;
default:
case file_magic::bitcode:
case file_magic::elf_relocatable:
if (InLib)
Files.push_back(make<LazyObjFile>(MBRef, "", 0));
else
Files.push_back(createObjectFile(MBRef));
break;
default:
error(Path + ": unknown file type");
}
}

View File

@ -0,0 +1,9 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
# RUN: ld.lld -o %t1.exe %t.o
# RUN: not ld.lld -o %t2.exe %t1.exe 2>&1 | FileCheck %s
# CHECK: unknown file type
.global _start
_start:
ret

View File

@ -1,5 +0,0 @@
# REQUIRES: x86
## too-short.elf file is a truncated ELF.
# RUN: not ld.lld %S/Inputs/too-short.elf -o %t 2>&1 | FileCheck %s
# CHECK: file is too short