[PATCH] D118693: [llvm-ar] Prevent automatic conversion from thin to full archive

Owen Reynolds via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 3 03:46:26 PST 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rGd17c54d17de2: [llvm-ar] Prevent automatic conversion from thin to full archive (authored by gbreynoo).

Changed prior to commit:
  https://reviews.llvm.org/D118693?vs=404878&id=405571#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118693/new/

https://reviews.llvm.org/D118693

Files:
  llvm/test/tools/llvm-ar/full-to-thin-archive.test
  llvm/test/tools/llvm-ar/thin-to-full-archive.test
  llvm/tools/llvm-ar/llvm-ar.cpp


Index: llvm/tools/llvm-ar/llvm-ar.cpp
===================================================================
--- llvm/tools/llvm-ar/llvm-ar.cpp
+++ llvm/tools/llvm-ar/llvm-ar.cpp
@@ -654,6 +654,11 @@
                            bool FlattenArchive = false) {
   if (Thin && !M.getParent()->isThin())
     fail("cannot convert a regular archive to a thin one");
+
+  // Avoid converting an existing thin archive to a regular one.
+  if (!AddLibrary && M.getParent()->isThin())
+    Thin = true;
+
   Expected<NewArchiveMember> NMOrErr =
       NewArchiveMember::getOldMember(M, Deterministic);
   failIfError(NMOrErr.takeError());
Index: llvm/test/tools/llvm-ar/thin-to-full-archive.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-ar/thin-to-full-archive.test
@@ -0,0 +1,26 @@
+## Test thin archives do not siletly convert to full archives on write.
+
+# RUN: rm -f %tthin.a %tfull.a 
+
+# RUN: llvm-ar -Trc %tthin.a %S/Inputs/a.txt
+# RUN: FileCheck --check-prefixes=THIN --input-file=%tthin.a %s
+
+# RUN: llvm-ar -q %tthin.a %S/Inputs/b.txt
+# RUN: FileCheck --check-prefixes=THIN --input-file=%tthin.a %s
+
+# RUN: llvm-ar -r %tthin.a %S/Inputs/c.txt
+# RUN: FileCheck --check-prefixes=THIN --input-file=%tthin.a %s
+
+# RUN: llvm-ar -am %S/Inputs/a.txt %tthin.a %S/Inputs/c.txt
+# RUN: FileCheck --check-prefixes=THIN --input-file=%tthin.a %s
+
+# RUN: llvm-ar -d %tthin.a %S/Inputs/c.txt
+# RUN: FileCheck --check-prefixes=THIN --input-file=%tthin.a %s
+
+THIN: !<thin>
+
+## Test that you can add a thin archive's contents to a full archive with 'L'
+# RUN: llvm-ar -qcL %tfull.a %tthin.a
+# RUN: FileCheck --check-prefixes=FULL --input-file=%tfull.a %s
+
+FULL: !<arch>
Index: llvm/test/tools/llvm-ar/full-to-thin-archive.test
===================================================================
--- llvm/test/tools/llvm-ar/full-to-thin-archive.test
+++ llvm/test/tools/llvm-ar/full-to-thin-archive.test
@@ -6,3 +6,9 @@
 # RUN: not llvm-ar rT %t/archive.a %s 2>&1 | FileCheck %s
 
 # CHECK: error: cannot convert a regular archive to a thin one
+
+## Test that you can add a full archive's contents to a thin archive with 'L'
+# RUN: llvm-ar -TqcL %t/thin.a %t/archive.a
+# RUN: FileCheck --check-prefixes=THIN --input-file=%t/thin.a %s
+
+THIN: !<thin>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118693.405571.patch
Type: text/x-patch
Size: 2321 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220203/d3bbdc56/attachment.bin>


More information about the llvm-commits mailing list