[PATCH] ar: Add --thin for creating thin archives
Fangrui Song
maskray@google.com
Mon Jan 10 21:24:38 GMT 2022
In many ar implementations (FreeBSD, elfutils, etc), ar -T has the
X/Open System Interface specified semantics. Therefore -T for thin
archives is not recommended for portability.
PR binutils/28759
* ar.c (long_options): Add --thin.
* binutils/testsuite/binutils-all/ar.exp: Add tests.
* NEWS: Mention --thin.
---
binutils/NEWS | 4 ++++
binutils/ar.c | 1 +
binutils/testsuite/binutils-all/ar.exp | 17 +++++++++++++++++
3 files changed, 22 insertions(+)
diff --git a/binutils/NEWS b/binutils/NEWS
index 903f8233b99..9598930b581 100644
--- a/binutils/NEWS
+++ b/binutils/NEWS
@@ -18,6 +18,10 @@
* Support for efi-app-aarch64, efi-rtdrv-aarch64 and efi-bsdrv-aarch64 has been
added to objcopy in order to enable UEFI development using binutils.
+* ar: Add --thin for creating thin archives. -T is not recommended for
+ portability because in many ar implementations -T has a different meaning
+ from X/Open System Interface.
+
Changes in 2.37:
* The readelf tool has a new command line option which can be used to specify
diff --git a/binutils/ar.c b/binutils/ar.c
index d7d2fc21dd9..ba710ee426d 100644
--- a/binutils/ar.c
+++ b/binutils/ar.c
@@ -172,6 +172,7 @@ static struct option long_options[] =
{"version", no_argument, &show_version, 1},
{"output", required_argument, NULL, OPTION_OUTPUT},
{"record-libdeps", required_argument, NULL, 'l'},
+ {"thin", no_argument, NULL, 'T'},
{NULL, no_argument, NULL, 0}
};
diff --git a/binutils/testsuite/binutils-all/ar.exp b/binutils/testsuite/binutils-all/ar.exp
index 12aa079865b..3b841825f6f 100644
--- a/binutils/testsuite/binutils-all/ar.exp
+++ b/binutils/testsuite/binutils-all/ar.exp
@@ -309,11 +309,13 @@ proc thin_archive_with_nested { bfdtests } {
if [is_remote host] {
set archive artest.a
set archive2 artest2.a
+ set archive3 artest3.a
set objfile [remote_download host tmpdir/bintest.${obj}]
remote_file host delete $archive
} else {
set archive tmpdir/artest.a
set archive2 tmpdir/artest2.a
+ set archive3 tmpdir/artest3.a
set objfile tmpdir/bintest.${obj}
}
@@ -333,6 +335,14 @@ proc thin_archive_with_nested { bfdtests } {
return
}
+ remote_file build delete tmpdir/artest3.a
+
+ set got [binutils_run $AR "rc --thin $archive3 ${archive}"]
+ if ![string match "" $got] {
+ fail $testname
+ return
+ }
+
foreach bfdtest $bfdtests {
set exec_output [binutils_run "$base_dir/$bfdtest" "$archive"]
if ![string match "" $exec_output] {
@@ -347,6 +357,13 @@ proc thin_archive_with_nested { bfdtests } {
fail "$testname ($bfdtest)"
return
}
+
+ set exec_output [binutils_run "$base_dir/$bfdtest" "$archive3"]
+ if ![string match "" $exec_output] {
+ verbose -log $exec_output
+ fail "$testname ($bfdtest)"
+ return
+ }
}
set got [binutils_run $NM "--print-armap $archive"]
--
2.34.1.575.g55b058a8bb-goog
More information about the Binutils
mailing list