[llvm] 1f71b5a - [llvm-ar] Fix thin archive being wrongly converted to a full archive
via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 21 07:49:23 PDT 2022
Author: gbreynoo
Date: 2022-04-21T15:48:26+01:00
New Revision: 1f71b5a38605a4f101af43288ae22feb89c8a469
URL: https://github.com/llvm/llvm-project/commit/1f71b5a38605a4f101af43288ae22feb89c8a469
DIFF: https://github.com/llvm/llvm-project/commit/1f71b5a38605a4f101af43288ae22feb89c8a469.diff
LOG: [llvm-ar] Fix thin archive being wrongly converted to a full archive
When using the L option to quick append a full archive to a thin
archive, the thin archive was being wrongly converted to a full archive.
I've fixed the issue and added a check for it in
thin-to-full-archive.test and expanded some tests.
Differential Revision: https://reviews.llvm.org/D123142
Added:
Modified:
llvm/test/tools/llvm-ar/flatten-thin-archive.test
llvm/test/tools/llvm-ar/regular-to-thin-archive.test
llvm/test/tools/llvm-ar/thin-to-regular-archive.test
llvm/tools/llvm-ar/llvm-ar.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-ar/flatten-thin-archive.test b/llvm/test/tools/llvm-ar/flatten-thin-archive.test
index 3d228ce609df7..865d9f199289a 100644
--- a/llvm/test/tools/llvm-ar/flatten-thin-archive.test
+++ b/llvm/test/tools/llvm-ar/flatten-thin-archive.test
@@ -11,8 +11,9 @@
# RUN: llvm-ar rcs --thin %t-a-plus-b.a %t-a.txt %t-b.txt
# RUN: llvm-ar rcs %t-d-plus-e.a %t-d.txt %t-e.txt
# RUN: llvm-ar rcs --thin %t.a %t-a-plus-b.a %t-c.txt %t-d-plus-e.a
-# RUN: llvm-ar t %t.a | FileCheck %s
+# RUN: FileCheck --input-file=%t.a %s
+# CHECK: !<thin>
# CHECK: a.txt
# CHECK-NEXT: b.txt
# CHECK-NEXT: c.txt
diff --git a/llvm/test/tools/llvm-ar/regular-to-thin-archive.test b/llvm/test/tools/llvm-ar/regular-to-thin-archive.test
index 65e7aa9211eb5..f216e47b2c6d4 100644
--- a/llvm/test/tools/llvm-ar/regular-to-thin-archive.test
+++ b/llvm/test/tools/llvm-ar/regular-to-thin-archive.test
@@ -2,14 +2,28 @@
## Test regular archives do not convert to thin archives.
# RUN: rm -rf %t && mkdir -p %t
-# RUN: llvm-ar qc %t/archive.a %s
+# RUN: llvm-ar qc %t/archive.a %S/Inputs/a.txt
# RUN: not llvm-ar q --thin %t/archive.a %s 2>&1 | FileCheck %s
# RUN: not llvm-ar r --thin %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 regular archive's contents to a thin archive with 'L'
-# RUN: llvm-ar -qcL --thin %t/thin.a %t/archive.a
-# RUN: FileCheck --check-prefixes=THIN --input-file=%t/thin.a %s
+## Test that you can add a regular archive to a new thin archive with 'L'.
+# RUN: llvm-ar -qcL --thin %t/thin1.a %S/Inputs/b.txt %t/archive.a
+# RUN: FileCheck --check-prefixes=THIN --input-file=%t/thin1.a %s
-THIN: !<thin>
+## Test that you can add a regular archive to an existing thin archive with 'L'.
+# RUN: llvm-ar -qc --thin %t/thin2.a %S/Inputs/b.txt
+# RUN: llvm-ar -qL --thin %t/thin2.a %t/archive.a
+# RUN: FileCheck --check-prefixes=THIN --input-file=%t/thin2.a %s
+
+# THIN: !<thin>
+# THIN: archive.a
+
+## Test archives do not convert to thin archives with use of 'L' and '--thin'.
+# RUN: not llvm-ar -qL --thin %t/archive.a %t/thin2.a 2>&1 | FileCheck %s
+
+## Test that a regular archive can be read despite use of --thin
+# RUN: llvm-ar -t --thin %t/archive.a
+# RUN: FileCheck --check-prefixes=REGULAR --input-file=%t/archive.a %s
+# REGULAR: !<arch>
diff --git a/llvm/test/tools/llvm-ar/thin-to-regular-archive.test b/llvm/test/tools/llvm-ar/thin-to-regular-archive.test
index 08b2e5253deeb..00af9414ab6d2 100644
--- a/llvm/test/tools/llvm-ar/thin-to-regular-archive.test
+++ b/llvm/test/tools/llvm-ar/thin-to-regular-archive.test
@@ -1,7 +1,7 @@
# XFAIL: system-aix
## Test thin archives do not siletly convert to regular archives on write.
-# RUN: rm -f %tthin.a %tregular.a
+# RUN: rm -f %tthin.a %tregular1.a %tregular2.a
# RUN: llvm-ar -rc --thin %tthin.a %S/Inputs/a.txt
# RUN: FileCheck --check-prefixes=THIN --input-file=%tthin.a %s
@@ -20,8 +20,19 @@
# THIN: !<thin>
-## Test that you can add a thin archive's contents to a regular archive with 'L'
-# RUN: llvm-ar -qcL %tregular.a %tthin.a
-# RUN: FileCheck --check-prefixes=REGULAR --input-file=%tregular.a %s
+## Test that you can add a thin archive's contents to a regular archive with 'L'.
+# RUN: llvm-ar -qcL %tregular1.a %tthin.a
+# RUN: FileCheck --check-prefixes=REGULAR --input-file=%tregular1.a --implicit-check-not=thin.a %s
-REGULAR: !<arch>
+# REGULAR: !<arch>
+# REGULAR: a.txt
+# REGULAR: b.txt
+
+## Test that you can add a thin archive's contents to an existing regular archive with 'L'.
+# RUN: llvm-ar -q %tregular2.a %S/Inputs/d.txt
+# RUN: llvm-ar -qL %tregular2.a %tthin.a
+# RUN: FileCheck --check-prefixes=REGULAR --input-file=%tregular2.a %s
+
+## Test that thin archives do not convert to regular archives with 'L' and no use of '--thin'.
+# RUN: llvm-ar -qL %tthin.a %tregular2.a
+# RUN: FileCheck --check-prefixes=THIN --input-file=%tthin.a %s
diff --git a/llvm/tools/llvm-ar/llvm-ar.cpp b/llvm/tools/llvm-ar/llvm-ar.cpp
index 0d87e25edb426..2b0288321834d 100644
--- a/llvm/tools/llvm-ar/llvm-ar.cpp
+++ b/llvm/tools/llvm-ar/llvm-ar.cpp
@@ -653,13 +653,6 @@ static void performReadOperation(ArchiveOperation Operation,
static void addChildMember(std::vector<NewArchiveMember> &Members,
const object::Archive::Child &M,
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());
@@ -927,6 +920,14 @@ static void performWriteOperation(ArchiveOperation Operation,
object::Archive *OldArchive,
std::unique_ptr<MemoryBuffer> OldArchiveBuf,
std::vector<NewArchiveMember> *NewMembersP) {
+ if (OldArchive) {
+ if (Thin && !OldArchive->isThin())
+ fail("cannot convert a regular archive to a thin one");
+
+ if (OldArchive->isThin())
+ Thin = true;
+ }
+
std::vector<NewArchiveMember> NewMembers;
if (!NewMembersP)
NewMembers = computeNewArchiveMembers(Operation, OldArchive);
More information about the llvm-commits
mailing list