[llvm] r289726 - LibDriver: Reject inputs that are not COFF objects or bitcode files.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 14 14:19:22 PST 2016


Author: pcc
Date: Wed Dec 14 16:19:22 2016
New Revision: 289726

URL: http://llvm.org/viewvc/llvm-project?rev=289726&view=rev
Log:
LibDriver: Reject inputs that are not COFF objects or bitcode files.

Fixes PR31372.

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

Added:
    llvm/trunk/test/LibDriver/Inputs/cl-gl.obj   (with props)
    llvm/trunk/test/LibDriver/invalid.test
Modified:
    llvm/trunk/lib/LibDriver/LibDriver.cpp
    llvm/trunk/test/LibDriver/thin.test

Modified: llvm/trunk/lib/LibDriver/LibDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LibDriver/LibDriver.cpp?rev=289726&r1=289725&r2=289726&view=diff
==============================================================================
--- llvm/trunk/lib/LibDriver/LibDriver.cpp (original)
+++ llvm/trunk/lib/LibDriver/LibDriver.cpp Wed Dec 14 16:19:22 2016
@@ -143,6 +143,13 @@ int llvm::libDriverMain(llvm::ArrayRef<c
       });
       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));
   }
 

Added: llvm/trunk/test/LibDriver/Inputs/cl-gl.obj
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LibDriver/Inputs/cl-gl.obj?rev=289726&view=auto
==============================================================================
Binary file - no diff available.

Propchange: llvm/trunk/test/LibDriver/Inputs/cl-gl.obj
------------------------------------------------------------------------------
    svn:executable = *

Propchange: llvm/trunk/test/LibDriver/Inputs/cl-gl.obj
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: llvm/trunk/test/LibDriver/invalid.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LibDriver/invalid.test?rev=289726&view=auto
==============================================================================
--- llvm/trunk/test/LibDriver/invalid.test (added)
+++ llvm/trunk/test/LibDriver/invalid.test Wed Dec 14 16:19:22 2016
@@ -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

Modified: llvm/trunk/test/LibDriver/thin.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LibDriver/thin.test?rev=289726&r1=289725&r2=289726&view=diff
==============================================================================
--- llvm/trunk/test/LibDriver/thin.test (original)
+++ llvm/trunk/test/LibDriver/thin.test Wed Dec 14 16:19:22 2016
@@ -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




More information about the llvm-commits mailing list