This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
PATCH: Choose a better GP for ia64
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)
{