[llvm] 6a1e5f5 - [llvm-ar] Fix MRI ADDLIB command when used with thin archives

via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 27 09:11:30 PDT 2022


Author: gbreynoo
Date: 2022-06-27T17:10:11+01:00
New Revision: 6a1e5f5a7111ce07a3beb8be366b63ea10fa56f4

URL: https://github.com/llvm/llvm-project/commit/6a1e5f5a7111ce07a3beb8be366b63ea10fa56f4
DIFF: https://github.com/llvm/llvm-project/commit/6a1e5f5a7111ce07a3beb8be366b63ea10fa56f4.diff

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

We did not properly handle using CREATETHIN in an MRI script and
attempting to use ADDLIB to add the contents of a regular archive. This
fix outputs a meaningful error message in this case and provides some
more testing.

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

Added: 
    

Modified: 
    llvm/test/tools/llvm-ar/mri-thin-archive.test
    llvm/tools/llvm-ar/llvm-ar.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-ar/mri-thin-archive.test b/llvm/test/tools/llvm-ar/mri-thin-archive.test
index e759a9a25f283..8010cb998beb9 100644
--- a/llvm/test/tools/llvm-ar/mri-thin-archive.test
+++ b/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

diff  --git a/llvm/tools/llvm-ar/llvm-ar.cpp b/llvm/tools/llvm-ar/llvm-ar.cpp
index b4f5e5b05762e..29b41ecf48334 100644
--- a/llvm/tools/llvm-ar/llvm-ar.cpp
+++ b/llvm/tools/llvm-ar/llvm-ar.cpp
@@ -1066,6 +1066,8 @@ static void runMRIScript() {
         fail("no output archive has been opened");
       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);


        


More information about the llvm-commits mailing list