llvm-ar: Don't try to extract from thin archives.
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 14 Jul 2015 16:55:13 +0000 (16:55 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 14 Jul 2015 16:55:13 +0000 (16:55 +0000)
This matches the gnu ar behavior.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242162 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Object/Archive.h
test/Object/archive-extract.test
tools/llvm-ar/llvm-ar.cpp

index 0745eaf5c6e50c701d485ded4f1544567320fd58..e461564ace8e092b9a5edd9fed9d9b1af1555ecd 100644 (file)
@@ -183,6 +183,7 @@ public:
   };
 
   Kind kind() const { return (Kind)Format; }
+  bool isThin() const { return IsThin; }
 
   child_iterator child_begin(bool SkipInternal = true) const;
   child_iterator child_end() const;
index 606fc753c3358482099919eb487ed050fe9aca8c..c1ddcf717257aa7e0a62ab2fad5b10821994f0b5 100644 (file)
@@ -45,3 +45,6 @@ CHECK: 1465 2004-11-19 03:01:31.000000000 very_long_bytecode_file_name.bc
 
 RUN: not llvm-ar x %p/Inputs/GNU.a foo.o 2>&1 | FileCheck --check-prefix=NOTFOUND %s
 NOTFOUND: foo.o was not found
+
+RUN: not llvm-ar x %p/Inputs/thin.a foo.o 2>&1 | FileCheck %s --check-prefix=THINEXTRACT
+THINEXTRACT: extracting from a thin archive is not supported
index 50ddf598efee0ab36be5735bb569d6405add3366..c87606d7826891162ccdfdec3637338b4aac0402 100644 (file)
@@ -391,6 +391,11 @@ static bool shouldCreateArchive(ArchiveOperation Op) {
 
 static void performReadOperation(ArchiveOperation Operation,
                                  object::Archive *OldArchive) {
+  if (Operation == Extract && OldArchive->isThin()) {
+    errs() << "extracting from a thin archive is not supported\n";
+    std::exit(1);
+  }
+
   bool Filter = !Members.empty();
   for (const object::Archive::Child &C : OldArchive->children()) {
     ErrorOr<StringRef> NameOrErr = C.getName();