public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: binutils <binutils@sources.redhat.com>
Subject: Re: PATCH: PR ld/10569: -z max-page-size may not work for linker  	scripts
Date: Fri, 28 Aug 2009 14:31:00 -0000	[thread overview]
Message-ID: <6dc9ffc80908280640q35b52922gda316d43127b7ab7@mail.gmail.com> (raw)
In-Reply-To: <20090828055016.GE19523@bubble.grove.modra.org>

[-- Attachment #1: Type: text/plain, Size: 2599 bytes --]

On Thu, Aug 27, 2009 at 10:50 PM, Alan Modra<amodra@bigpond.net.au> wrote:
> On Thu, Aug 27, 2009 at 08:55:46PM -0700, H.J. Lu wrote:
>> On Thu, Aug 27, 2009 at 8:32 PM, H.J. Lu<hjl.tools@gmail.com> wrote:
>> > On Thu, Aug 27, 2009 at 8:14 PM, Alan Modra<amodra@bigpond.net.au> wrote:
>> >> I think this is the wrong place to call bfd_emul_set_maxpagesize
>> >> (and the current call in elf32.em is wrong too).  You probably should
>> >> be calling bfd_emul_set_maxpagesize in open_output.  Also,
>> >
>> > Will open_output be called before any linker scripts are processed?
>
> Depends on what you mean by processed.  Yes, they are parsed and
> converted to internal format before open_output, but why does it
> matter?  Nothing much depends on maxpagesize until
> lang_size_sections.

This linker script:

---
SECTIONS
{
  .text : {*(.text)}
  . = ALIGN(CONSTANT (MAXPAGESIZE));
  .data : {*(.data)}
  /DISCARD/ : {*(*)}
}
---

calls fold_name on MAXPAGESIZE before open_output is called.

>
> Perhaps even a nicer patch would be to put your
> bfd_emul_set_maxpagesize calls in a LD_EMUL_SET_OUTPUT_ARCH hook,
> which is called just after open_output.
>
>> >> bfd_emul_get_maxpagesize in fold_name shouldn't be using
>> >> default_target.  Ditto for commonpagesize.
>> >>
>> >
>> > That is true. I will fix it.
>>
>> There is no easy fix. Should we just set max/common page sizes for
>> all enabled ELF targets?
>
> Why can't you use output_target?
>

We may set and get page sizes in linker. In linker script, we should use
emulation target, which may be different from output target, to get
page size, We need to set page size for emulation target in
gld${EMULATION_NAME}_handle_option. We also need to set page
size for output target in ldemul_set_output_arch.

OK to install?

Thanks.


H.J.
---
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 (gld${EMULATION_NAME}_handle_option): 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.

[-- Attachment #2: ld-page-size-2.patch --]
[-- Type: application/octet-stream, Size: 5086 bytes --]

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);

  reply	other threads:[~2009-08-28 13:40 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 [this message]
2009-08-28 14:48           ` Alan Modra
2009-08-28 15:05             ` H.J. Lu
2009-08-30 13:51               ` Alan Modra
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=6dc9ffc80908280640q35b52922gda316d43127b7ab7@mail.gmail.com \
    --to=hjl.tools@gmail.com \
    --cc=binutils@sources.redhat.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).