+ /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
+ it here if it is defined in a non-shared object. */
+ if (h != NULL
+ && h->type == STT_GNU_IFUNC
+ && h->def_regular)
+ {
+ asection *plt, *gotplt, *base_got;
+ bfd_vma plt_index;
+ const char *name;
+
+ if ((input_section->flags & SEC_ALLOC) == 0
+ || h->plt.offset == (bfd_vma) -1)
+ abort ();
+
+ /* STT_GNU_IFUNC symbol must go through PLT. */
+ if (htab->elf.splt != NULL)
+ {
+ plt = htab->elf.splt;
+ gotplt = htab->elf.sgotplt;
+ }
+ else
+ {
+ plt = htab->elf.iplt;
+ gotplt = htab->elf.igotplt;
+ }
+
+ relocation = (plt->output_section->vma
+ + plt->output_offset + h->plt.offset);
+
+ switch (r_type)
+ {
+ default:
+ if (h->root.root.string)
+ name = h->root.root.string;
+ else
+ name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
+ NULL);
+ (*_bfd_error_handler)
+ (_("%B: relocation %s against STT_GNU_IFUNC "
+ "symbol `%s' isn't handled by %s"), input_bfd,
+ elf_howto_table[r_type].name,
+ name, __FUNCTION__);
+ bfd_set_error (bfd_error_bad_value);
+ return FALSE;
+
+ case R_386_32:
+ /* Generate dynamic relcoation only when there is a
+ non-GOF reference in a shared object. */
+ if (info->shared && h->non_got_ref)
+ {
+ Elf_Internal_Rela outrel;
+ bfd_byte *loc;
+ asection *sreloc;
+ bfd_vma offset;
+
+ /* Need a dynamic relocation to get the real function
+ adddress. */
+ offset = _bfd_elf_section_offset (output_bfd,
+ info,
+ input_section,
+ rel->r_offset);
+ if (offset == (bfd_vma) -1
+ || offset == (bfd_vma) -2)
+ abort ();
+
+ outrel.r_offset = (input_section->output_section->vma
+ + input_section->output_offset
+ + offset);
+
+ if (h->dynindx == -1
+ || h->forced_local
+ || 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);
+ }
+ else
+ outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
+
+ sreloc = htab->elf.irelifunc;
+ loc = sreloc->contents;
+ loc += (sreloc->reloc_count++
+ * sizeof (Elf32_External_Rel));
+ bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
+
+ /* If this reloc is against an external symbol, we
+ do not want to fiddle with the addend. Otherwise,
+ 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;
+ }
+
+ case R_386_PC32:
+ case R_386_PLT32:
+ goto do_relocation;
+
+ case R_386_GOT32:
+ base_got = htab->elf.sgot;
+ off = h->got.offset;
+
+ if (base_got == NULL)
+ abort ();
+
+ if (off == (bfd_vma) -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->elf.splt != NULL)
+ {
+ plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
+ off = (plt_index + 3) * 4;
+ base_got = htab->elf.sgotplt;
+ }
+ else
+ {
+ plt_index = h->plt.offset / PLT_ENTRY_SIZE;
+ off = plt_index * 4;
+ base_got = htab->elf.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;
+ else
+ {
+ bfd_put_32 (output_bfd, relocation,
+ base_got->contents + off);
+ h->got.offset |= 1;
+ }
+ }
+
+ relocation = off;
+
+ /* Adjust for static executables. */
+ if (htab->elf.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);
+ /* Adjust for static executables. */
+ if (htab->elf.splt == NULL)
+ relocation += gotplt->output_offset;
+ }
+
+ goto do_relocation;
+
+ case R_386_GOTOFF:
+ relocation -= (gotplt->output_section->vma
+ + gotplt->output_offset);
+ goto do_relocation;
+ }
+ }
+