[llvm] d17c54d - [llvm-ar] Prevent automatic conversion from thin to full archive
via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 3 03:46:15 PST 2022
Author: gbreynoo
Date: 2022-02-03T11:45:21Z
New Revision: d17c54d17de22d2961a04163f3dbc8e973de89b8
URL: https://github.com/llvm/llvm-project/commit/d17c54d17de22d2961a04163f3dbc8e973de89b8
DIFF: https://github.com/llvm/llvm-project/commit/d17c54d17de22d2961a04163f3dbc8e973de89b8.diff
LOG: [llvm-ar] Prevent automatic conversion from thin to full archive
llvm-ar silently converts a thin archive to a regular archive when you
specify a modification operation (e.g. 'r') without the 'T' modifier.
This change stops this from occuring. If a user is trying to convert
between thin and full archives then they can explicitly use the 'L'
command to createa new archive.
Differential Revision: https://reviews.llvm.org/D118693
Added:
llvm/test/tools/llvm-ar/thin-to-full-archive.test
Modified:
llvm/test/tools/llvm-ar/full-to-thin-archive.test
llvm/tools/llvm-ar/llvm-ar.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-ar/full-to-thin-archive.test b/llvm/test/tools/llvm-ar/full-to-thin-archive.test
index 6853005a32f86..511e0cb743322 100644
--- a/llvm/test/tools/llvm-ar/full-to-thin-archive.test
+++ b/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>
diff --git a/llvm/test/tools/llvm-ar/thin-to-full-archive.test b/llvm/test/tools/llvm-ar/thin-to-full-archive.test
new file mode 100644
index 0000000000000..bbe5302853648
--- /dev/null
+++ b/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>
diff --git a/llvm/tools/llvm-ar/llvm-ar.cpp b/llvm/tools/llvm-ar/llvm-ar.cpp
index 8842162f5216b..6ab5bf7e9c281 100644
--- a/llvm/tools/llvm-ar/llvm-ar.cpp
+++ b/llvm/tools/llvm-ar/llvm-ar.cpp
@@ -654,6 +654,11 @@ static void addChildMember(std::vector<NewArchiveMember> &Members,
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());
More information about the llvm-commits
mailing list