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] Fix -z max-page-size


Hi!

When using -z max-page-size=N and/or -z common-page-size=N
options in addition to -T script.lds, the linker script is
parsed before bfd_emul_set_{max,common}pagesize is called
and thus CONSTANT (MAXPAGESIZE) and CONSTANT (COMMONPAGESIZE)
return the default rather than overridden values.

Below is one possible fix, the other would be to call
bfd_emul_set_*pagesize immediately in *_handle_option
rather than waiting until parse_args returns and yet another
would be not to evaluate CONSTANT (MAXPAGESIZE) etc. when
parsing the script, but at some later time.

2007-01-17  Jakub Jelinek  <jakub@redhat.com>

	* ldexp.c (fold_name): If config.maxpagesize resp.
	config.commonpagesize is non-zero, prefer that over
	bfd_emul_get_*pagesize.
	* emultempl/elf32.em (handle_option): Make sure -z max-page-size
	or -z common-page-size argument is a power of 2.

--- ld/ldexp.c.jj	2007-01-09 13:45:50.000000000 +0100
+++ ld/ldexp.c	2007-01-17 15:36:38.000000000 +0100
@@ -643,9 +643,13 @@ fold_name (etree_type *tree)
 
     case CONSTANT:
       if (strcmp (tree->name.name, "MAXPAGESIZE") == 0)
-	new_abs (bfd_emul_get_maxpagesize (default_target));
+	new_abs (config.maxpagesize != 0
+		 ? config.maxpagesize
+		 : bfd_emul_get_maxpagesize (default_target));
       else if (strcmp (tree->name.name, "COMMONPAGESIZE") == 0)
-	new_abs (bfd_emul_get_commonpagesize (default_target));
+	new_abs (config.commonpagesize != 0
+		 ? config.commonpagesize
+		 : bfd_emul_get_commonpagesize (default_target));
       else
 	einfo (_("%F%S: unknown constant `%s' referenced in expression\n"),
 	       tree->name.name);
--- ld/emultempl/elf32.em.jj	2006-12-23 10:53:49.000000000 +0100
+++ ld/emultempl/elf32.em	2007-01-17 15:33:01.000000000 +0100
@@ -1915,7 +1915,7 @@ cat >>e${EMULATION_NAME}.c <<EOF
 	  char *end;
 
 	  config.maxpagesize = strtoul (optarg + 14, &end, 0);
-	  if (*end)
+	  if (*end || (config.maxpagesize & (config.maxpagesize - 1)) != 0)
 	    einfo (_("%P%F: invalid maxium page size \`%s'\n"),
 		   optarg + 14);
 	}
@@ -1923,7 +1923,8 @@ cat >>e${EMULATION_NAME}.c <<EOF
 	{
 	  char *end;
 	  config.commonpagesize = strtoul (optarg + 17, &end, 0);
-	  if (*end)
+	  if (*end
+	      || (config.commonpagesize & (config.commonpagesize - 1)) != 0)
 	    einfo (_("%P%F: invalid common page size \`%s'\n"),
 		   optarg + 17);
 	}

	Jakub


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