[PATCH] D88693: [llvm-ar] Reject bitcode which can't be parsed.

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 1 12:18:39 PDT 2020


efriedma created this revision.
efriedma added a reviewer: MaskRay.
Herald added subscribers: rupprecht, hiraditya.
Herald added a project: LLVM.
efriedma requested review of this revision.

If llvm-ar is older than the compiler that produced the bitcode, we should produce an error message, instead of silently generating a corrupt archive. This has, unfortunately, bit me multiple times now.

Doing this only for bitcode for now; I'm not confident that the "magic" detection in other cases is good enough to avoid compatibility issues in other cases, and other cases are much less likely to cause trouble anyway.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88693

Files:
  llvm/lib/Object/ArchiveWriter.cpp
  llvm/test/tools/llvm-ar/invalid-bitcode.test


Index: llvm/test/tools/llvm-ar/invalid-bitcode.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-ar/invalid-bitcode.test
@@ -0,0 +1,2 @@
+; RUN: printf "\xDE\xC0\x17\x0B" > %t.o
+; RUN: not llvm-ar cr %t.a %t.o 2>&1 | grep "Invalid bitcode wrapper header"
Index: llvm/lib/Object/ArchiveWriter.cpp
===================================================================
--- llvm/lib/Object/ArchiveWriter.cpp
+++ llvm/lib/Object/ArchiveWriter.cpp
@@ -362,11 +362,8 @@
   if (identify_magic(Buf.getBuffer()) == file_magic::bitcode) {
     auto ObjOrErr = object::SymbolicFile::createSymbolicFile(
         Buf, file_magic::bitcode, &Context);
-    if (!ObjOrErr) {
-      // FIXME: check only for "not an object file" errors.
-      consumeError(ObjOrErr.takeError());
-      return Ret;
-    }
+    if (auto E = ObjOrErr.takeError())
+      return std::move(E);
     Obj = std::move(*ObjOrErr);
   } else {
     auto ObjOrErr = object::SymbolicFile::createSymbolicFile(Buf);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88693.295646.patch
Type: text/x-patch
Size: 1031 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201001/8d5a01d9/attachment.bin>


More information about the llvm-commits mailing list