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: PR ld/10569: -z max-page-size may not work for linker scripts


On Fri, Aug 28, 2009 at 07:37:22AM -0700, H.J. Lu wrote:
> Output target can be different from emulation target. Emulation target
> may be ELF, which supports page sizes, while output target may not support
> page sizes at all. We need to page sizes for both.

Hmm, OK.  If we are doing something like an "--oformat srec" link,
then the bfd srec backend has no idea of page size, but the input
files might be ELF and we might be using an ELF ld script which
references MAXPAGESIZE.

So the linker needs to know maxpagesize independently of the output.
It just happens that the linker already has config.maxpagesize, so
let's use that in ldexp.c.  We will need to get config.maxpagesize
from the bfd emulation target early in the link process, before we've
parsed -z maxpagesize, and pass any changed value back before final
link time.

bfd/
	PR ld/10569
	* bfd.c (bfd_emul_get_maxpagesize): Don't abort.
	(bfd_emul_get_commonpagesize): Likewise.
ld/
	PR ld/10569
	* ldexp.c (fold_name <MAXPAGESIZE>): Return config.maxpagesize.
	(fold_name <COMMONPAGESIZE>): Similarly.
	* ldlang.c (output_target): Make global.
	* ldlang.h (output_target): Declare.
	* ldmain.c (main): Set config.maxpagesize from bfd_emul_get_maxpagesize.
	Similarly for config.commonpagesize.
	* ldemul.c (set_output_arch_default): Call bfd_emul_set_maxpagesize
	and bfd_emul_set_commonpagesize.
	* emultempl/elf32.em (gld${EMULATION_NAME}_handle_option): Don't call
	bfd_emul_set_maxpagesize or bfd_emul_set_commonpagesize here.

Index: bfd/bfd.c
===================================================================
RCS file: /cvs/src/src/bfd/bfd.c,v
retrieving revision 1.109
diff -u -p -r1.109 bfd.c
--- bfd/bfd.c	26 May 2009 14:12:02 -0000	1.109
+++ bfd/bfd.c	30 Aug 2009 05:17:57 -0000
@@ -1703,8 +1703,7 @@ DESCRIPTION
 	emulation.
 
 RETURNS
-	Returns the maximum page size in bytes for ELF, abort
-	otherwise.
+	Returns the maximum page size in bytes for ELF, 0 otherwise.
 */
 
 bfd_vma
@@ -1717,7 +1716,6 @@ bfd_emul_get_maxpagesize (const char *em
       && target->flavour == bfd_target_elf_flavour)
     return xvec_get_elf_backend_data (target)->maxpagesize;
 
-  abort ();
   return 0;
 }
 
@@ -1776,7 +1774,7 @@ DESCRIPTION
 	emulation.
 
 RETURNS
-	Returns the common page size in bytes for ELF, abort otherwise.
+	Returns the common page size in bytes for ELF, 0 otherwise.
 */
 
 bfd_vma
@@ -1789,7 +1787,6 @@ bfd_emul_get_commonpagesize (const char 
       && target->flavour == bfd_target_elf_flavour)
     return xvec_get_elf_backend_data (target)->commonpagesize;
 
-  abort ();
   return 0;
 }
 
Index: ld/ldexp.c
===================================================================
RCS file: /cvs/src/src/ld/ldexp.c,v
retrieving revision 1.77
diff -u -p -r1.77 ldexp.c
--- ld/ldexp.c	29 Aug 2009 22:11:01 -0000	1.77
+++ ld/ldexp.c	30 Aug 2009 05:19:24 -0000
@@ -673,9 +673,9 @@ 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);
       else if (strcmp (tree->name.name, "COMMONPAGESIZE") == 0)
-	new_abs (bfd_emul_get_commonpagesize (default_target));
+	new_abs (config.commonpagesize);
       else
 	einfo (_("%F%S: unknown constant `%s' referenced in expression\n"),
 	       tree->name.name);
Index: ld/ldemul.c
===================================================================
RCS file: /cvs/src/src/ld/ldemul.c,v
retrieving revision 1.31
diff -u -p -r1.31 ldemul.c
--- ld/ldemul.c	10 Aug 2009 07:50:56 -0000	1.31
+++ ld/ldemul.c	30 Aug 2009 05:19:23 -0000
@@ -228,6 +228,9 @@ set_output_arch_default (void)
   /* Set the output architecture and machine if possible.  */
   bfd_set_arch_mach (link_info.output_bfd,
 		     ldfile_output_architecture, ldfile_output_machine);
+
+  bfd_emul_set_maxpagesize (output_target, config.maxpagesize);
+  bfd_emul_set_commonpagesize (output_target, config.commonpagesize);
 }
 
 void
Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.316
diff -u -p -r1.316 ldlang.c
--- ld/ldlang.c	29 Aug 2009 22:11:01 -0000	1.316
+++ ld/ldlang.c	30 Aug 2009 05:19:27 -0000
@@ -52,6 +52,7 @@ static struct obstack map_obstack;
 #define obstack_chunk_alloc xmalloc
 #define obstack_chunk_free free
 static const char *startup_file;
+static const char *entry_symbol_default = "start";
 static bfd_boolean placed_commons = FALSE;
 static bfd_boolean stripped_excluded_sections = FALSE;
 static lang_output_section_statement_type *default_common_section;
@@ -59,7 +60,6 @@ static bfd_boolean map_option_f;
 static bfd_vma print_dot;
 static lang_input_statement_type *first_file;
 static const char *current_target;
-static const char *output_target;
 static lang_statement_list_type statement_list;
 static struct bfd_hash_table lang_definedness_table;
 static lang_statement_list_type *stat_save[10];
@@ -86,13 +86,13 @@ static void lang_finalize_version_expr_h
   (struct bfd_elf_version_expr_head *);
 
 /* Exported variables.  */
+const char *output_target;
 lang_output_section_statement_type *abs_output_section;
 lang_statement_list_type lang_output_section_statement;
 lang_statement_list_type *stat_ptr = &statement_list;
 lang_statement_list_type file_chain = { NULL, NULL };
 lang_statement_list_type input_file_chain;
 struct bfd_sym_chain entry_symbol = { NULL, NULL };
-static const char *entry_symbol_default = "start";
 const char *entry_section = ".text";
 bfd_boolean entry_from_cmdline;
 bfd_boolean lang_has_input_file = FALSE;
Index: ld/ldlang.h
===================================================================
RCS file: /cvs/src/src/ld/ldlang.h,v
retrieving revision 1.84
diff -u -p -r1.84 ldlang.h
--- ld/ldlang.h	10 Aug 2009 07:50:56 -0000	1.84
+++ ld/ldlang.h	30 Aug 2009 05:19:27 -0000
@@ -445,6 +445,7 @@ struct orphan_save
   lang_output_section_statement_type **os_tail;
 };
 
+extern const char *output_target;
 extern lang_output_section_statement_type *abs_output_section;
 extern lang_statement_list_type lang_output_section_statement;
 extern bfd_boolean lang_has_input_file;
Index: ld/ldmain.c
===================================================================
RCS file: /cvs/src/src/ld/ldmain.c,v
retrieving revision 1.136
diff -u -p -r1.136 ldmain.c
--- ld/ldmain.c	27 May 2009 13:31:24 -0000	1.136
+++ ld/ldmain.c	30 Aug 2009 05:19:29 -0000
@@ -280,6 +280,8 @@ main (int argc, char **argv)
   emulation = get_emulation (argc, argv);
   ldemul_choose_mode (emulation);
   default_target = ldemul_choose_target (argc, argv);
+  config.maxpagesize = bfd_emul_get_maxpagesize (default_target);
+  config.commonpagesize = bfd_emul_get_commonpagesize (default_target);
   lang_init ();
   ldemul_before_parse ();
   lang_has_input_file = FALSE;
Index: ld/emultempl/elf32.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/elf32.em,v
retrieving revision 1.199
diff -u -p -r1.199 elf32.em
--- ld/emultempl/elf32.em	26 Aug 2009 13:08:07 -0000	1.199
+++ ld/emultempl/elf32.em	30 Aug 2009 05:19:30 -0000
@@ -2178,8 +2178,6 @@ 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);
 	}
       else if (CONST_STRNEQ (optarg, "common-page-size="))
 	{
@@ -2189,9 +2187,6 @@ 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,
-				       config.commonpagesize);
 	}
       /* What about the other Solaris -z options? FIXME.  */
       break;

-- 
Alan Modra
Australia Development Lab, IBM


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