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]

[PATCH] Enable Windows --auto-image-base to take an argument


I've been carrying this patch in the cygwin version of ld for a
while.  Ok to apply?

cgf

commit 606e9fc6a35cf48cc71d7d4ebc4cabc3f02b488e
Author: Chris Faylor <me.cygwin2011@cgf.cx>
Date:   Mon Mar 17 13:38:52 2014 -0400

    2014-03-17  Christopher Faylor  <me.cygwin2013@cgf.cx>
    
    	* ld.texinfo: Document change in handling of --enable-auto-image-base.
    	* emultempl/pe.em (pe_auto_image_base): Set to default base.
    	(gld_${EMULATION_NAME}_list_options): Change usage message to reflect
    	optional --enable-auto-image-base argument.
    	(gld${EMULATION_NAME}_handle_option): Handle optional
    	--enable-auto-image-base argument.
    	(compute_dll_image_base): Eliminate constant.  Use pe_auto_image_base.

diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em
index 67df2bc..c18cb26 100644
--- a/ld/emultempl/pe.em
+++ b/ld/emultempl/pe.em
@@ -137,6 +137,7 @@ static int pe_enable_stdcall_fixup = -1; /* 0=disable 1=enable.  */
 static char *pe_out_def_filename = NULL;
 static char *pe_implib_filename = NULL;
 static int pe_enable_auto_image_base = 0;
+static unsigned long pe_auto_image_base = 0x61500000;
 static char *pe_dll_search_prefix = NULL;
 #endif
 
@@ -322,7 +323,7 @@ gld${EMULATION_NAME}_add_options
        treating -c as an abbreviation for these --compat-implib.  */
     {"compat-implib", no_argument, NULL, OPTION_IMP_COMPAT},
     {"compat-implib", no_argument, NULL, OPTION_IMP_COMPAT},
-    {"enable-auto-image-base", no_argument, NULL, OPTION_ENABLE_AUTO_IMAGE_BASE},
+    {"enable-auto-image-base", optional_argument, NULL, OPTION_ENABLE_AUTO_IMAGE_BASE},
     {"disable-auto-image-base", no_argument, NULL, OPTION_DISABLE_AUTO_IMAGE_BASE},
     {"dll-search-prefix", required_argument, NULL, OPTION_DLL_SEARCH_PREFIX},
     {"no-default-excludes", no_argument, NULL, OPTION_NO_DEFAULT_EXCLUDES},
@@ -455,11 +456,12 @@ gld_${EMULATION_NAME}_list_options (FILE *file)
   fprintf (file, _("  --kill-at                          Remove @nn from exported symbols\n"));
   fprintf (file, _("  --out-implib <file>                Generate import library\n"));
   fprintf (file, _("  --output-def <file>                Generate a .DEF file for the built DLL\n"));
-  fprintf (file, _("  --warn-duplicate-exports           Warn about duplicate exports.\n"));
+  fprintf (file, _("  --warn-duplicate-exports           Warn about duplicate exports\n"));
   fprintf (file, _("  --compat-implib                    Create backward compatible import libs;\n\
                                        create __imp_<SYMBOL> as well.\n"));
-  fprintf (file, _("  --enable-auto-image-base           Automatically choose image base for DLLs\n\
-                                       unless user specifies one\n"));
+  fprintf (file, _("  --enable-auto-image-base[=<address>] Automatically choose image base for DLLs\n\
+                                       (optionally starting with address) unless\n\
+                                       specifically set with --image-base\n"));
   fprintf (file, _("  --disable-auto-image-base          Do not auto-choose image base. (default)\n"));
   fprintf (file, _("  --dll-search-prefix=<string>       When linking dynamically to a dll without\n\
                                        an importlib, use <string><basename>.dll\n\
@@ -802,6 +804,12 @@ gld${EMULATION_NAME}_handle_option (int optc)
       break;
     case OPTION_ENABLE_AUTO_IMAGE_BASE:
       pe_enable_auto_image_base = 1;
+      if (optarg && *optarg)
+	{
+	  char *end;
+	  pe_auto_image_base = strtoul(optarg, &end, 0);
+	  /* XXX should check that we actually parsed something */
+	}
       break;
     case OPTION_DISABLE_AUTO_IMAGE_BASE:
       pe_enable_auto_image_base = 0;
@@ -911,7 +919,7 @@ static unsigned long
 compute_dll_image_base (const char *ofile)
 {
   unsigned long hash = strhash (ofile);
-  return 0x61300000 + ((hash << 16) & 0x0FFC0000);
+  return pe_auto_image_base + ((hash << 16) & 0x0FFC0000);
 }
 #endif
 
diff --git a/ld/ld.texinfo b/ld/ld.texinfo
index 2c39d3c..8a41ee8 100644
--- a/ld/ld.texinfo
+++ b/ld/ld.texinfo
@@ -2415,11 +2415,12 @@ creation step.
 
 @kindex --enable-auto-image-base
 @item --enable-auto-image-base
-Automatically choose the image base for DLLs, unless one is specified
-using the @code{--image-base} argument.  By using a hash generated
-from the dllname to create unique image bases for each DLL, in-memory
-collisions and relocations which can delay program execution are
-avoided.
+@itemx --enable-auto-image-base=@var{value}
+Automatically choose the image base for DLLs, optionally starting with base
+@var{value}, unless one is specified using the @code{--image-base} argument.
+By using a hash generated from the dllname to create unique image bases
+for each DLL, in-memory collisions and relocations which can delay program
+execution are avoided.
 [This option is specific to the i386 PE targeted port of the linker]
 
 @kindex --disable-auto-image-base


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