public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@bigpond.net.au>
To: "H.J. Lu" <hjl.tools@gmail.com>
Cc: binutils <binutils@sources.redhat.com>
Subject: Re: PATCH: PR ld/10569: -z max-page-size may not work for linker 	scripts
Date: Sun, 30 Aug 2009 13:51:00 -0000	[thread overview]
Message-ID: <20090830054221.GM19523@bubble.grove.modra.org> (raw)
In-Reply-To: <6dc9ffc80908280737q3b02c3e1ybfec435dd9307512@mail.gmail.com>

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

  reply	other threads:[~2009-08-30  5:42 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-28  0:40 H.J. Lu
2009-08-28  3:55 ` Alan Modra
2009-08-28  5:50   ` H.J. Lu
2009-08-28  8:01     ` H.J. Lu
2009-08-28  8:09       ` Alan Modra
2009-08-28 14:31         ` H.J. Lu
2009-08-28 14:48           ` Alan Modra
2009-08-28 15:05             ` H.J. Lu
2009-08-30 13:51               ` Alan Modra [this message]
2009-08-31  2:02                 ` H.J. Lu
2009-08-31  2:50                   ` Alan Modra
2009-08-31  6:19                     ` H.J. Lu
2009-08-31  9:09                       ` Alan Modra
2009-08-31 18:16                       ` H.J. Lu
2009-09-01  0:00                         ` Alan Modra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090830054221.GM19523@bubble.grove.modra.org \
    --to=amodra@bigpond.net.au \
    --cc=binutils@sources.redhat.com \
    --cc=hjl.tools@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).