/* IA-64 support for 64-bit ELF
Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
- 2009 Free Software Foundation, Inc.
+ 2008, 2009 Free Software Foundation, Inc.
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
This file is part of BFD, the Binary File Descriptor library.
unsigned reltext : 1; /* are there relocs against readonly sections? */
unsigned self_dtpmod_done : 1;/* has self DTPMOD entry been finished? */
bfd_vma self_dtpmod_offset; /* .got offset to self DTPMOD entry */
+ /* There are maybe R_IA64_GPREL22 relocations, including those
+ optimized from R_IA64_LTOFF22X, against non-SHF_IA_64_SHORT
+ sections. We need to record those sections so that we can choose
+ a proper GP to cover all R_IA64_GPREL22 relocations. */
+ asection *max_short_sec; /* maximum short output section */
+ bfd_vma max_short_offset; /* maximum short offset */
+ asection *min_short_sec; /* minimum short output section */
+ bfd_vma min_short_offset; /* minimum short offset */
htab_t loc_hash_table;
void *loc_hash_memory;
static bfd_boolean
elfNN_ia64_relax_br (bfd_byte *contents, bfd_vma off)
{
- unsigned int template, mlx;
+ unsigned int template_val, mlx;
bfd_vma t0, t1, s0, s1, s2, br_code;
long br_slot;
bfd_byte *hit_addr;
/* Check if we can turn br into brl. A label is always at the start
of the bundle. Even if there are predicates on NOPs, we still
perform this optimization. */
- template = t0 & 0x1e;
+ template_val = t0 & 0x1e;
s0 = (t0 >> 5) & 0x1ffffffffffLL;
s1 = ((t0 >> 46) | (t1 << 18)) & 0x1ffffffffffLL;
s2 = (t1 >> 23) & 0x1ffffffffffLL;
case 1:
/* Check if slot 2 is NOP. Possible templates are MBB and BBB.
For BBB, slot 0 also has to be nop.b. */
- if (!((template == 0x12 /* MBB */
+ if (!((template_val == 0x12 /* MBB */
&& IS_NOP_B (s2))
- || (template == 0x16 /* BBB */
+ || (template_val == 0x16 /* BBB */
&& IS_NOP_B (s0)
&& IS_NOP_B (s2))))
return FALSE;
case 2:
/* Check if slot 1 is NOP. Possible templates are MIB, MBB, BBB,
MMB and MFB. For BBB, slot 0 also has to be nop.b. */
- if (!((template == 0x10 /* MIB */
+ if (!((template_val == 0x10 /* MIB */
&& IS_NOP_I (s1))
- || (template == 0x12 /* MBB */
+ || (template_val == 0x12 /* MBB */
&& IS_NOP_B (s1))
- || (template == 0x16 /* BBB */
+ || (template_val == 0x16 /* BBB */
&& IS_NOP_B (s0)
&& IS_NOP_B (s1))
- || (template == 0x18 /* MMB */
+ || (template_val == 0x18 /* MMB */
&& IS_NOP_M (s1))
- || (template == 0x1c /* MFB */
+ || (template_val == 0x1c /* MFB */
&& IS_NOP_F (s1))))
return FALSE;
br_code = s2;
else
mlx = 0x4;
- if (template == 0x16)
+ if (template_val == 0x16)
{
/* For BBB, we need to put nop.m in slot 0. We keep the original
predicate only if slot 0 isn't br. */
static void
elfNN_ia64_relax_brl (bfd_byte *contents, bfd_vma off)
{
- int template;
+ int template_val;
bfd_byte *hit_addr;
bfd_vma t0, t1, i0, i1, i2;
/* Turn a MLX bundle into a MBB bundle with the same stop-bit
variety. */
if (t0 & 0x1)
- template = 0x13;
+ template_val = 0x13;
else
- template = 0x12;
- t0 = (i1 << 46) | (i0 << 5) | template;
+ template_val = 0x12;
+ t0 = (i1 << 46) | (i0 << 5) | template_val;
t1 = (i2 << 23) | (i1 >> 18);
bfd_putl64 (t0, hit_addr);
\f
/* These functions do relaxation for IA-64 ELF. */
+static void
+elfNN_ia64_update_short_info (asection *sec, bfd_vma offset,
+ struct elfNN_ia64_link_hash_table *ia64_info)
+{
+ /* Skip ABS and SHF_IA_64_SHORT sections. */
+ if (sec == bfd_abs_section_ptr
+ || (sec->flags & SEC_SMALL_DATA) != 0)
+ return;
+
+ if (!ia64_info->min_short_sec)
+ {
+ ia64_info->max_short_sec = sec;
+ ia64_info->max_short_offset = offset;
+ ia64_info->min_short_sec = sec;
+ ia64_info->min_short_offset = offset;
+ }
+ else if (sec == ia64_info->max_short_sec
+ && offset > ia64_info->max_short_offset)
+ ia64_info->max_short_offset = offset;
+ else if (sec == ia64_info->min_short_sec
+ && offset < ia64_info->min_short_offset)
+ ia64_info->min_short_offset = offset;
+ else if (sec->output_section->vma
+ > ia64_info->max_short_sec->vma)
+ {
+ ia64_info->max_short_sec = sec;
+ ia64_info->max_short_offset = offset;
+ }
+ else if (sec->output_section->vma
+ < ia64_info->min_short_sec->vma)
+ {
+ ia64_info->min_short_sec = sec;
+ ia64_info->min_short_offset = offset;
+ }
+}
+
static bfd_boolean
elfNN_ia64_relax_section (bfd *abfd, asection *sec,
struct bfd_link_info *link_info,
is_branch = TRUE;
break;
+ case R_IA64_GPREL22:
+ /* Update max_short_sec/min_short_sec. */
+
case R_IA64_LTOFF22X:
case R_IA64_LDXMOV:
/* We can't relax ldx/mov in pass 0 since br relaxations will
||(bfd_signed_vma) (symaddr - gp) < -0x200000)
continue;
- if (r_type == R_IA64_LTOFF22X)
+ if (r_type == R_IA64_GPREL22)
+ elfNN_ia64_update_short_info (tsec->output_section,
+ tsec->output_offset + toff,
+ ia64_info);
+ else if (r_type == R_IA64_LTOFF22X)
{
irel->r_info = ELFNN_R_INFO (ELFNN_R_SYM (irel->r_info),
R_IA64_GPREL22);
dyn_i->want_gotx = 0;
changed_got |= !dyn_i->want_got;
}
+
+ elfNN_ia64_update_short_info (tsec->output_section,
+ tsec->output_offset + toff,
+ ia64_info);
}
else
{
struct elfNN_ia64_local_hash_entry *entry
= (struct elfNN_ia64_local_hash_entry *) ptr;
- return (((entry->id & 0xff) << 24) | ((entry->id & 0xff00) << 8))
- ^ entry->r_sym ^ (entry->id >> 16);
+ return ELF_LOCAL_SYMBOL_HASH (entry->id, entry->r_sym);
}
/* Compare local hash entries. */
{
struct elfNN_ia64_local_hash_entry e, *ret;
asection *sec = abfd->sections;
- hashval_t h = (((sec->id & 0xff) << 24) | ((sec->id & 0xff00) << 8))
- ^ ELFNN_R_SYM (rel->r_info) ^ (sec->id >> 16);
+ hashval_t h = ELF_LOCAL_SYMBOL_HASH (sec->id,
+ ELFNN_R_SYM (rel->r_info));
void **slot;
e.id = sec->id;
}
}
+ if (ia64_info->min_short_sec)
+ {
+ if (min_short_vma
+ > (ia64_info->min_short_sec->vma
+ + ia64_info->min_short_offset))
+ min_short_vma = (ia64_info->min_short_sec->vma
+ + ia64_info->min_short_offset);
+ if (max_short_vma
+ < (ia64_info->max_short_sec->vma
+ + ia64_info->max_short_offset))
+ max_short_vma = (ia64_info->max_short_sec->vma
+ + ia64_info->max_short_offset);
+ }
+
/* See if the user wants to force a value. */
gp = elf_link_hash_lookup (elf_hash_table (info), "__gp", FALSE,
FALSE, FALSE);
{
/* Pick a sensible value. */
- asection *got_sec = ia64_info->root.sgot;
+ if (ia64_info->min_short_sec)
+ {
+ bfd_vma short_range = max_short_vma - min_short_vma;
- /* 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 if (max_vma - min_vma < 0x200000)
- gp_val = min_vma;
+ /* If min_short_sec is set, pick one in the middle bewteen
+ min_short_vma and max_short_vma. */
+ if (short_range >= 0x400000)
+ goto overflow;
+ gp_val = min_short_vma + short_range / 2;
+ }
else
- gp_val = max_vma - 0x200000 + 8;
+ {
+ asection *got_sec = ia64_info->root.sgot;
+
+ /* 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 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_short_vma - min_short_vma >= 0x400000)
{
+overflow:
(*_bfd_error_handler)
(_("%s: short data segment overflowed (0x%lx >= 0x400000)"),
bfd_get_filename (abfd),
#undef elf_backend_want_p_paddr_set_to_zero
+#undef ELF_OSABI
+#define ELF_OSABI ELFOSABI_OPENVMS
+
#undef ELF_MAXPAGESIZE
#define ELF_MAXPAGESIZE 0x10000 /* 64KB */