/* Renesas / SuperH SH specific support for 32-bit ELF
- Copyright (C) 1996-2020 Free Software Foundation, Inc.
+ Copyright (C) 1996-2021 Free Software Foundation, Inc.
Contributed by Ian Lance Taylor, Cygnus Support.
This file is part of BFD, the Binary File Descriptor library.
struct elf_link_hash_table root;
/* Short-cuts to get to dynamic linker sections. */
- asection *sdynbss;
- asection *srelbss;
asection *sfuncdesc;
asection *srelfuncdesc;
asection *srofixup;
/* The (unloaded but important) VxWorks .rela.plt.unloaded section. */
asection *srelplt2;
- /* Small local sym cache. */
- struct sym_cache sym_cache;
-
/* A counter or offset to track a TLS got entry. */
union
{
/* The type of PLT to use. */
const struct elf_sh_plt_info *plt_info;
- /* True if the target system is VxWorks. */
- bfd_boolean vxworks_p;
-
/* True if the target system uses FDPIC. */
bfd_boolean fdpic_p;
};
/* Get the sh ELF linker hash table from a link_info structure. */
#define sh_elf_hash_table(p) \
- (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
- == SH_ELF_DATA ? ((struct elf_sh_link_hash_table *) ((p)->hash)) : NULL)
+ ((is_elf_hash_table ((p)->hash) \
+ && elf_hash_table_id (elf_hash_table (p)) == SH_ELF_DATA) \
+ ? (struct elf_sh_link_hash_table *) (p)->hash : NULL)
/* Create an entry in an sh ELF linker hash table. */
return NULL;
}
- ret->vxworks_p = vxworks_object_p (abfd);
- ret->fdpic_p = fdpic_object_p (abfd);
+ if (fdpic_object_p (abfd))
+ {
+ ret->root.dt_pltgot_required = TRUE;
+ ret->fdpic_p = TRUE;
+ }
return &ret->root.root;
}
section into the .bss section of the final image. */
s = bfd_make_section_anyway_with_flags (abfd, ".dynbss",
SEC_ALLOC | SEC_LINKER_CREATED);
- htab->sdynbss = s;
+ htab->root.sdynbss = s;
if (s == NULL)
return FALSE;
(bed->default_use_rela_p
? ".rela.bss" : ".rel.bss"),
flags | SEC_READONLY);
- htab->srelbss = s;
+ htab->root.srelbss = s;
if (s == NULL
|| !bfd_set_section_alignment (s, ptralign))
return FALSE;
}
}
- if (htab->vxworks_p)
+ if (htab->root.target_os == is_vxworks)
{
if (!elf_vxworks_create_dynamic_sections (abfd, info, &htab->srelplt2))
return FALSE;
both the dynamic object and the regular object will refer to the
same memory location for the variable. */
- s = htab->sdynbss;
+ s = htab->root.sdynbss;
BFD_ASSERT (s != NULL);
/* We must generate a R_SH_COPY reloc to tell the dynamic linker to
{
asection *srel;
- srel = htab->srelbss;
+ srel = htab->root.srelbss;
BFD_ASSERT (srel != NULL);
srel->size += sizeof (Elf32_External_Rela);
h->needs_copy = 1;
/* We also need to make an entry in the .rel.plt section. */
htab->root.srelplt->size += sizeof (Elf32_External_Rela);
- if (htab->vxworks_p && !bfd_link_pic (info))
+ if (htab->root.target_os == is_vxworks && !bfd_link_pic (info))
{
/* VxWorks executables have a second set of relocations
for each PLT entry. They go in a separate relocation
}
}
- if (htab->vxworks_p)
+ if (htab->root.target_os == is_vxworks)
{
struct elf_dyn_relocs **pp;
linker script /DISCARD/, so we'll be discarding
the relocs too. */
}
- else if (htab->vxworks_p
+ else if (htab->root.target_os == is_vxworks
&& strcmp (p->sec->output_section->name,
".tls_vars") == 0)
{
|| s == htab->root.sgotplt
|| s == htab->sfuncdesc
|| s == htab->srofixup
- || s == htab->sdynbss)
+ || s == htab->root.sdynbss)
{
/* Strip this section if we don't need it; see the
comment below. */
}
- else if (CONST_STRNEQ (bfd_section_name (s), ".rela"))
+ else if (startswith (bfd_section_name (s), ".rela"))
{
if (s->size != 0 && s != htab->root.srelplt && s != htab->srelplt2)
relocs = TRUE;
return FALSE;
}
- if (htab->root.dynamic_sections_created)
- {
- /* Add some entries to the .dynamic section. We fill in the
- values later, in sh_elf_finish_dynamic_sections, but we
- must add the entries now so that we get the correct size for
- the .dynamic section. The DT_DEBUG entry is filled in by the
- dynamic linker and used by the debugger. */
-#define add_dynamic_entry(TAG, VAL) \
- _bfd_elf_add_dynamic_entry (info, TAG, VAL)
-
- if (bfd_link_executable (info))
- {
- if (! add_dynamic_entry (DT_DEBUG, 0))
- return FALSE;
- }
-
- if (htab->root.splt->size != 0)
- {
- if (! add_dynamic_entry (DT_PLTGOT, 0)
- || ! add_dynamic_entry (DT_PLTRELSZ, 0)
- || ! add_dynamic_entry (DT_PLTREL, DT_RELA)
- || ! add_dynamic_entry (DT_JMPREL, 0))
- return FALSE;
- }
- else if ((elf_elfheader (output_bfd)->e_flags & EF_SH_FDPIC))
- {
- if (! add_dynamic_entry (DT_PLTGOT, 0))
- return FALSE;
- }
-
- if (relocs)
- {
- if (! add_dynamic_entry (DT_RELA, 0)
- || ! add_dynamic_entry (DT_RELASZ, 0)
- || ! add_dynamic_entry (DT_RELAENT,
- sizeof (Elf32_External_Rela)))
- return FALSE;
-
- /* If any dynamic relocs apply to a read-only section,
- then we need a DT_TEXTREL entry. */
- if ((info->flags & DF_TEXTREL) == 0)
- elf_link_hash_traverse (&htab->root,
- _bfd_elf_maybe_set_textrel, info);
-
- if ((info->flags & DF_TEXTREL) != 0)
- {
- if (! add_dynamic_entry (DT_TEXTREL, 0))
- return FALSE;
- }
- }
- if (htab->vxworks_p
- && !elf_vxworks_add_dynamic_entries (output_bfd, info))
- return FALSE;
- }
-#undef add_dynamic_entry
-
- return TRUE;
+ return _bfd_elf_maybe_vxworks_add_dynamic_tags (output_bfd, info,
+ relocs);
}
\f
/* Add a dynamic relocation to the SRELOC section. */
/* We have to handle relocations in vxworks .tls_vars sections
specially, because the dynamic loader is 'weird'. */
- is_vxworks_tls = (htab && htab->vxworks_p && bfd_link_pic (info)
+ is_vxworks_tls = (htab && htab->root.target_os == is_vxworks && bfd_link_pic (info)
&& !strcmp (input_section->output_section->name,
".tls_vars"));
void *vpp;
Elf_Internal_Sym *isym;
- isym = bfd_sym_from_r_symndx (&htab->sym_cache,
+ isym = bfd_sym_from_r_symndx (&htab->root.sym_cache,
abfd, r_symndx);
if (isym == NULL)
return FALSE;
(splt->contents
+ h->plt.offset
+ plt_info->symbol_fields.got_entry));
- if (htab->vxworks_p)
+ if (htab->root.target_os == is_vxworks)
{
unsigned int reachable_plts, plts_per_4k;
int distance;
loc = srelplt->contents + plt_index * sizeof (Elf32_External_Rela);
bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
- if (htab->vxworks_p && !bfd_link_pic (info))
+ if (htab->root.target_os == is_vxworks && !bfd_link_pic (info))
{
/* Create the .rela.plt.unloaded relocations for this PLT entry.
Begin by pointing LOC to the first such relocation. */
_GLOBAL_OFFSET_TABLE_ is not absolute: it is relative to the
".got" section. */
if (h == htab->root.hdynamic
- || (!htab->vxworks_p && h == htab->root.hgot))
+ || (htab->root.target_os != is_vxworks && h == htab->root.hgot))
sym->st_shndx = SHN_ABS;
return TRUE;
switch (dyn.d_tag)
{
default:
- if (htab->vxworks_p
+ if (htab->root.target_os == is_vxworks
&& elf_vxworks_finish_dynamic_entry (output_bfd, &dyn))
bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
break;
(splt->contents
+ htab->plt_info->plt0_got_fields[i]));
- if (htab->vxworks_p)
+ if (htab->root.target_os == is_vxworks)
{
/* Finalize the .rela.plt.unloaded contents. */
Elf_Internal_Rela rel;
#define ELF_MAXPAGESIZE 0x1000
#undef ELF_COMMONPAGESIZE
+#undef ELF_TARGET_OS
+#define ELF_TARGET_OS is_vxworks
+
#include "elf32-target.h"
#endif /* not SH_TARGET_ALREADY_DEFINED */