From: Nick Clifton <nickc@redhat.com>
To: Alan Modra <amodra@gmail.com>
Cc: Jozef Lawrynowicz <jozef.l@mittosystems.com>, binutils@sourceware.org
Subject: Re: PR 25562: New binutils testsuite failures
Date: Mon, 30 Mar 2020 16:29:35 +0100 [thread overview]
Message-ID: <0844c797-5672-0b8e-a783-c44010b7af2b@redhat.com> (raw)
In-Reply-To: <20200330124541.GX4583@bubble.grove.modra.org>
[-- Attachment #1: Type: text/plain, Size: 1586 bytes --]
Hi Guys,
Right, I am checking in the attached patch which makes objcopy's -p
work with PE format files. I had to change the insert_timestamp field
in the pe_data structure to an integer containing the time to put in
the header. The value can be 0 for a deterministic output, and it can
also be -1, which is interpreted as 'insert the current time'.
I have rerun the pr25662 tests with this change and all of the PE
format targets now pass.
Cheers
Nick
bfd/ChangeLog
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.
binutils/ChangeLog
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.
ld/ChangeLog
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.
[-- Attachment #2: pr25662.patch --]
[-- Type: text/x-patch, Size: 4590 bytes --]
diff --git a/bfd/libcoff-in.h b/bfd/libcoff-in.h
index 3030a65fa7..c86ffc9933 100644
--- a/bfd/libcoff-in.h
+++ b/bfd/libcoff-in.h
@@ -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;
diff --git a/bfd/libcoff.h b/bfd/libcoff.h
index 4c7be6e935..eeb7b6b995 100644
--- a/bfd/libcoff.h
+++ b/bfd/libcoff.h
@@ -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;
diff --git a/bfd/peXXigen.c b/bfd/peXXigen.c
index e42d646552..b9eeb775d9 100644
--- a/bfd/peXXigen.c
+++ b/bfd/peXXigen.c
@@ -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);
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index e6711a99fb..738ef4c2c9 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -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)
diff --git a/binutils/testsuite/binutils-all/objcopy.exp b/binutils/testsuite/binutils-all/objcopy.exp
index e4eb53cf84..56a7db8199 100644
--- a/binutils/testsuite/binutils-all/objcopy.exp
+++ b/binutils/testsuite/binutils-all/objcopy.exp
@@ -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"]
diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em
index db23b221d6..4fe195ec32 100644
--- a/ld/emultempl/pe.em
+++ b/ld/emultempl/pe.em
@@ -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
diff --git a/ld/emultempl/pep.em b/ld/emultempl/pep.em
index 3d09a0a6b1..3e03eb3a6e 100644
--- a/ld/emultempl/pep.em
+++ b/ld/emultempl/pep.em
@@ -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
diff --git a/ld/pe-dll.c b/ld/pe-dll.c
index 397af8780e..0addde2318 100644
--- a/ld/pe-dll.c
+++ b/ld/pe-dll.c
@@ -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)
{
next prev parent reply other threads:[~2020-03-30 15:29 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-30 9:48 Nick Clifton
2020-03-30 12:15 ` Jozef Lawrynowicz
2020-03-30 12:26 ` Nick Clifton
2020-03-30 12:36 ` Jozef Lawrynowicz
2020-03-30 12:45 ` Alan Modra
2020-03-30 14:00 ` Nick Clifton
2020-03-30 15:29 ` Nick Clifton [this message]
2020-03-31 0:18 ` Maciej W. Rozycki
2020-08-02 12:53 ` Maciej W. Rozycki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0844c797-5672-0b8e-a783-c44010b7af2b@redhat.com \
--to=nickc@redhat.com \
--cc=amodra@gmail.com \
--cc=binutils@sourceware.org \
--cc=jozef.l@mittosystems.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).