Fix objcopy's --preserve-dates command line option so that it will work with PE forma...
authorNick Clifton <nickc@redhat.com>
Mon, 30 Mar 2020 15:30:02 +0000 (16:30 +0100)
committerNick Clifton <nickc@redhat.com>
Mon, 30 Mar 2020 15:30:02 +0000 (16:30 +0100)
PR binutils/pr25662
bfd * libcoff-in.h (struct pe_tdata): Rename the insert_timestamp
field to timestamp and make it an integer.
* libcoff.h: Regenerate.
* peXXigen.c (_bfd_XXi_only_swap_filehdr_out): Test the timestamp
field in the pe_data structure rather than the insert_timestamp
field.

binutils* objcopy.c (copy_object): When copying PE format files set the
timestamp field in the pe_data structure if the preserve_dates
flag is set.
* testsuite/binutils-all/objcopy.exp (objcopy_test) Use
--preserve-dates in place of the -p option, in order to make its
effect more obvious.

ld * emultempl/pe.em (after_open): Replace initialisation of the
insert_timestamp field in the pe_data structure with an
initialisation of the timestamp field.
* emultemp/pep.em: Likewise.
* pe-dll.c (fill_edata): Use the timestamp field in the pe_data
structure instead of the insert_timestamp field.

bfd/ChangeLog
bfd/libcoff-in.h
bfd/libcoff.h
bfd/peXXigen.c
binutils/ChangeLog
binutils/objcopy.c
binutils/testsuite/binutils-all/objcopy.exp
ld/ChangeLog
ld/emultempl/pe.em
ld/emultempl/pep.em
ld/pe-dll.c

index d17767fd7a90bc086531064c9a056e57f85559a1..bd43b676ba15d9f1be9be5c95fd58fde084fd186 100644 (file)
@@ -1,3 +1,13 @@
+2020-03-30  Nick Clifton  <nickc@redhat.com>
+
+       PR binutils/pr25662
+       * libcoff-in.h (struct pe_tdata): Rename the insert_timestamp
+       field to timestamp and make it an integer.
+       * libcoff.h: Regenerate.
+       * peXXigen.c (_bfd_XXi_only_swap_filehdr_out): Test the timestamp
+       field in the pe_data structure rather than the insert_timestamp
+       field.
+
 2020-03-30  Alan Modra  <amodra@gmail.com>
 
        PR 25745
index 3030a65fa77128920d94fab9b301a3d7ca6559de..c86ffc99330088f57f14ce1a762634aa61a23d72 100644 (file)
@@ -128,7 +128,9 @@ typedef struct pe_tdata
   int has_reloc_section;
   int dont_strip_reloc;
   int dos_message[16];
-  bfd_boolean insert_timestamp;
+  /* The timestamp to insert into the output file.
+     If the timestamp is -1 then the current time is used.  */
+  int timestamp;
   bfd_boolean (*in_reloc_p) (bfd *, reloc_howto_type *);
   flagword real_flags;
 
index 4c7be6e935a8755c0ba810f6d2c7a0b976d18bf3..eeb7b6b9954073412cff1ea07f9b7be40be31d29 100644 (file)
@@ -132,7 +132,9 @@ typedef struct pe_tdata
   int has_reloc_section;
   int dont_strip_reloc;
   int dos_message[16];
-  bfd_boolean insert_timestamp;
+  /* The timestamp to insert into the output file.
+     If the timestamp is -1 then the current time is used.  */
+  int timestamp;
   bfd_boolean (*in_reloc_p) (bfd *, reloc_howto_type *);
   flagword real_flags;
 
index e42d646552a0ca1e856e082256cd3d943b54ddf0..b9eeb775d9b1ba0c452e3b1fe541a2f27e412f8a 100644 (file)
@@ -876,10 +876,10 @@ _bfd_XXi_only_swap_filehdr_out (bfd * abfd, void * in, void * out)
 
   /* Use a real timestamp by default, unless the no-insert-timestamp
      option was chosen.  */
-  if ((pe_data (abfd)->insert_timestamp))
+  if ((pe_data (abfd)->timestamp) == -1)
     H_PUT_32 (abfd, time (0), filehdr_out->f_timdat);
   else
-    H_PUT_32 (abfd, 0, filehdr_out->f_timdat);
+    H_PUT_32 (abfd, pe_data (abfd)->timestamp, filehdr_out->f_timdat);
 
   PUT_FILEHDR_SYMPTR (abfd, filehdr_in->f_symptr,
                      filehdr_out->f_symptr);
index c7c2d73fb72f43e387cc78df857507b1ad20eed6..a08be238790e8a0a1952631af80934e2b0bc47e9 100644 (file)
@@ -1,3 +1,13 @@
+2020-03-30  Nick Clifton  <nickc@redhat.com>
+
+       PR binutils/25662
+       * objcopy.c (copy_object): When copying PE format files set the
+       timestamp field in the pe_data structure if the preserve_dates
+       flag is set.
+       * testsuite/binutils-all/objcopy.exp (objcopy_test) Use
+       --preserve-dates in place of the -p option, in order to make its
+       effect more obvious.
+
 2020-03-28  Alan Modra  <amodra@gmail.com>
 
        * testsuite/binutils-all/objcopy.exp (objcopy_test): Only
index e6711a99fb2f0324c8f7edea21580daa061cfdaa..738ef4c2c9135742d6c0518a3bac631574e8fa58 100644 (file)
@@ -2774,6 +2774,11 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch)
 
                     file_alignment, section_alignment);
        }
+
+      if (preserve_dates
+         && bfd_get_flavour (ibfd) == bfd_target_coff_flavour
+         && bfd_pei_p (ibfd))
+       pe->timestamp = pe_data (ibfd)->coff.timestamp;
     }
 
   if (isympp)
index e4eb53cf84ad4e14ee814023cb4d4d33215f6964..56a7db8199b7a375b9ca5a44657e893e9488d952 100644 (file)
@@ -76,7 +76,7 @@ proc objcopy_test {testname srcfile type asflags ldflags} {
            unresolved "objcopy $type ($testname)"
            return
        }
-       set xflags "-p"
+       set xflags "--preserve-dates"
     }
 
     set got [binutils_run $OBJCOPY "$OBJCOPYFLAGS $xflags $t_tempfile $t_copyfile"]
index 1227113d00c06214d7a7264027111e0b80de7da3..15d34bc5a3f134c5edfec930d53ff53de0f165e9 100644 (file)
@@ -1,3 +1,13 @@
+2020-03-30  Nick Clifton  <nickc@redhat.com>
+
+       PR binutils/25662
+       * emultempl/pe.em (after_open): Replace initialisation of the
+       insert_timestamp field in the pe_data structure with an
+       initialisation of the timestamp field.
+       * emultemp/pep.em: Likewise.
+       * pe-dll.c (fill_edata): Use the timestamp field in the pe_data
+       structure instead of the insert_timestamp field.
+
 2020-03-28  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR 25732
index db23b221d66adc7ddc64b14aaa4881df9753482a..4fe195ec32abc4eab650121bc7198f1ce1f8bd75 100644 (file)
@@ -1375,7 +1375,10 @@ gld_${EMULATION_NAME}_after_open (void)
   pe_data (link_info.output_bfd)->pe_opthdr = pe;
   pe_data (link_info.output_bfd)->dll = init[DLLOFF].value;
   pe_data (link_info.output_bfd)->real_flags |= real_flags;
-  pe_data (link_info.output_bfd)->insert_timestamp = insert_timestamp;
+  if (insert_timestamp)
+    pe_data (link_info.output_bfd)->timestamp = -1;
+  else
+    pe_data (link_info.output_bfd)->timestamp = 0;
 
   /* At this point we must decide whether to use long section names
      in the output or not.  If the user hasn't explicitly specified
index 3d09a0a6b13244ad59d349ec912dee5ebcecde3b..3e03eb3a6e0f40135f67abfc3355d5aadc1fabea 100644 (file)
@@ -1364,7 +1364,10 @@ gld_${EMULATION_NAME}_after_open (void)
   pe_data (link_info.output_bfd)->pe_opthdr = pep;
   pe_data (link_info.output_bfd)->dll = init[DLLOFF].value;
   pe_data (link_info.output_bfd)->real_flags |= real_flags;
-  pe_data (link_info.output_bfd)->insert_timestamp = insert_timestamp;
+  if (insert_timestamp)
+    pe_data (link_info.output_bfd)->timestamp = -1;
+  else
+    pe_data (link_info.output_bfd)->timestamp = 0;
 
   /* At this point we must decide whether to use long section names
      in the output or not.  If the user hasn't explicitly specified
index 397af8780e47f5cd9ccc1c24a104906876edd38e..0addde231863a50e7111e2ce23cd00699dcfb98c 100644 (file)
@@ -1211,8 +1211,10 @@ fill_edata (bfd *abfd, struct bfd_link_info *info ATTRIBUTE_UNUSED)
 
   memset (edata_d, 0, edata_sz);
 
-  if (pe_data (abfd)->insert_timestamp)
+  if (pe_data (abfd)->timestamp == -1)
     H_PUT_32 (abfd, time (0), edata_d + 4);
+  else
+    H_PUT_32 (abfd, pe_data (abfd)->timestamp, edata_d + 4);
 
   if (pe_def_file->version_major != -1)
     {
This page took 0.031526 seconds and 4 git commands to generate.