This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Make windres output deterministic by using constant (zero) timestamps.


This patch is a follow-up from the thread: "Deterministic windres coff output".

There are several places that this change could be made, I decided to
start with the simplest.

As far as I can tell, the resource timestamp field is used to set the
coff header timestamp, but the value is ultimately unused (as a
resource value) in the final binary. Since the goal is to make sure
the coff timestamp is zero so that .o output is predictable, it makes
sense to me to set the resource stamp to zero and let the coff header
pull the value in as before.

The alternative I suppose would be to continue to set the resource
stamp, but override it in rescoff.c (coff_to_bin), but IMO that is a
bit less obvious, as a quick read of windres.c would make it appear as
though a real stamp is being used.

Regards,
Cory

On Thu, Nov 14, 2013 at 3:20 PM, Cory Fields <cory@coryfields.com> wrote:
> binutils/
>     * windres.c (define_resource): Use zero for timestamp.
>     time.h include is no longer needed.
>     * resres.c (res_append_resource): Likewise.
> ---
>  binutils/ChangeLog |  5 +++++
>  binutils/resres.c  | 14 +++++---------
>  binutils/windres.c | 14 +++++---------
>  3 files changed, 15 insertions(+), 18 deletions(-)
>
> diff --git a/binutils/ChangeLog b/binutils/ChangeLog
> index cc9c6f9..acc6645 100644
> --- a/binutils/ChangeLog
> +++ b/binutils/ChangeLog
> @@ -1,3 +1,8 @@
> +2013-11-14  Cory Fields  <cory@coryfields.com>
> +       * windres.c (define_resource): Use zero for timestamp, making output
> +       deterministic. time.h include is no longer needed.
> +       * resres.c (res_append_resource): Likewise.
> +
>  2013-11-13  Martin Mitas  <mity@morous.org>
>
>         * rescoff.c (write_coff_file): Use 64-bit alignment for resource
> diff --git a/binutils/resres.c b/binutils/resres.c
> index ff95cb5..52a9f47 100644
> --- a/binutils/resres.c
> +++ b/binutils/resres.c
> @@ -32,7 +32,6 @@
>  #include "windres.h"
>
>  #include <assert.h>
> -#include <time.h>
>
>  static rc_uint_type write_res_directory (windres_bfd *, rc_uint_type,
>                                          const rc_res_directory *, const rc_res_id *,
> @@ -660,17 +659,14 @@ res_append_resource (rc_res_directory **res_dirs, rc_res_resource *resource,
>
>        if (*res_dirs == NULL)
>         {
> -         static unsigned long timeval;
> -
> -         /* Use the same timestamp for every resource created in a
> -            single run.  */
> -         if (timeval == 0)
> -           timeval = time (NULL);
> -
>           *res_dirs = ((rc_res_directory *)
>                         res_alloc (sizeof (rc_res_directory)));
> +
> +         /* Using a real timestamp only serves to create non-deterministic
> +            results. Use zero instead. */
> +         (*res_dirs)->time = 0;
> +
>           (*res_dirs)->characteristics = 0;
> -         (*res_dirs)->time = timeval;
>           (*res_dirs)->major = 0;
>           (*res_dirs)->minor = 0;
>           (*res_dirs)->entries = NULL;
> diff --git a/binutils/windres.c b/binutils/windres.c
> index 7de73ef..3ef83af 100644
> --- a/binutils/windres.c
> +++ b/binutils/windres.c
> @@ -37,7 +37,6 @@
>
>  #include "sysdep.h"
>  #include <assert.h>
> -#include <time.h>
>  #include "bfd.h"
>  #include "getopt.h"
>  #include "bucomm.h"
> @@ -339,17 +338,14 @@ define_resource (rc_res_directory **resources, int cids,
>
>        if (*resources == NULL)
>         {
> -         static unsigned int timeval;
> -
> -         /* Use the same timestamp for every resource created in a
> -             single run.  */
> -         if (timeval == 0)
> -           timeval = time (NULL);
> -
>           *resources = ((rc_res_directory *)
>                         res_alloc (sizeof (rc_res_directory)));
> +
> +         /* Using a real timestamp only serves to create non-deterministic
> +            results. Use zero instead. */
> +         (*resources)->time = 0;
> +
>           (*resources)->characteristics = 0;
> -         (*resources)->time = timeval;
>           (*resources)->major = 0;
>           (*resources)->minor = 0;
>           (*resources)->entries = NULL;
> --
> 1.8.1.2
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]