/* The index of the next unused R_386_TLS_DESC slot in .rel.plt. */
bfd_vma next_tls_desc_index;
+
+ /* The index of the next unused R_386_JUMP_SLOT slot in .rel.plt. */
+ bfd_vma next_jump_slot_index;
+
+ /* The index of the next unused R_386_IRELATIVE slot in .rel.plt. */
+ bfd_vma next_irelative_index;
};
/* Get the i386 ELF linker hash table from a link_info structure. */
ret->sym_cache.abfd = NULL;
ret->srelplt2 = NULL;
ret->tls_module_base = NULL;
+ ret->next_jump_slot_index = 0;
+ ret->next_irelative_index = 0;
ret->loc_hash_table = htab_try_create (1024,
elf_i386_local_htab_hash,
_bfd_elf_link_hash_copy_indirect (info, dir, ind);
}
-typedef union
- {
- unsigned char c[2];
- uint16_t i;
- }
-i386_opcode16;
-
/* Return TRUE if the TLS access code sequence support transition
from R_TYPE. */
if (offset + 2 <= sec->size)
{
/* Make sure that it's a call *x@tlsdesc(%rax). */
- static i386_opcode16 call = { { 0xff, 0x10 } };
- return bfd_get_16 (abfd, contents + offset) == call.i;
+ static const unsigned char call[] = { 0xff, 0x10 };
+ return memcmp (contents + offset, call, 2) == 0;
}
return FALSE;
/* We also need to make an entry in the .rel.plt section. */
htab->elf.srelplt->size += sizeof (Elf32_External_Rel);
- htab->next_tls_desc_index++;
+ htab->elf.srelplt->reloc_count++;
if (get_elf_i386_backend_data (info->output_bfd)->is_vxworks
&& !info->shared)
incremented. However, when we reserve space for TLS descriptors,
it's not incremented, so in order to compute the space reserved
for them, it suffices to multiply the reloc count by the jump
- slot size. */
+ slot size.
+
+ PR ld/13302: We start next_irelative_index at the end of .rela.plt
+ so that R_386_IRELATIVE entries come last. */
if (htab->elf.srelplt)
- htab->sgotplt_jump_table_size = htab->next_tls_desc_index * 4;
+ {
+ htab->next_tls_desc_index = htab->elf.srelplt->reloc_count;
+ htab->sgotplt_jump_table_size = htab->next_tls_desc_index * 4;
+ htab->next_irelative_index = htab->elf.srelplt->reloc_count - 1;
+ }
+ else if (htab->elf.irelplt)
+ htab->next_irelative_index = htab->elf.irelplt->reloc_count - 1;
+
if (htab->elf.sgotplt)
{
case R_386_32:
/* Generate dynamic relcoation only when there is a
- non-GOF reference in a shared object. */
+ non-GOT reference in a shared object. */
if (info->shared && h->non_got_ref)
{
Elf_Internal_Rela outrel;
bfd_byte *loc;
asection *sreloc;
bfd_vma offset;
+ bfd_boolean relocate;
/* Need a dynamic relocation to get the real function
adddress. */
|| info->executable)
{
/* This symbol is resolved locally. */
- outrel.r_info = ELF32_R_INFO (0, R_386_IRELATIVE);
- bfd_put_32 (output_bfd,
- (h->root.u.def.value
- + h->root.u.def.section->output_section->vma
- + h->root.u.def.section->output_offset),
- contents + offset);
+ outrel.r_info = ELF32_R_INFO (0, R_386_RELATIVE);
+ relocate = TRUE;
}
else
- outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
+ {
+ outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
+ relocate = FALSE;
+ }
sreloc = htab->elf.irelifunc;
loc = sreloc->contents;
we need to include the symbol value so that it
becomes an addend for the dynamic reloc. For an
internal symbol, we have updated addend. */
- continue;
+ if (! relocate)
+ continue;
}
/* FALLTHROUGH */
case R_386_PC32:
not process them. */
if (unresolved_reloc
&& !((input_section->flags & SEC_DEBUGGING) != 0
- && h->def_dynamic))
+ && h->def_dynamic)
+ && _bfd_elf_section_offset (output_bfd, info, input_section,
+ rel->r_offset) != (bfd_vma) -1)
{
(*_bfd_error_handler)
(_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
if (plt == htab->elf.splt)
{
- plt_index = h->plt.offset / plt_entry_size - 1;
- got_offset = (plt_index + 3) * 4;
+ got_offset = h->plt.offset / plt_entry_size - 1;
+ got_offset = (got_offset + 3) * 4;
}
else
{
- plt_index = h->plt.offset / plt_entry_size;
- got_offset = plt_index * 4;
+ got_offset = h->plt.offset / plt_entry_size;
+ got_offset = got_offset * 4;
}
/* Fill in the entry in the procedure linkage table. */
+ abed->plt->plt_got_offset);
}
- /* Don't fill PLT entry for static executables. */
- if (plt == htab->elf.splt)
- {
- bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rel),
- plt->contents + h->plt.offset
- + abed->plt->plt_reloc_offset);
- bfd_put_32 (output_bfd, - (h->plt.offset
- + abed->plt->plt_plt_offset + 4),
- plt->contents + h->plt.offset
- + abed->plt->plt_plt_offset);
- }
-
/* Fill in the entry in the global offset table. */
bfd_put_32 (output_bfd,
(plt->output_section->vma
+ h->root.u.def.section->output_offset),
gotplt->contents + got_offset);
rel.r_info = ELF32_R_INFO (0, R_386_IRELATIVE);
+ /* R_386_IRELATIVE comes last. */
+ plt_index = htab->next_irelative_index--;
}
else
- rel.r_info = ELF32_R_INFO (h->dynindx, R_386_JUMP_SLOT);
+ {
+ rel.r_info = ELF32_R_INFO (h->dynindx, R_386_JUMP_SLOT);
+ plt_index = htab->next_jump_slot_index++;
+ }
loc = relplt->contents + plt_index * sizeof (Elf32_External_Rel);
bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
+ /* Don't fill PLT entry for static executables. */
+ if (plt == htab->elf.splt)
+ {
+ bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rel),
+ plt->contents + h->plt.offset
+ + abed->plt->plt_reloc_offset);
+ bfd_put_32 (output_bfd, - (h->plt.offset
+ + abed->plt->plt_plt_offset + 4),
+ plt->contents + h->plt.offset
+ + abed->plt->plt_plt_offset);
+ }
+
if (!h->def_regular)
{
/* Mark the symbol as undefined, rather than as defined in