ld/

2009-08-28  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/10569
	* ldemul.c (ldemul_set_output_arch): Set maximum/common page
	 sizes on output target.

	* ldexp.c: Include "ldfile.h" and "ldemul.h".
	(fold_name): Use ldemul_choose_target instead of default_target
	to get maximum/common page sizes.

	* ldmain.c (main): Initialize config.maxpagesize and
	config.commonpagesize to (bfd_vma) -1.

	* emultempl/elf32.em: Use ldemul_choose_target instead of
	default_target to set maximum/common page sizes.


ld/testsuite

2009-08-28  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/10569
	* ld-elf/commonpage2.d: New.
	* ld-elf/maxpage4.d: Likewise.
	* ld-elf/maxpage4.t: Likewise.

Index: emultempl/elf32.em
===================================================================
--- emultempl/elf32.em	(revision 6643)
+++ emultempl/elf32.em	(working copy)
@@ -2178,8 +2178,8 @@ fragment <<EOF
 	  if (*end || (config.maxpagesize & (config.maxpagesize - 1)) != 0)
 	    einfo (_("%P%F: invalid maxium page size \`%s'\n"),
 		   optarg + 14);
-	  ASSERT (default_target != NULL);
-	  bfd_emul_set_maxpagesize (default_target, config.maxpagesize);
+	  bfd_emul_set_maxpagesize (ldemul_choose_target (0, NULL),
+				    config.maxpagesize);
 	}
       else if (CONST_STRNEQ (optarg, "common-page-size="))
 	{
@@ -2189,8 +2189,7 @@ fragment <<EOF
 	      || (config.commonpagesize & (config.commonpagesize - 1)) != 0)
 	    einfo (_("%P%F: invalid common page size \`%s'\n"),
 		   optarg + 17);
-	  ASSERT (default_target != NULL);
-	  bfd_emul_set_commonpagesize (default_target,
+	  bfd_emul_set_commonpagesize (ldemul_choose_target (0, NULL),
 				       config.commonpagesize);
 	}
       /* What about the other Solaris -z options? FIXME.  */
Index: testsuite/ld-elf/maxpage4.d
===================================================================
--- testsuite/ld-elf/maxpage4.d	(revision 0)
+++ testsuite/ld-elf/maxpage4.d	(revision 0)
@@ -0,0 +1,9 @@
+#source: maxpage1.s
+#as: --32
+#ld: -z max-page-size=0x200000 -T maxpage4.t
+#readelf: -l --wide
+#target: x86_64-*-linux*
+
+#...
+  LOAD+.*0x200000
+#pass
Index: testsuite/ld-elf/maxpage4.t
===================================================================
--- testsuite/ld-elf/maxpage4.t	(revision 0)
+++ testsuite/ld-elf/maxpage4.t	(revision 0)
@@ -0,0 +1,9 @@
+OUTPUT_FORMAT("elf32-i386")
+OUTPUT_ARCH(i386)
+ENTRY(_start)
+SECTIONS
+{
+  .text : {*(.text)}
+  .data : {*(.data)}
+  /DISCARD/ : {*(*)}
+}
Index: testsuite/ld-elf/commonpage2.d
===================================================================
--- testsuite/ld-elf/commonpage2.d	(revision 0)
+++ testsuite/ld-elf/commonpage2.d	(revision 0)
@@ -0,0 +1,9 @@
+#source: maxpage1.s
+#as: --32
+#ld: -z max-page-size=0x200000 -z common-page-size=0x100000 -T maxpage4.t
+#readelf: -l --wide
+#target: x86_64-*-linux*
+
+#...
+  LOAD+.*0x200000
+#pass
Index: ldmain.c
===================================================================
--- ldmain.c	(revision 6600)
+++ ldmain.c	(working copy)
@@ -248,6 +248,8 @@ main (int argc, char **argv)
   config.make_executable = TRUE;
   config.magic_demand_paged = TRUE;
   config.text_read_only = TRUE;
+  config.maxpagesize = (bfd_vma) -1;
+  config.commonpagesize = (bfd_vma) -1;
 
   command_line.warn_mismatch = TRUE;
   command_line.warn_search_mismatch = TRUE;
Index: ldemul.c
===================================================================
--- ldemul.c	(revision 6600)
+++ ldemul.c	(working copy)
@@ -82,6 +82,21 @@ void
 ldemul_set_output_arch (void)
 {
   ld_emulation->set_output_arch ();
+
+  if (config.maxpagesize != (bfd_vma) -1
+      || config.commonpagesize != (bfd_vma) -1)
+    {
+      const char *output_target = lang_get_output_target ();
+
+      if (config.maxpagesize != (bfd_vma) -1)
+	bfd_emul_set_maxpagesize (output_target,
+				  config.maxpagesize);
+
+      if (config.commonpagesize != (bfd_vma) -1)
+	bfd_emul_set_commonpagesize (output_target,
+				     config.commonpagesize);
+
+    }
 }
 
 void
Index: ldexp.c
===================================================================
--- ldexp.c	(revision 6600)
+++ ldexp.c	(working copy)
@@ -40,6 +40,8 @@
 #include "ldlex.h"
 #include <ldgram.h>
 #include "ldlang.h"
+#include "ldfile.h"
+#include "ldemul.h"
 #include "libiberty.h"
 #include "safe-ctype.h"
 
@@ -482,6 +484,8 @@ fold_trinary (etree_type *tree)
 static void
 fold_name (etree_type *tree)
 {
+  const char *target;
+
   memset (&expld.result, 0, sizeof (expld.result));
 
   switch (tree->type.node_code)
@@ -672,10 +676,11 @@ fold_name (etree_type *tree)
       break;
 
     case CONSTANT:
+      target = ldemul_choose_target (0, NULL);
       if (strcmp (tree->name.name, "MAXPAGESIZE") == 0)
-	new_abs (bfd_emul_get_maxpagesize (default_target));
+	new_abs (bfd_emul_get_maxpagesize (target));
       else if (strcmp (tree->name.name, "COMMONPAGESIZE") == 0)
-	new_abs (bfd_emul_get_commonpagesize (default_target));
+	new_abs (bfd_emul_get_commonpagesize (target));
       else
 	einfo (_("%F%S: unknown constant `%s' referenced in expression\n"),
 	       tree->name.name);
