aboutsummaryrefslogtreecommitdiff
path: root/bfd/elf32-i386.c
diff options
context:
space:
mode:
Diffstat (limited to 'bfd/elf32-i386.c')
-rw-r--r--bfd/elf32-i386.c99
1 files changed, 56 insertions, 43 deletions
diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index 70c579e..ade5aa8 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -1336,6 +1336,7 @@ elf_i386_check_relocs (bfd *abfd,
case R_386_GOT32:
case R_386_GOTOFF:
+ h->got.refcount += 1;
if (htab->sgot == NULL
&& !elf_i386_create_got_section (htab->elf.dynobj,
info))
@@ -1999,8 +2000,13 @@ elf_i386_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
if (h->dynindx == -1 || h->forced_local)
eh->dyn_relocs = NULL;
- /* STT_GNU_IFUNC symbol uses .got.plt, not .got. */
- h->got.refcount = 0;
+ /* STT_GNU_IFUNC symbol uses .got.plt, not .got. But for
+ shared library, we must go through GOT and we can't
+ use R_386_IRELATIVE unless it is forced local. */
+ if (!info->shared
+ || info->symbolic
+ || h->forced_local)
+ h->got.refcount = 0;
}
else if (htab->elf.dynamic_sections_created
&& h->plt.refcount > 0)
@@ -2908,55 +2914,62 @@ elf_i386_relocate_section (bfd *output_bfd,
base_got = htab->sgot;
off = h->got.offset;
- if (base_got == NULL
- || off != (bfd_vma) -1)
+ if (base_got == NULL)
abort ();
- /* We can't use h->got.offset here to save state, or
- even just remember the offset, as finish_dynamic_symbol
- would use that as offset into .got. */
-
- if (htab->splt != NULL)
- {
- plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
- off = (plt_index + 3) * 4;
- base_got = htab->sgotplt;
- }
- else
+ if (off == (bfd_vma) -1)
{
- plt_index = h->plt.offset / PLT_ENTRY_SIZE;
- off = plt_index * 4;
- base_got = htab->igotplt;
- }
-
- if (h->dynindx == -1
- || h->forced_local
- || info->symbolic)
- {
- /* This references the local defitionion. We must
- initialize this entry in the global offset table.
- Since the offset must always be a multiple of 8, we
- use the least significant bit to record whether we
- have initialized it already.
-
- When doing a dynamic link, we create a .rela.got
- relocation entry to initialize the value. This is
- done in the finish_dynamic_symbol routine. */
- if ((off & 1) != 0)
- off &= ~1;
+ /* We can't use h->got.offset here to save state, or
+ even just remember the offset, as finish_dynamic_symbol
+ would use that as offset into .got. */
+
+ if (htab->splt != NULL)
+ {
+ plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
+ off = (plt_index + 3) * 4;
+ base_got = htab->sgotplt;
+ }
else
{
- bfd_put_32 (output_bfd, relocation,
- base_got->contents + off);
- h->got.offset |= 1;
+ plt_index = h->plt.offset / PLT_ENTRY_SIZE;
+ off = plt_index * 4;
+ base_got = htab->igotplt;
}
- }
- relocation = off;
+ if (h->dynindx == -1
+ || h->forced_local
+ || info->symbolic)
+ {
+ /* This references the local defitionion. We must
+ initialize this entry in the global offset table.
+ Since the offset must always be a multiple of 8,
+ we use the least significant bit to record
+ whether we have initialized it already.
+
+ When doing a dynamic link, we create a .rela.got
+ relocation entry to initialize the value. This
+ is done in the finish_dynamic_symbol routine. */
+ if ((off & 1) != 0)
+ off &= ~1;
+ else
+ {
+ bfd_put_32 (output_bfd, relocation,
+ base_got->contents + off);
+ h->got.offset |= 1;
+ }
+ }
+
+ relocation = off;
- /* Adjust for static executables. */
- if (htab->splt == NULL)
- relocation += gotplt->output_offset;
+ /* Adjust for static executables. */
+ if (htab->splt == NULL)
+ relocation += gotplt->output_offset;
+ }
+ else
+ relocation = (base_got->output_section->vma
+ + base_got->output_offset + off
+ - gotplt->output_section->vma
+ - gotplt->output_offset);
goto do_relocation;