public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Choose a better GP for ia64?
@ 2006-03-08  6:04 H. J. Lu
  2006-03-08  6:32 ` H. J. Lu
  0 siblings, 1 reply; 6+ messages in thread
From: H. J. Lu @ 2006-03-08  6:04 UTC (permalink / raw)
  To: binutils

The current ia64 linker tries to set GP to cover the whole image. I
was wondering if it was really optimal. Assuming there are no data
in text section, can we set GP to cover data sections only if it
can't cover the whole image?


H.J.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Choose a better GP for ia64?
  2006-03-08  6:04 Choose a better GP for ia64? H. J. Lu
@ 2006-03-08  6:32 ` H. J. Lu
  2006-03-08 18:20   ` PATCH: Choose a better GP for ia64 H. J. Lu
  0 siblings, 1 reply; 6+ messages in thread
From: H. J. Lu @ 2006-03-08  6:32 UTC (permalink / raw)
  To: binutils

On Tue, Mar 07, 2006 at 10:04:32PM -0800, H. J. Lu wrote:
> The current ia64 linker tries to set GP to cover the whole image. I
> was wondering if it was really optimal. Assuming there are no data
> in text section, can we set GP to cover data sections only if it
> can't cover the whole image?
> 

Never mind. I was looking at the wrong place.


H.J.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* PATCH: Choose a better GP for ia64
  2006-03-08  6:32 ` H. J. Lu
@ 2006-03-08 18:20   ` H. J. Lu
  2006-03-08 20:07     ` James E Wilson
  0 siblings, 1 reply; 6+ messages in thread
From: H. J. Lu @ 2006-03-08 18:20 UTC (permalink / raw)
  To: binutils; +Cc: wilson

On Tue, Mar 07, 2006 at 10:32:39PM -0800, H. J. Lu wrote:
> On Tue, Mar 07, 2006 at 10:04:32PM -0800, H. J. Lu wrote:
> > The current ia64 linker tries to set GP to cover the whole image. I
> > was wondering if it was really optimal. Assuming there are no data
> > in text section, can we set GP to cover data sections only if it
> > can't cover the whole image?
> > 
> 
> Never mind. I was looking at the wrong place.
> 
> 

There are 2 problems with the current elfNN_ia64_choose_gp:

1. This code

      /* Start with just the address of the .got.  */
      if (got_sec)
        gp_val = got_sec->output_section->vma;
      else if (max_short_vma != 0)
        gp_val = min_short_vma;
      else
        gp_val = min_vma;

may set gp to min_vma. Usually, data is at the higher address. Setting
gp close to max_vma is better.

2. I don't quite understand what this code

      if (max_vma - min_vma < 0x400000
          && max_vma - gp_val <= 0x200000
          && gp_val - min_vma > 0x200000)
        gp_val = min_vma + 0x200000;

is trying to do. When max_vma - min_vma < 0x400000, we want to put
gp in the middle. Assuming gp_val starts with min_vma, gp_val - min_vma
is 0. The current code may wind up with max_vma == 0x400000,
min_vma == 0x100000 and gp_val == 0x100000. It results in
max_vma - gp_val == 0x300000.

This patch fixes both.


H.J.
---
2006-03-08  H.J. Lu  <hongjiu.lu@intel.com>

	* elfxx-ia64.c (elfNN_ia64_choose_gp): Properly choose gp.

--- bfd/elfxx-ia64.c.gp	2006-03-07 17:49:19.000000000 -0800
+++ bfd/elfxx-ia64.c	2006-03-08 09:54:49.000000000 -0800
@@ -3928,14 +3928,15 @@ elfNN_ia64_choose_gp (abfd, info)
 	gp_val = got_sec->output_section->vma;
       else if (max_short_vma != 0)
 	gp_val = min_short_vma;
-      else
+      else if (max_vma - min_vma < 0x400000)
 	gp_val = min_vma;
+      else
+	gp_val = max_vma - 0x200000 + 8;
 
       /* If it is possible to address the entire image, but we
 	 don't with the choice above, adjust.  */
       if (max_vma - min_vma < 0x400000
-	  && max_vma - gp_val <= 0x200000
-	  && gp_val - min_vma > 0x200000)
+	  && max_vma - gp_val > 0x200000)
 	gp_val = min_vma + 0x200000;
       else if (max_short_vma != 0)
 	{

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PATCH: Choose a better GP for ia64
  2006-03-08 18:20   ` PATCH: Choose a better GP for ia64 H. J. Lu
@ 2006-03-08 20:07     ` James E Wilson
  2006-03-08 20:51       ` H. J. Lu
  0 siblings, 1 reply; 6+ messages in thread
From: James E Wilson @ 2006-03-08 20:07 UTC (permalink / raw)
  To: H. J. Lu; +Cc: binutils

On Wed, 2006-03-08 at 10:20, H. J. Lu wrote:
> 2. I don't quite understand what this code
>       if (max_vma - min_vma < 0x400000
>           && max_vma - gp_val <= 0x200000
>           && gp_val - min_vma > 0x200000)
>         gp_val = min_vma + 0x200000;
> is trying to do.

This handles the case where the gp_val is set too high.  Suppose we end
up with max_vma == 0x400000, gp_val == 0x400000, and min_vma ==
0x100000.  This code will trigger, and set gp_val to 0x300000.  Your
revised code won't handle this case.

However, you are right that the current code won't handle the case where
gp_val was set too low.  So, really, there are two cases we need to test
for and handle here.  One case where gp_val was set too high, and one
case where gp_val was set too low.  So I think the code should be
something like
  if (max_vma - min_vma < 0x400000
      && ((max_vma - gp_val > 0x200000)
	  || (gp_val - min_vma > 0x200000)))
    gp_val = min_vma + 0x200000;

Also, this code
+      else if (max_vma - min_vma < 0x400000)
        gp_val = min_vma;
I think should be testing against 0x200000 instead of 0x400000. 
Otherwise, you are giving gp_val a value which may be wrong, since it
won't cover the entire image if it is between 0x200000 and 0x400000. 
This also makes the code easier to understand, since clearly the next
line is not safe if the image size is less than 0x200000.
-- 
Jim Wilson, GNU Tools Support, http://www.specifix.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PATCH: Choose a better GP for ia64
  2006-03-08 20:07     ` James E Wilson
@ 2006-03-08 20:51       ` H. J. Lu
  2006-03-08 21:18         ` James E Wilson
  0 siblings, 1 reply; 6+ messages in thread
From: H. J. Lu @ 2006-03-08 20:51 UTC (permalink / raw)
  To: James E Wilson; +Cc: binutils

On Wed, Mar 08, 2006 at 12:07:08PM -0800, James E Wilson wrote:
> On Wed, 2006-03-08 at 10:20, H. J. Lu wrote:
> > 2. I don't quite understand what this code
> >       if (max_vma - min_vma < 0x400000
> >           && max_vma - gp_val <= 0x200000
> >           && gp_val - min_vma > 0x200000)
> >         gp_val = min_vma + 0x200000;
> > is trying to do.
> 
> This handles the case where the gp_val is set too high.  Suppose we end
> up with max_vma == 0x400000, gp_val == 0x400000, and min_vma ==
> 0x100000.  This code will trigger, and set gp_val to 0x300000.  Your
> revised code won't handle this case.
> 
> However, you are right that the current code won't handle the case where
> gp_val was set too low.  So, really, there are two cases we need to test
> for and handle here.  One case where gp_val was set too high, and one
> case where gp_val was set too low.  So I think the code should be
> something like
>   if (max_vma - min_vma < 0x400000
>       && ((max_vma - gp_val > 0x200000)
> 	  || (gp_val - min_vma > 0x200000)))
>     gp_val = min_vma + 0x200000;

I think it should be

   if (max_vma - min_vma < 0x400000
       && ((max_vma - gp_val >= 0x200000)
 	  || (gp_val - min_vma > 0x200000)))
     gp_val = min_vma + 0x200000;

Otherwise, max_vma == 0x400000, min_vma == 0x100000 and gp_val ==
0x200000 won't cover the whole image.

> 
> Also, this code
> +      else if (max_vma - min_vma < 0x400000)
>         gp_val = min_vma;
> I think should be testing against 0x200000 instead of 0x400000. 
> Otherwise, you are giving gp_val a value which may be wrong, since it
> won't cover the entire image if it is between 0x200000 and 0x400000. 
> This also makes the code easier to understand, since clearly the next
> line is not safe if the image size is less than 0x200000.

Here is the updated patch.

Thanks.


H.J.
----
2006-03-08  H.J. Lu  <hongjiu.lu@intel.com>

	* elfxx-ia64.c (elfNN_ia64_choose_gp): Properly choose gp.

--- bfd/elfxx-ia64.c.gp	2006-03-08 12:40:15.000000000 -0800
+++ bfd/elfxx-ia64.c	2006-03-08 12:47:37.000000000 -0800
@@ -3928,14 +3928,16 @@ elfNN_ia64_choose_gp (abfd, info)
 	gp_val = got_sec->output_section->vma;
       else if (max_short_vma != 0)
 	gp_val = min_short_vma;
-      else
+      else if (max_vma - min_vma < 0x200000)
 	gp_val = min_vma;
+      else
+	gp_val = max_vma - 0x200000 + 8;
 
       /* If it is possible to address the entire image, but we
 	 don't with the choice above, adjust.  */
       if (max_vma - min_vma < 0x400000
-	  && max_vma - gp_val <= 0x200000
-	  && gp_val - min_vma > 0x200000)
+	  && (max_vma - gp_val >= 0x200000
+	      || gp_val - min_vma > 0x200000))
 	gp_val = min_vma + 0x200000;
       else if (max_short_vma != 0)
 	{

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PATCH: Choose a better GP for ia64
  2006-03-08 20:51       ` H. J. Lu
@ 2006-03-08 21:18         ` James E Wilson
  0 siblings, 0 replies; 6+ messages in thread
From: James E Wilson @ 2006-03-08 21:18 UTC (permalink / raw)
  To: H. J. Lu; +Cc: binutils

On Wed, 2006-03-08 at 12:51, H. J. Lu wrote:
> 	* elfxx-ia64.c (elfNN_ia64_choose_gp): Properly choose gp.

OK.
-- 
Jim Wilson, GNU Tools Support, http://www.specifix.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-03-08 21:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-08  6:04 Choose a better GP for ia64? H. J. Lu
2006-03-08  6:32 ` H. J. Lu
2006-03-08 18:20   ` PATCH: Choose a better GP for ia64 H. J. Lu
2006-03-08 20:07     ` James E Wilson
2006-03-08 20:51       ` H. J. Lu
2006-03-08 21:18         ` James E Wilson

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