[PATCH] D128067: [llvm-ar] Fix MRI ADDLIB command when used with thin archives

Owen Reynolds via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 24 09:45:29 PDT 2022


gbreynoo updated this revision to Diff 439802.
gbreynoo added a comment.

Updated with use of `--match-full-lines`.


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

https://reviews.llvm.org/D128067

Files:
  llvm/test/tools/llvm-ar/mri-thin-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
@@ -1064,6 +1064,8 @@
     case MRICommand::AddLib: {
       object::Archive &Lib = readLibrary(Rest);
       {
+        if (Thin && !Lib.isThin())
+          fail("cannot add a regular archive's contents to a thin archive");
         Error Err = Error::success();
         for (auto &Member : Lib.children(Err))
           addChildMember(NewMembers, Member, /*FlattenArchive=*/Thin);
Index: llvm/test/tools/llvm-ar/mri-thin-archive.test
===================================================================
--- llvm/test/tools/llvm-ar/mri-thin-archive.test
+++ llvm/test/tools/llvm-ar/mri-thin-archive.test
@@ -1,23 +1,47 @@
-RUN: rm -rf %t && mkdir -p %t/addlib/
+# UNSUPPORTED: system-aix
+# RUN: rm -rf %t && mkdir -p %t/addlib/ && split-file %s %t
+# RUN: cd %t
 
-RUN: yaml2obj %S/Inputs/elf.yaml -o %t/elf.o
-RUN: cp %t/elf.o %t/addlib/elf.o
-RUN: cp %t/elf.o %t/delete.o
+# RUN: yaml2obj %S/Inputs/elf.yaml -o %t/elf.o
+# RUN: cp %t/elf.o %t/addlib/elf.o
+# RUN: cp %t/elf.o %t/delete.o
 
-RUN: cd %t && llvm-ar rTc addlib/addlib.ar addlib/elf.o
+# RUN: llvm-ar rc --thin addlib/thin.ar addlib/elf.o
+# RUN: llvm-ar rc addlib/regular.ar addlib/elf.o
 
-RUN: echo "createthin %t/archive.ar" > %t/mri.script
-RUN: echo "addmod elf.o" >> %t/mri.script
-RUN: echo "addlib addlib/addlib.ar" >> %t/mri.script
-RUN: echo "addmod delete.o" >> %t/mri.script
-RUN: echo "delete delete.o" >> %t/mri.script
-RUN: echo "save" >> %t/mri.script
-RUN: echo "end" >> %t/mri.script
+# RUN: llvm-ar -M < thin.script
+# RUN: FileCheck -input-file=archive.ar %s --check-prefixes=THIN --implicit-check-not=delete.o --match-full-lines
 
-RUN: cd %t && llvm-ar -M < mri.script
-RUN: FileCheck -input-file=%t/archive.ar %s
+# THIN: !<thin>
+# THIN: elf.o/
+# THIN-NEXT: addlib/elf.o/
 
-CHECK: !<thin>
-CHECK: elf.o
-CHECK-NEXT: addlib/elf.o/
-CHECK-NOT: delete.o
+# RUN: llvm-ar -M < thin-to-regular.script
+# RUN: FileCheck -input-file=regular.ar %s --check-prefixes=REGULAR
+
+# REGULAR: !<arch>
+
+# RUN: not llvm-ar -M < regular-to-thin.script 2>&1 | FileCheck %s --check-prefix=ERROR
+# RUN: not ls thin.ar
+# ERROR: error: script line 2: cannot add a regular archive's contents to a thin archive
+
+#--- thin.script
+createthin archive.ar
+addmod elf.o
+addlib addlib/thin.ar
+addmod delete.o
+delete delete.o
+save
+end
+
+#--- thin-to-regular.script
+create regular.ar
+addlib addlib/thin.ar
+save
+end
+
+#--- regular-to-thin.script
+createthin thin.ar
+addlib addlib/regular.ar
+save
+end


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128067.439802.patch
Type: text/x-patch
Size: 2657 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220624/8dbb29e1/attachment.bin>


More information about the llvm-commits mailing list