From 0cb112f7400187275da81a05a9ad0534f1430139 Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Fri, 22 Nov 2013 14:54:33 +0000 Subject: [PATCH] * windres.c (define_resource): Use zero for timestamp, making output deterministic. time.h include is no longer needed. * resres.c (res_append_resource): Likewise. * pe-dll.c (fill_edata): Only use a real timestamp if --insert-timestamp was used. * emultempl/pe.em: Add the --insert-timestamp option. * emultempl/pep.em: Likewise for 64bit. * ld.texinfo: Document the --insert-timestamp option. * libcoff-in.h: Add insert_timestamp flag to the pe_data struct. * libcoff.h: Regenerate. * peXXigen.c (_bfd_XXi_only_swap_filehdr_out): Only use a real timestamp if --insert-timestamp was used. --- bfd/ChangeLog | 7 +++++++ bfd/libcoff-in.h | 5 ++--- bfd/libcoff.h | 5 ++--- bfd/peXXigen.c | 8 +++++--- binutils/ChangeLog | 6 ++++++ binutils/resres.c | 16 +++++----------- binutils/windres.c | 15 ++++----------- ld/ChangeLog | 8 ++++++++ ld/emultempl/pe.em | 21 ++++++++++++++------- ld/emultempl/pep.em | 12 ++++++++++-- ld/ld.texinfo | 5 +++++ ld/pe-dll.c | 8 ++++---- 12 files changed, 72 insertions(+), 44 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 89a8f1b6ea0..d76b1b4c34d 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,10 @@ +2013-11-22 Cory Fields + + * libcoff-in.h: Add insert_timestamp flag to the pe_data struct. + * libcoff.h: Regenerate. + * peXXigen.c (_bfd_XXi_only_swap_filehdr_out): Only use a real + timestamp if --insert-timestamp was used. + 2013-11-19 Roland McGrath * elf-nacl.c (nacl_modify_segment_map): Calculate SIZEOF_HEADERS diff --git a/bfd/libcoff-in.h b/bfd/libcoff-in.h index 6efbc524a94..49b5f10b0a7 100644 --- a/bfd/libcoff-in.h +++ b/bfd/libcoff-in.h @@ -1,7 +1,5 @@ /* BFD COFF object file private structure. - Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, - 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 - Free Software Foundation, Inc. + Copyright 1990-2013 Free Software Foundation, Inc. Written by Cygnus Support. This file is part of BFD, the Binary File Descriptor library. @@ -118,6 +116,7 @@ typedef struct pe_tdata int dll; int has_reloc_section; int dont_strip_reloc; + bfd_boolean insert_timestamp; bfd_boolean (*in_reloc_p) (bfd *, reloc_howto_type *); flagword real_flags; } pe_data_type; diff --git a/bfd/libcoff.h b/bfd/libcoff.h index 6270bab86b9..19b6d9c8e1a 100644 --- a/bfd/libcoff.h +++ b/bfd/libcoff.h @@ -3,9 +3,7 @@ Run "make headers" in your build bfd/ to regenerate. */ /* BFD COFF object file private structure. - Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, - 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 - Free Software Foundation, Inc. + Copyright 1990-2013 Free Software Foundation, Inc. Written by Cygnus Support. This file is part of BFD, the Binary File Descriptor library. @@ -122,6 +120,7 @@ typedef struct pe_tdata int dll; int has_reloc_section; int dont_strip_reloc; + bfd_boolean insert_timestamp; bfd_boolean (*in_reloc_p) (bfd *, reloc_howto_type *); flagword real_flags; } pe_data_type; diff --git a/bfd/peXXigen.c b/bfd/peXXigen.c index d0f7a96e1f9..287e4a2e3a1 100644 --- a/bfd/peXXigen.c +++ b/bfd/peXXigen.c @@ -1,6 +1,5 @@ /* Support for the generic parts of PE/PEI; the common executable parts. - Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, - 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. + Copyright 1995-2013 Free Software Foundation, Inc. Written by Cygnus Solutions. This file is part of BFD, the Binary File Descriptor library. @@ -793,7 +792,10 @@ _bfd_XXi_only_swap_filehdr_out (bfd * abfd, void * in, void * out) H_PUT_16 (abfd, filehdr_in->f_magic, filehdr_out->f_magic); H_PUT_16 (abfd, filehdr_in->f_nscns, filehdr_out->f_nscns); - H_PUT_32 (abfd, time (0), filehdr_out->f_timdat); + /* Only use a real timestamp if the option was chosen. */ + if ((pe_data (abfd)->insert_timestamp)) + H_PUT_32 (abfd, time(0), filehdr_out->f_timdat); + PUT_FILEHDR_SYMPTR (abfd, filehdr_in->f_symptr, filehdr_out->f_symptr); H_PUT_32 (abfd, filehdr_in->f_nsyms, filehdr_out->f_nsyms); diff --git a/binutils/ChangeLog b/binutils/ChangeLog index cc9c6f9c5cd..ca2a322d355 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,9 @@ +2013-11-22 Cory Fields + + * 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 * rescoff.c (write_coff_file): Use 64-bit alignment for resource diff --git a/binutils/resres.c b/binutils/resres.c index ff95cb5bea3..84f956f1538 100644 --- a/binutils/resres.c +++ b/binutils/resres.c @@ -1,6 +1,5 @@ /* resres.c: read_res_file and write_res_file implementation for windres. - Copyright 1998, 1999, 2001, 2002, 2005, 2007, 2008, 2011 - Free Software Foundation, Inc. + Copyright 1998-2013 Free Software Foundation, Inc. Written by Anders Norlander . Rewritten by Kai Tietz, Onevision. @@ -32,7 +31,6 @@ #include "windres.h" #include -#include static rc_uint_type write_res_directory (windres_bfd *, rc_uint_type, const rc_res_directory *, const rc_res_id *, @@ -660,17 +658,13 @@ 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))); + (*res_dirs)->characteristics = 0; - (*res_dirs)->time = timeval; + /* Using a real timestamp only serves to create non-deterministic + results. Use zero instead. */ + (*res_dirs)->time = 0; (*res_dirs)->major = 0; (*res_dirs)->minor = 0; (*res_dirs)->entries = NULL; diff --git a/binutils/windres.c b/binutils/windres.c index 7de73ef2f55..64afb3ad6a5 100644 --- a/binutils/windres.c +++ b/binutils/windres.c @@ -1,6 +1,5 @@ /* windres.c -- a program to manipulate Windows resources - Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, - 2009, 2011, 2012 Free Software Foundation, Inc. + Copyright 1997-2013 Free Software Foundation, Inc. Written by Ian Lance Taylor, Cygnus Support. Rewritten by Kai Tietz, Onevision. @@ -37,7 +36,6 @@ #include "sysdep.h" #include -#include #include "bfd.h" #include "getopt.h" #include "bucomm.h" @@ -339,17 +337,12 @@ 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))); (*resources)->characteristics = 0; - (*resources)->time = timeval; + /* Using a real timestamp only serves to create non-deterministic + results. Use zero instead. */ + (*resources)->time = 0; (*resources)->major = 0; (*resources)->minor = 0; (*resources)->entries = NULL; diff --git a/ld/ChangeLog b/ld/ChangeLog index e98129dc9eb..4582adb1a4e 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,11 @@ +2013-11-22 Cory Fields + + * pe-dll.c (fill_edata): Only use a real timestamp if + --insert-timestamp was used. + * emultempl/pe.em: Add the --insert-timestamp option. + * emultempl/pep.em: Likewise for 64bit. + * ld.texinfo: Document the --insert-timestamp option. + 2013-11-22 Senthil Kumar Selvaraj * scripttempl/avr.sc: Set .data section's LMA to next available diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em index 4df7753caa5..5d6da9e05f1 100644 --- a/ld/emultempl/pe.em +++ b/ld/emultempl/pe.em @@ -130,6 +130,7 @@ static int support_old_code = 0; static char * thumb_entry_symbol = NULL; static lang_assignment_statement_type *image_base_statement = 0; static unsigned short pe_dll_characteristics = 0; +static bfd_boolean insert_timestamp = FALSE; #ifdef DLL_SUPPORT static int pe_enable_stdcall_fixup = -1; /* 0=disable 1=enable. */ @@ -239,8 +240,7 @@ fragment < Set the entry point to be Thumb \n")); + fprintf (file, _(" --insert-timestamp Use a real timestamp rather than zero.\n")); + fprintf (file, _(" This makes binaries non-deterministic\n")); #ifdef DLL_SUPPORT fprintf (file, _(" --add-stdcall-alias Export symbols with and without @nn\n")); fprintf (file, _(" --disable-stdcall-fixup Don't link _sym to _sym@nn\n")); @@ -754,6 +757,9 @@ gld${EMULATION_NAME}_handle_option (int optc) case OPTION_LEADING_UNDERSCORE: pe_leading_underscore = 1; break; + case OPTION_INSERT_TIMESTAMP: + insert_timestamp = TRUE; + break; #ifdef DLL_SUPPORT case OPTION_OUT_DEF: pe_out_def_filename = xstrdup (optarg); @@ -1255,6 +1261,7 @@ 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; /* 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 3e8b65e19a2..b7388001df7 100644 --- a/ld/emultempl/pep.em +++ b/ld/emultempl/pep.em @@ -18,8 +18,7 @@ esac rm -f e${EMULATION_NAME}.c (echo;echo;echo;echo;echo)>e${EMULATION_NAME}.c # there, now line numbers match ;-) fragment <[:] Set required OS subsystem [& version]\n")); fprintf (file, _(" --support-old-code Support interworking with old code\n")); fprintf (file, _(" --[no-]leading-underscore Set explicit symbol underscore prefix mode\n")); + fprintf (file, _(" --insert-timestamp Use a real timestamp rather than zero.\n")); + fprintf (file, _(" This makes binaries non-deterministic\n")); #ifdef DLL_SUPPORT fprintf (file, _(" --add-stdcall-alias Export symbols with and without @nn\n")); fprintf (file, _(" --disable-stdcall-fixup Don't link _sym to _sym@nn\n")); @@ -707,6 +711,9 @@ gld${EMULATION_NAME}_handle_option (int optc) case OPTION_LEADING_UNDERSCORE: pep_leading_underscore = 1; break; + case OPTION_INSERT_TIMESTAMP: + insert_timestamp = TRUE; + break; #ifdef DLL_SUPPORT case OPTION_OUT_DEF: pep_out_def_filename = xstrdup (optarg); @@ -1219,6 +1226,7 @@ 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; /* 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/ld.texinfo b/ld/ld.texinfo index e4788f67b57..c925ecb3f98 100644 --- a/ld/ld.texinfo +++ b/ld/ld.texinfo @@ -2657,6 +2657,11 @@ The driver uses the MS Windows Driver Model. @item --tsaware The image is Terminal Server aware. +@kindex --insert-timestamp +@item --insert-timestamp +Insert a real timestamp into the image, rather than the default value +of zero. This will result in a slightly different results with each +invocation, which could be helpful for distributing unique images. @end table @c man end diff --git a/ld/pe-dll.c b/ld/pe-dll.c index 7d5f90db92d..8777efb9b7c 100644 --- a/ld/pe-dll.c +++ b/ld/pe-dll.c @@ -1169,9 +1169,6 @@ fill_edata (bfd *abfd, struct bfd_link_info *info ATTRIBUTE_UNUSED) unsigned char *enameptrs; unsigned char *eordinals; char *enamestr; - time_t now; - - time (&now); edata_d = xmalloc (edata_sz); @@ -1186,7 +1183,10 @@ fill_edata (bfd *abfd, struct bfd_link_info *info ATTRIBUTE_UNUSED) + edata_s->output_section->vma - image_base) memset (edata_d, 0, edata_sz); - bfd_put_32 (abfd, now, edata_d + 4); + + if (pe_data (abfd)->insert_timestamp) + H_PUT_32 (abfd, time (0), edata_d + 4); + if (pe_def_file->version_major != -1) { bfd_put_16 (abfd, pe_def_file->version_major, edata_d + 8); -- 2.30.2