diff --git a/llvm/test/tools/llvm-ar/mri-thin-archive.test b/llvm/test/tools/llvm-ar/mri-thin-archive.test --- a/llvm/test/tools/llvm-ar/mri-thin-archive.test +++ b/llvm/test/tools/llvm-ar/mri-thin-archive.test @@ -1,23 +1,50 @@ -RUN: rm -rf %t && mkdir -p %t/addlib/ +# RUN: rm -rf %t +# RUN: split-file %s %t +# RUN: mkdir -p %t/addlib/ +# 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 rTc 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 -RUN: cd %t && llvm-ar -M < mri.script -RUN: FileCheck -input-file=%t/archive.ar %s +# CHECK: ! +# CHECK: elf.o +# CHECK-NEXT: addlib/elf.o/ +# CHECK-NOT: delete.o -CHECK: ! -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: ! +# REGULAR: elf.o + +# 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 archives 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 --- a/llvm/tools/llvm-ar/llvm-ar.cpp +++ b/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 archives contents to a thin archive"); Error Err = Error::success(); for (auto &Member : Lib.children(Err)) addChildMember(NewMembers, Member, /*FlattenArchive=*/Thin);