[llvm] dd6e7e0 - [llvm-ar] Add --thin for creating a thin archive
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 1 09:56:54 PST 2022
Author: Fangrui Song
Date: 2022-02-01T09:56:50-08:00
New Revision: dd6e7e0d5722d6396f8a0e94146f0b5e50dfa028
URL: https://github.com/llvm/llvm-project/commit/dd6e7e0d5722d6396f8a0e94146f0b5e50dfa028
DIFF: https://github.com/llvm/llvm-project/commit/dd6e7e0d5722d6396f8a0e94146f0b5e50dfa028.diff
LOG: [llvm-ar] Add --thin for creating a thin archive
In GNU ar (since 2008), the modifier 'T' means creating a thin archive.
In many other ar implementations (FreeBSD, macOS, elfutils, etc), -T
means "allow filename truncation of extracted files", as specified by
X/Open System Interface.
For portability, 'T' with thin archive semantics should be avoided.
See https://sourceware.org/bugzilla/show_bug.cgi?id=28759 binutils 2.38
will deprecate 'T' (without diagnostic) and add --thin.
Reviewed By: jhenderson
Differential Revision: https://reviews.llvm.org/D116979
Added:
Modified:
llvm/docs/CommandGuide/llvm-ar.rst
llvm/test/tools/llvm-ar/thin-archive.test
llvm/tools/llvm-ar/llvm-ar.cpp
Removed:
################################################################################
diff --git a/llvm/docs/CommandGuide/llvm-ar.rst b/llvm/docs/CommandGuide/llvm-ar.rst
index f1385ad0c5685..0f3625274fa70 100644
--- a/llvm/docs/CommandGuide/llvm-ar.rst
+++ b/llvm/docs/CommandGuide/llvm-ar.rst
@@ -201,10 +201,8 @@ section to determine which modifiers are applicable to which operations.
.. option:: T
- When creating or modifying an archive, this option specifies that the
- ``archive`` will be thin. By default, archives are not created as thin
- archives and when modifying a thin archive, it will be converted to a regular
- archive.
+ Alias for ``--thin``. In many ar implementations ``T`` has a
diff erent
+ meaning, as specified by X/Open System interface.
.. option:: v
@@ -281,6 +279,12 @@ Other
``posix`` or ``windows``. The default when on Windows is ``windows``, otherwise the
default is ``posix``.
+.. option:: --thin
+
+ When creating or modifying an archive, this option specifies that the
+ ``archive`` will be thin. By default, archives are not created as thin archives
+ and when modifying a thin archive, it will be converted to a regular archive.
+
.. option:: --version
Display the version of the :program:`llvm-ar` executable.
diff --git a/llvm/test/tools/llvm-ar/thin-archive.test b/llvm/test/tools/llvm-ar/thin-archive.test
index fca8e1176234c..d62f9ae18db91 100644
--- a/llvm/test/tools/llvm-ar/thin-archive.test
+++ b/llvm/test/tools/llvm-ar/thin-archive.test
@@ -6,11 +6,15 @@ RUN: cp %t/foo/bar/elf.o %t/delete.o
Test that modules can be added with absolute paths when the archive is created using an absolute path
-RUN: llvm-ar rTc %t/absolute-1.ar %t/foo/elf.o %t/delete.o %t/foo/bar/elf.o
-RUN: llvm-ar dT %t/absolute-1.ar delete.o
+RUN: llvm-ar rc --thin %t/absolute-1a.ar %t/foo/elf.o %t/delete.o %t/foo/bar/elf.o
+RUN: llvm-ar --thin d %t/absolute-1a.ar delete.o
-RUN: FileCheck -input-file=%t/absolute-1.ar --check-prefixes=THIN,CHECK %s -DPATH=%/t/
-RUN: llvm-ar t %t/absolute-1.ar | FileCheck %s -DPATH=%/t/
+RUN: FileCheck --input-file=%t/absolute-1a.ar --check-prefixes=THIN,CHECK %s -DPATH=%/t/
+RUN: llvm-ar t %t/absolute-1a.ar | FileCheck %s -DPATH=%/t/
+
+RUN: llvm-ar rTc %t/absolute-1b.ar %t/foo/elf.o %t/delete.o %t/foo/bar/elf.o
+RUN: llvm-ar dT %t/absolute-1b.ar delete.o
+RUN: cmp %t/absolute-1a.ar %t/absolute-1b.ar
These tests must be run in %t/foo. cd %t is included on each line to make debugging this test case easier.
diff --git a/llvm/tools/llvm-ar/llvm-ar.cpp b/llvm/tools/llvm-ar/llvm-ar.cpp
index f7b29b8840277..1ece120c2331a 100644
--- a/llvm/tools/llvm-ar/llvm-ar.cpp
+++ b/llvm/tools/llvm-ar/llvm-ar.cpp
@@ -90,6 +90,7 @@ USAGE: llvm-ar [options] [-]<operation>[modifiers] [relpos] [count] <archive> [f
--rsp-quoting - quoting style for response files
=posix - posix
=windows - windows
+ --thin - create a thin archive
--version - print the version and exit
@<file> - read options from <file>
@@ -118,7 +119,7 @@ USAGE: llvm-ar [options] [-]<operation>[modifiers] [relpos] [count] <archive> [f
[P] - use full names when matching (implied for thin archives)
[s] - create an archive index (cf. ranlib)
[S] - do not build a symbol table
- [T] - create a thin archive
+ [T] - deprecated, use --thin instead
[u] - update only [files] newer than archive contents
[U] - use actual timestamps and uids/gids
[v] - be verbose about actions taken
@@ -390,8 +391,6 @@ static ArchiveOperation parseCommandLine() {
break;
case 'T':
Thin = true;
- // Thin archives store path names, so P should be forced.
- CompareFullPath = true;
break;
case 'L':
AddLibrary = true;
@@ -407,6 +406,10 @@ static ArchiveOperation parseCommandLine() {
}
}
+ // Thin archives store path names, so P should be forced.
+ if (Thin)
+ CompareFullPath = true;
+
// At this point, the next thing on the command line must be
// the archive name.
getArchive();
@@ -1202,6 +1205,11 @@ static int ar_main(int argc, char **argv) {
continue;
}
+ if (strcmp(*ArgIt, "--thin") == 0) {
+ Thin = true;
+ continue;
+ }
+
Match = matchFlagWithArg("format", ArgIt, Argv);
if (Match) {
FormatType = StringSwitch<Format>(Match)
More information about the llvm-commits
mailing list