LibDriver: Reject inputs that are not COFF objects or bitcode files.

Fixes PR31372.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289726 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Peter Collingbourne 2016-12-14 22:19:22 +00:00
parent ca0bb7af02
commit f87c88ec75
4 changed files with 10 additions and 1 deletions

View File

@ -143,6 +143,13 @@ int llvm::libDriverMain(llvm::ArrayRef<const char*> ArgsArr) {
});
return 1;
}
sys::fs::file_magic Magic =
sys::fs::identify_magic(MOrErr->Buf->getBuffer());
if (Magic != sys::fs::file_magic::coff_object &&
Magic != sys::fs::file_magic::bitcode) {
llvm::errs() << Arg->getValue() << ": not a COFF object or bitcode file\n";
return 1;
}
Members.emplace_back(std::move(*MOrErr));
}

BIN
test/LibDriver/Inputs/cl-gl.obj Executable file

Binary file not shown.

View File

@ -0,0 +1,2 @@
RUN: not llvm-lib %S/Inputs/cl-gl.obj 2>&1 | FileCheck %s
CHECK: not a COFF object or bitcode file

View File

@ -1,4 +1,4 @@
RUN: echo foo > %t
RUN: llvm-mc -triple=x86_64-pc-windows-msvc -filetype=obj -o %t %S/Inputs/a.s
RUN: llvm-lib -out:%t.a %t
RUN: FileCheck --check-prefix=FAT %s < %t.a