From 0173a86f124acd7a28b7137118de4b45841d0dce Mon Sep 17 00:00:00 2001 From: maminjie Date: Fri, 15 Jul 2022 04:41:42 +0800 Subject: [PATCH] Fix preserve-dates: cannot set time Reference: https://sourceware.org/git/?p=binutils-gdb.git;a=patch;h=6b02746a0e29b1007efd4feb137e2da3e681fc6 Signed-off-by: maminjie (cherry picked from commit 70f363a2ce639f0ad8396a7fcd39e720d6dbb2a9) --- ...jcopy-preserve-dates-.a-cannot-set-t.patch | 54 +++++++++++++++++++ binutils.spec | 6 ++- 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 backport-0001-PR28391-strip-objcopy-preserve-dates-.a-cannot-set-t.patch diff --git a/backport-0001-PR28391-strip-objcopy-preserve-dates-.a-cannot-set-t.patch b/backport-0001-PR28391-strip-objcopy-preserve-dates-.a-cannot-set-t.patch new file mode 100644 index 0000000..71da583 --- /dev/null +++ b/backport-0001-PR28391-strip-objcopy-preserve-dates-.a-cannot-set-t.patch @@ -0,0 +1,54 @@ +From 70b88840a4c65c8f5e2244129487886b5a5c7664 Mon Sep 17 00:00:00 2001 +From: Gleb Fotengauer-Malinovskiy +Date: Tue, 28 Sep 2021 20:11:26 +0930 +Subject: [PATCH] PR28391, strip/objcopy --preserve-dates *.a: cannot set time + +Reference: https://sourceware.org/git/?p=binutils-gdb.git;a=patch;h=6b02746a0e29b1007efd4feb137e2da3e681fc68 + +After commit 985e0264516 copy_archive function began to pass invalid +values to the utimensat(2) function when it tries to preserve +timestamps in ar archives. This happens because the bfd_stat_arch_elt +implementation for ar archives fills only the st_mtim.tv_sec part of +the st_mtim timespec structure, but leaves the st_mtim.tv_nsec part +and the whole st_atim timespec untouched leaving them uninitialized + + PR 28391 + * ar.c (extract_file): Clear buf for preserve_dates. + * objcopy.c (copy_archive): Likewise. + +(cherry picked from commit 0d62064867c74286360e821b75ef6799bedc4b34) +Signed-off-by: maminjie +--- + binutils/ar.c | 3 +++ + binutils/objcopy.c | 1 + + 2 files changed, 4 insertions(+) + +diff --git a/binutils/ar.c b/binutils/ar.c +index 5d6976c7..8885585e 100644 +--- a/binutils/ar.c ++++ b/binutils/ar.c +@@ -1180,6 +1180,9 @@ extract_file (bfd *abfd) + bfd_size_type size; + struct stat buf; + ++ if (preserve_dates) ++ memset (&buf, 0, sizeof (buf)); ++ + if (bfd_stat_arch_elt (abfd, &buf) != 0) + /* xgettext:c-format */ + fatal (_("internal stat error on %s"), bfd_get_filename (abfd)); +diff --git a/binutils/objcopy.c b/binutils/objcopy.c +index fe3ea29c..242b1052 100644 +--- a/binutils/objcopy.c ++++ b/binutils/objcopy.c +@@ -3600,6 +3600,7 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target, + + if (preserve_dates) + { ++ memset (&buf, 0, sizeof (buf)); + stat_status = bfd_stat_arch_elt (this_element, &buf); + + if (stat_status != 0) +-- +2.30.0 + diff --git a/binutils.spec b/binutils.spec index 152cb19..4399f38 100644 --- a/binutils.spec +++ b/binutils.spec @@ -1,7 +1,7 @@ Summary: Binary utilities Name: binutils Version: 2.37 -Release: 7 +Release: 8 License: GPLv3+ URL: https://sourceware.org/binutils @@ -31,6 +31,7 @@ Patch8: backport-0002-CVE-2021-42574.patch Patch9: backport-0003-CVE-2021-42574.patch Patch10: bfd-Close-the-file-descriptor-if-there-is-no-archive.patch Patch11: binutils-AArch64-EFI.patch +Patch12: backport-0001-PR28391-strip-objcopy-preserve-dates-.a-cannot-set-t.patch Provides: bundled(libiberty) @@ -354,6 +355,9 @@ fi %{_infodir}/bfd*info* %changelog +* Fri Aug 05 2022 maminjie - 2.37-8 +- Fix preserve_dates: cannot set time + * Wed Jun 29 2022 Chenxi Mao - 2.37-7 - Add support for the EFI format to the AArch64 target. -- Gitee