Skip to content

Commit dd6e7e0

Browse files
committedFeb 1, 2022
[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
1 parent 83620bd commit dd6e7e0

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed
 

‎llvm/docs/CommandGuide/llvm-ar.rst

+8-4
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,8 @@ section to determine which modifiers are applicable to which operations.
201201

202202
.. option:: T
203203

204-
When creating or modifying an archive, this option specifies that the
205-
``archive`` will be thin. By default, archives are not created as thin
206-
archives and when modifying a thin archive, it will be converted to a regular
207-
archive.
204+
Alias for ``--thin``. In many ar implementations ``T`` has a different
205+
meaning, as specified by X/Open System interface.
208206

209207
.. option:: v
210208

@@ -281,6 +279,12 @@ Other
281279
``posix`` or ``windows``. The default when on Windows is ``windows``, otherwise the
282280
default is ``posix``.
283281

282+
.. option:: --thin
283+
284+
When creating or modifying an archive, this option specifies that the
285+
``archive`` will be thin. By default, archives are not created as thin archives
286+
and when modifying a thin archive, it will be converted to a regular archive.
287+
284288
.. option:: --version
285289

286290
Display the version of the :program:`llvm-ar` executable.

‎llvm/test/tools/llvm-ar/thin-archive.test

+8-4
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ RUN: cp %t/foo/bar/elf.o %t/delete.o
66

77
Test that modules can be added with absolute paths when the archive is created using an absolute path
88

9-
RUN: llvm-ar rTc %t/absolute-1.ar %t/foo/elf.o %t/delete.o %t/foo/bar/elf.o
10-
RUN: llvm-ar dT %t/absolute-1.ar delete.o
9+
RUN: llvm-ar rc --thin %t/absolute-1a.ar %t/foo/elf.o %t/delete.o %t/foo/bar/elf.o
10+
RUN: llvm-ar --thin d %t/absolute-1a.ar delete.o
1111

12-
RUN: FileCheck -input-file=%t/absolute-1.ar --check-prefixes=THIN,CHECK %s -DPATH=%/t/
13-
RUN: llvm-ar t %t/absolute-1.ar | FileCheck %s -DPATH=%/t/
12+
RUN: FileCheck --input-file=%t/absolute-1a.ar --check-prefixes=THIN,CHECK %s -DPATH=%/t/
13+
RUN: llvm-ar t %t/absolute-1a.ar | FileCheck %s -DPATH=%/t/
14+
15+
RUN: llvm-ar rTc %t/absolute-1b.ar %t/foo/elf.o %t/delete.o %t/foo/bar/elf.o
16+
RUN: llvm-ar dT %t/absolute-1b.ar delete.o
17+
RUN: cmp %t/absolute-1a.ar %t/absolute-1b.ar
1418

1519
These tests must be run in %t/foo. cd %t is included on each line to make debugging this test case easier.
1620

‎llvm/tools/llvm-ar/llvm-ar.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ USAGE: llvm-ar [options] [-]<operation>[modifiers] [relpos] [count] <archive> [f
9090
--rsp-quoting - quoting style for response files
9191
=posix - posix
9292
=windows - windows
93+
--thin - create a thin archive
9394
--version - print the version and exit
9495
@<file> - read options from <file>
9596
@@ -118,7 +119,7 @@ USAGE: llvm-ar [options] [-]<operation>[modifiers] [relpos] [count] <archive> [f
118119
[P] - use full names when matching (implied for thin archives)
119120
[s] - create an archive index (cf. ranlib)
120121
[S] - do not build a symbol table
121-
[T] - create a thin archive
122+
[T] - deprecated, use --thin instead
122123
[u] - update only [files] newer than archive contents
123124
[U] - use actual timestamps and uids/gids
124125
[v] - be verbose about actions taken
@@ -390,8 +391,6 @@ static ArchiveOperation parseCommandLine() {
390391
break;
391392
case 'T':
392393
Thin = true;
393-
// Thin archives store path names, so P should be forced.
394-
CompareFullPath = true;
395394
break;
396395
case 'L':
397396
AddLibrary = true;
@@ -407,6 +406,10 @@ static ArchiveOperation parseCommandLine() {
407406
}
408407
}
409408

409+
// Thin archives store path names, so P should be forced.
410+
if (Thin)
411+
CompareFullPath = true;
412+
410413
// At this point, the next thing on the command line must be
411414
// the archive name.
412415
getArchive();
@@ -1202,6 +1205,11 @@ static int ar_main(int argc, char **argv) {
12021205
continue;
12031206
}
12041207

1208+
if (strcmp(*ArgIt, "--thin") == 0) {
1209+
Thin = true;
1210+
continue;
1211+
}
1212+
12051213
Match = matchFlagWithArg("format", ArgIt, Argv);
12061214
if (Match) {
12071215
FormatType = StringSwitch<Format>(Match)

0 commit comments

Comments
 (0)
Please sign in to comment.