-/* Hitachi SH specific support for 32-bit ELF
+/* Renesas / SuperH SH specific support for 32-bit ELF
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
Free Software Foundation, Inc.
Contributed by Ian Lance Taylor, Cygnus Support.
PARAMS ((bfd *, struct bfd_link_info *));
static bfd_vma dtpoff_base
PARAMS ((struct bfd_link_info *));
+static bfd_vma tpoff
+ PARAMS ((struct bfd_link_info *, bfd_vma));
static asection * sh_elf_gc_mark_hook
PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,
struct elf_link_hash_entry *, Elf_Internal_Sym *));
TRUE), /* pcrel_offset */
/* 12 bit PC relative branch divided by 2. */
+ /* This cannot be partial_inplace because relaxation can't know the
+ eventual value of a symbol. */
HOWTO (R_SH_IND12W, /* type */
1, /* rightshift */
1, /* size (0 = byte, 1 = short, 2 = long) */
TRUE, /* pc_relative */
0, /* bitpos */
complain_overflow_signed, /* complain_on_overflow */
- sh_elf_reloc, /* special_function */
+ NULL, /* special_function */
"R_SH_IND12W", /* name */
- TRUE, /* partial_inplace */
- 0xfff, /* src_mask */
+ FALSE, /* partial_inplace */
+ 0x0, /* src_mask */
0xfff, /* dst_mask */
TRUE), /* pcrel_offset */
*again = FALSE;
- if (link_info->relocateable
+ if (link_info->relocatable
|| (sec->flags & SEC_RELOC) == 0
|| sec->reloc_count == 0)
return TRUE;
symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
- internal_relocs = (_bfd_elf32_link_read_relocs
+ internal_relocs = (_bfd_elf_link_read_relocs
(abfd, sec, (PTR) NULL, (Elf_Internal_Rela *) NULL,
link_info->keep_memory));
if (internal_relocs == NULL)
/* Change the R_SH_USES reloc into an R_SH_IND12W reloc, and
replace the jsr with a bsr. */
irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irelfn->r_info), R_SH_IND12W);
+ /* We used to test (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
+ here, but that only checks if the symbol is an external symbol,
+ not if the symbol is in a different section. Besides, we need
+ a consistent meaning for the relocation, so we just assume here that
+ the value of the symbol is not available. */
+#if 0
if (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
{
/* If this needs to be changed because of future relaxing,
contents + irel->r_offset);
}
else
+#endif
{
/* We can't fully resolve this yet, because the external
symbol value may be changed by future relaxing. We let
the final link phase handle it. */
bfd_put_16 (abfd, (bfd_vma) 0xb000, contents + irel->r_offset);
}
+ irel->r_addend = -4;
/* See if there is another R_SH_USES reloc referring to the same
register load. */
/* Look for load and store instructions that we can align on four
byte boundaries. */
- if (have_code)
+ if ((elf_elfheader (abfd)->e_flags & EF_SH_MACH_MASK) != EF_SH4
+ && have_code)
{
bfd_boolean swapped;
break;
case R_SH_IND12W:
- if (ELF32_R_SYM (irel->r_info) >= symtab_hdr->sh_info)
- start = stop = addr;
+ off = insn & 0xfff;
+ if (! off)
+ {
+ /* This has been made by previous relaxation. Since the
+ relocation will be against an external symbol, the
+ final relocation will just do the right thing. */
+ start = stop = addr;
+ }
else
{
- off = insn & 0xfff;
if (off & 0x800)
off -= 0x1000;
stop = (bfd_vma) ((bfd_signed_vma) start + 4 + off * 2);
+
+ /* The addend will be against the section symbol, thus
+ for adjusting the addend, the relevant start is the
+ start of the section.
+ N.B. If we want to abandom in-place changes here and
+ test directly using symbol + addend, we have to take into
+ account that the addend has already been adjusted by -4. */
+ if (stop > addr && stop < toaddr)
+ irel->r_addend -= count;
}
break;
/* We always cache the relocs. Perhaps, if info->keep_memory is
FALSE, we should free them, if we are permitted to, when we
leave sh_coff_relax_section. */
- internal_relocs = (_bfd_elf32_link_read_relocs
+ internal_relocs = (_bfd_elf_link_read_relocs
(abfd, o, (PTR) NULL, (Elf_Internal_Rela *) NULL,
TRUE));
if (internal_relocs == NULL)
/* Number of pc-relative relocs copied for the input section. */
bfd_size_type pc_count;
-
- /* If TRUE, R_SH_TLS_TPOFF32 relocation is generated. */
- bfd_boolean tls_tpoff32;
};
/* sh ELF linker hash entry. */
}
htab = sh_elf_hash_table (info);
+ if (htab->root.dynamic_sections_created)
+ return TRUE;
/* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
.rel[a].bss sections. */
|| ! bfd_set_section_alignment (abfd, s, ptralign))
return FALSE;
- if (! create_got_section (abfd, info))
+ if (htab->sgot == NULL
+ && !create_got_section (abfd, info))
return FALSE;
{
relname = (char *) bfd_malloc ((bfd_size_type) strlen (secname) + 6);
strcpy (relname, ".rela");
strcat (relname, secname);
+ if (bfd_get_section_by_name (abfd, secname))
+ continue;
s = bfd_make_section (abfd, relname);
if (s == NULL
|| ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
struct elf_sh_link_hash_table *htab;
struct elf_sh_link_hash_entry *eh;
struct elf_sh_dyn_relocs *p;
- bfd *dynobj;
asection *s;
unsigned int power_of_two;
- dynobj = elf_hash_table (info)->dynobj;
+ htab = sh_elf_hash_table (info);
/* Make sure we know what is going on here. */
- BFD_ASSERT (dynobj != NULL
+ BFD_ASSERT (htab->root.dynobj != NULL
&& ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
|| h->weakdef != NULL
|| ((h->elf_link_hash_flags
|| h->weakdef->root.type == bfd_link_hash_defweak);
h->root.u.def.section = h->weakdef->root.u.def.section;
h->root.u.def.value = h->weakdef->root.u.def.value;
+ if (info->nocopyreloc)
+ h->elf_link_hash_flags
+ = ((h->elf_link_hash_flags & ~ELF_LINK_NON_GOT_REF)
+ | (h->weakdef->elf_link_hash_flags & ELF_LINK_NON_GOT_REF));
return TRUE;
}
both the dynamic object and the regular object will refer to the
same memory location for the variable. */
- htab = sh_elf_hash_table (info);
s = htab->sdynbss;
BFD_ASSERT (s != NULL);
/* Apply the required alignment. */
s->_raw_size = BFD_ALIGN (s->_raw_size, (bfd_size_type) (1 << power_of_two));
- if (power_of_two > bfd_get_section_alignment (dynobj, s))
+ if (power_of_two > bfd_get_section_alignment (htab->root.dynobj, s))
{
- if (! bfd_set_section_alignment (dynobj, s, power_of_two))
+ if (! bfd_set_section_alignment (htab->root.dynobj, s, power_of_two))
return FALSE;
}
will be called from elflink.h. If elflink.h doesn't call our
finish_dynamic_symbol routine, we'll need to do something about
initializing any .plt and .got entries in sh_elf_relocate_section. */
-#define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
+#define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, SHARED, H) \
((DYN) \
- && ((INFO)->shared \
+ && ((SHARED) \
|| ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
&& ((H)->dynindx != -1 \
|| ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
&& eh->gotplt_refcount > 0)
{
/* The symbol has been forced local, or we have some direct got refs,
- so treat all the gotplt refs as got refs. */
+ so treat all the gotplt refs as got refs. */
h->got.refcount += eh->gotplt_refcount;
if (h->plt.refcount >= eh->gotplt_refcount)
h->plt.refcount -= eh->gotplt_refcount;
}
if (htab->root.dynamic_sections_created
- && h->plt.refcount > 0)
+ && h->plt.refcount > 0
+ && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
+ || h->root.type != bfd_link_hash_undefweak))
{
/* Make sure this symbol is output as a dynamic symbol.
Undefined weak syms won't yet be marked as dynamic. */
return FALSE;
}
- if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info, h))
+ if (info->shared
+ || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
{
asection *s = htab->splt;
if (tls_type == GOT_TLS_GD)
s->_raw_size += 4;
dyn = htab->root.dynamic_sections_created;
- /* R_SH_TLS_IE_32 needs one dynamic relocation,
+ /* R_SH_TLS_IE_32 needs one dynamic relocation if dynamic,
R_SH_TLS_GD needs one if local symbol and two if global. */
if ((tls_type == GOT_TLS_GD && h->dynindx == -1)
- || tls_type == GOT_TLS_IE)
+ || (tls_type == GOT_TLS_IE && dyn))
htab->srelgot->_raw_size += sizeof (Elf32_External_Rela);
else if (tls_type == GOT_TLS_GD)
htab->srelgot->_raw_size += 2 * sizeof (Elf32_External_Rela);
- else if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h))
+ else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
+ || h->root.type != bfd_link_hash_undefweak)
+ && (info->shared
+ || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
htab->srelgot->_raw_size += sizeof (Elf32_External_Rela);
}
else
eh->datalabel_got.offset = s->_raw_size;
s->_raw_size += 4;
dyn = htab->root.dynamic_sections_created;
- if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h))
+ if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h))
htab->srelgot->_raw_size += sizeof (Elf32_External_Rela);
}
else
pp = &p->next;
}
}
+
+ /* Also discard relocs on undefined weak syms with non-default
+ visibility. */
+ if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
+ && h->root.type == bfd_link_hash_undefweak)
+ eh->dyn_relocs = NULL;
}
else
{
- for (p = eh->dyn_relocs; p; p = p->next)
- if (p->tls_tpoff32)
- goto keep;
-
/* For the non-shared case, discard space for relocs against
symbols which turn out to need copy relocs or are not
dynamic. */
if (htab->root.dynamic_sections_created)
{
/* Set the contents of the .interp section to the interpreter. */
- if (! info->shared)
+ if (info->executable)
{
s = bfd_get_section_by_name (dynobj, ".interp");
BFD_ASSERT (s != NULL);
#define add_dynamic_entry(TAG, VAL) \
bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
- if (! info->shared)
+ if (info->executable)
{
if (! add_dynamic_entry (DT_DEBUG, 0))
return FALSE;
(info,
_("Unexpected STO_SH5_ISA32 on local symbol is not handled"),
input_bfd, input_section, rel->r_offset));
- if (info->relocateable)
+ if (info->relocatable)
{
- /* This is a relocateable link. We don't have to change
+ /* This is a relocatable link. We don't have to change
anything, unless the reloc is against a section symbol,
in which case we have to adjust according to where the
section symbol winds up in the output section. */
{
/* Section symbol are never (?) placed in the hash table, so
we can just ignore hash relocations when creating a
- relocateable object file. */
- if (info->relocateable)
+ relocatable object file. */
+ if (info->relocatable)
continue;
h = sym_hashes[r_symndx - symtab_hdr->sh_info];
|| r_type == R_SH_GOT_MEDLOW16
|| r_type == R_SH_GOT_MEDHI16
|| r_type == R_SH_GOT_HI16)
- && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h)
+ && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
&& (! info->shared
|| (! info->symbolic && h->dynindx != -1)
|| (h->elf_link_hash_flags
else if (h->root.type == bfd_link_hash_undefweak)
relocation = 0;
else if (info->shared
- && (! info->symbolic || info->allow_shlib_undefined)
&& ! info->no_undefined
&& ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
relocation = 0;
break;
case R_SH_IND12W:
- relocation -= 4;
goto final_link_relocate;
case R_SH_DIR8WPN:
case R_SH_DIR32:
case R_SH_REL32:
if (info->shared
+ && (h == NULL
+ || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
+ || h->root.type != bfd_link_hash_undefweak)
&& r_symndx != 0
&& (input_section->flags & SEC_ALLOC) != 0
&& (r_type != R_SH_REL32
BFD_ASSERT (off != (bfd_vma) -1);
dyn = htab->root.dynamic_sections_created;
- if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h)
+ if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
|| (info->shared
&& (info->symbolic || h->dynindx == -1
|| (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
- && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
+ && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
+ || (ELF_ST_VISIBILITY (h->other)
+ && h->root.type == bfd_link_hash_undefweak))
{
/* This is actually a static link, or it is a
-Bsymbolic link and the symbol is defined
if (! info->shared
&& (h->dynindx == -1
|| (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
- {
- struct elf_sh_dyn_relocs *p;
-
- /* If TPOFF32 relocation can be created, convert it. */
- for (p = sh_elf_hash_entry (h)->dyn_relocs; p; p = p->next)
- if (p->sec == input_section && p->tls_tpoff32)
- {
- r_type = R_SH_TLS_LE_32;
- break;
- }
- }
+ r_type = R_SH_TLS_LE_32;
}
if (r_type == R_SH_TLS_GD_32 && tls_type == GOT_TLS_IE)
{
bfd_vma offset;
unsigned short insn;
- int indx;
- Elf_Internal_Rela outrel;
- bfd_byte *loc;
if (ELF32_R_TYPE (rel->r_info) == R_SH_TLS_GD_32)
{
bfd_put_16 (output_bfd, 0x0009, contents + offset + 4);
}
- if (sreloc == NULL)
- {
- const char *name;
-
- name = (bfd_elf_string_from_elf_section
- (input_bfd,
- elf_elfheader (input_bfd)->e_shstrndx,
- elf_section_data (input_section)->rel_hdr.sh_name));
- if (name == NULL)
- return FALSE;
-
- BFD_ASSERT (strncmp (name, ".rela", 5) == 0
- && strcmp (bfd_get_section_name (input_bfd,
- input_section),
- name + 5) == 0);
-
- sreloc = bfd_get_section_by_name (dynobj, name);
- BFD_ASSERT (sreloc != NULL);
- }
-
- if (h == NULL
- || h->dynindx == -1
- || (! info->shared
- && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
- indx = 0;
- else
- indx = h->dynindx;
- outrel.r_offset = (input_section->output_section->vma
- + input_section->output_offset
- + rel->r_offset);
- outrel.r_info = ELF32_R_INFO (indx, R_SH_TLS_TPOFF32);
- if (indx == 0)
- outrel.r_addend = relocation - dtpoff_base (info);
- else
- outrel.r_addend = 0;
-
- loc = sreloc->contents;
- loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
- bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
+ bfd_put_32 (output_bfd, tpoff (info, relocation),
+ contents + rel->r_offset);
continue;
}
off = local_got_offsets[r_symndx];
}
+ /* Relocate R_SH_TLS_IE_32 directly when statically linking. */
+ if (r_type == R_SH_TLS_IE_32
+ && ! htab->root.dynamic_sections_created)
+ {
+ off &= ~1;
+ bfd_put_32 (output_bfd, tpoff (info, relocation),
+ sgot->contents + off);
+ bfd_put_32 (output_bfd, sgot->output_offset + off,
+ contents + rel->r_offset);
+ continue;
+ }
+
if ((off & 1) != 0)
off &= ~1;
- else
+ else
{
Elf_Internal_Rela outrel;
bfd_byte *loc;
outrel.r_offset = (sgot->output_section->vma
+ sgot->output_offset + off);
- if (h == NULL
- || h->dynindx == -1
- || (! info->shared
- && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
+ if (h == NULL || h->dynindx == -1)
indx = 0;
else
indx = h->dynindx;
+
dr_type = (r_type == R_SH_TLS_GD_32 ? R_SH_TLS_DTPMOD32 :
R_SH_TLS_TPOFF32);
if (dr_type == R_SH_TLS_TPOFF32 && indx == 0)
case R_SH_TLS_LDO_32:
if (! info->shared)
- {
- int indx;
- Elf_Internal_Rela outrel;
- bfd_byte *loc;
-
- if (sreloc == NULL)
- {
- const char *name;
-
- name = (bfd_elf_string_from_elf_section
- (input_bfd,
- elf_elfheader (input_bfd)->e_shstrndx,
- elf_section_data (input_section)->rel_hdr.sh_name));
- if (name == NULL)
- return FALSE;
-
- BFD_ASSERT (strncmp (name, ".rela", 5) == 0
- && strcmp (bfd_get_section_name (input_bfd,
- input_section),
- name + 5) == 0);
-
- sreloc = bfd_get_section_by_name (dynobj, name);
- BFD_ASSERT (sreloc != NULL);
- }
-
- indx = (h && h->dynindx != -1) ? h->dynindx : 0;
- outrel.r_offset = (input_section->output_section->vma
- + input_section->output_offset
- + rel->r_offset);
- outrel.r_info = ELF32_R_INFO (indx, R_SH_TLS_TPOFF32);
- if (indx == 0)
- outrel.r_addend = relocation - dtpoff_base (info);
- else
- outrel.r_addend = 0;
-
- loc = sreloc->contents;
- loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
- bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
- continue;
- }
+ relocation = tpoff (info, relocation);
else
relocation -= dtpoff_base (info);
Elf_Internal_Rela outrel;
bfd_byte *loc;
+ if (! info->shared)
+ {
+ relocation = tpoff (info, relocation);
+ addend = rel->r_addend;
+ goto final_link_relocate;
+ }
+
if (sreloc == NULL)
{
const char *name;
BFD_ASSERT (sreloc != NULL);
}
- indx = (h && h->dynindx != -1) ? h->dynindx : 0;
+ if (h == NULL || h->dynindx == -1)
+ indx = 0;
+ else
+ indx = h->dynindx;
+
outrel.r_offset = (input_section->output_section->vma
+ input_section->output_offset
+ rel->r_offset);
static bfd_byte *
sh_elf_get_relocated_section_contents (output_bfd, link_info, link_order,
- data, relocateable, symbols)
+ data, relocatable, symbols)
bfd *output_bfd;
struct bfd_link_info *link_info;
struct bfd_link_order *link_order;
bfd_byte *data;
- bfd_boolean relocateable;
+ bfd_boolean relocatable;
asymbol **symbols;
{
Elf_Internal_Shdr *symtab_hdr;
/* We only need to handle the case of relaxing, or of having a
particular set of section contents, specially. */
- if (relocateable
+ if (relocatable
|| elf_section_data (input_section)->this_hdr.contents == NULL)
return bfd_generic_get_relocated_section_contents (output_bfd, link_info,
link_order, data,
- relocateable,
+ relocatable,
symbols);
symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
Elf_Internal_Sym *isym, *isymend;
bfd_size_type amt;
- internal_relocs = (_bfd_elf32_link_read_relocs
+ internal_relocs = (_bfd_elf_link_read_relocs
(input_bfd, input_section, (PTR) NULL,
(Elf_Internal_Rela *) NULL, FALSE));
if (internal_relocs == NULL)
dtpoff_base (info)
struct bfd_link_info *info;
{
- /* If tls_segment is NULL, we should have signalled an error already. */
- if (elf_hash_table (info)->tls_segment == NULL)
- return 0;
+ /* If tls_segment is NULL, we should have signalled an error already. */
+ if (elf_hash_table (info)->tls_segment == NULL)
+ return 0;
return elf_hash_table (info)->tls_segment->start;
}
+/* Return the relocation value for R_SH_TLS_TPOFF32.. */
+
+static bfd_vma
+tpoff (info, address)
+ struct bfd_link_info *info;
+ bfd_vma address;
+{
+ /* If tls_segment is NULL, we should have signalled an error already. */
+ if (elf_hash_table (info)->tls_segment == NULL)
+ return 0;
+ /* SH TLS ABI is variant I and static TLS block start just after tcbhead
+ structure which has 2 pointer fields. */
+ return (address - dtpoff_base (info) + 8);
+}
+
static asection *
sh_elf_gc_mark_hook (sec, info, rel, h, sym)
asection *sec;
struct elf_link_hash_entry **sym_hashes;
bfd_signed_vma *local_got_refcounts;
const Elf_Internal_Rela *rel, *relend;
- unsigned long r_symndx;
- struct elf_link_hash_entry *h;
- struct elf_sh_link_hash_entry *eh;
elf_section_data (sec)->local_dynrel = NULL;
relend = relocs + sec->reloc_count;
for (rel = relocs; rel < relend; rel++)
{
+ unsigned long r_symndx;
+ unsigned int r_type;
+ struct elf_link_hash_entry *h = NULL;
#ifdef INCLUDE_SHMEDIA
int seen_stt_datalabel = 0;
#endif
r_symndx = ELF32_R_SYM (rel->r_info);
- if (r_symndx < symtab_hdr->sh_info)
- h = NULL;
- else
+ if (r_symndx >= symtab_hdr->sh_info)
{
+ struct elf_sh_link_hash_entry *eh;
+ struct elf_sh_dyn_relocs **pp;
+ struct elf_sh_dyn_relocs *p;
+
h = sym_hashes[r_symndx - symtab_hdr->sh_info];
#ifdef INCLUDE_SHMEDIA
while (h->root.type == bfd_link_hash_indirect
h = (struct elf_link_hash_entry *) h->root.u.i.link;
}
#endif
+ eh = (struct elf_sh_link_hash_entry *) h;
+ for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
+ if (p->sec == sec)
+ {
+ /* Everything must go for SEC. */
+ *pp = p->next;
+ break;
+ }
}
- eh = (struct elf_sh_link_hash_entry *) h;
- switch (sh_elf_optimized_tls_reloc (info, ELF32_R_TYPE (rel->r_info),
- ELF32_R_SYM (rel->r_info)
- >= symtab_hdr->sh_info))
+ r_type = ELF32_R_TYPE (rel->r_info);
+ switch (sh_elf_optimized_tls_reloc (info, r_type, h != NULL))
{
case R_SH_TLS_LD_32:
if (sh_elf_hash_table (info)->tls_ldm_got.refcount > 0)
#ifdef INCLUDE_SHMEDIA
if (seen_stt_datalabel)
{
+ struct elf_sh_link_hash_entry *eh;
+ eh = (struct elf_sh_link_hash_entry *) h;
if (eh->datalabel_got.refcount > 0)
eh->datalabel_got.refcount -= 1;
}
case R_SH_DIR32:
case R_SH_REL32:
- if (h != NULL)
- {
- struct elf_sh_dyn_relocs **pp;
- struct elf_sh_dyn_relocs *p;
-
-
- if (!info->shared && h->plt.refcount > 0)
- h->plt.refcount -= 1;
-
- for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
- if (p->sec == sec)
- {
- if (ELF32_R_TYPE (rel->r_info) == R_SH_REL32)
- p->pc_count -= 1;
- p->count -= 1;
- if (p->count == 0)
- *pp = p->next;
- break;
- }
- }
- break;
+ if (info->shared)
+ break;
+ /* Fall thru */
case R_SH_PLT32:
#ifdef INCLUDE_SHMEDIA
#endif
if (h != NULL)
{
+ struct elf_sh_link_hash_entry *eh;
+ eh = (struct elf_sh_link_hash_entry *) h;
if (eh->gotplt_refcount > 0)
{
eh->gotplt_refcount -= 1;
eind->tls_type = GOT_UNKNOWN;
}
- _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
+ if (ind->root.type != bfd_link_hash_indirect
+ && (dir->elf_link_hash_flags & ELF_LINK_HASH_DYNAMIC_ADJUSTED) != 0)
+ /* If called to transfer flags for a weakdef during processing
+ of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF.
+ We clear it ourselves for ELIMINATE_COPY_RELOCS. */
+ dir->elf_link_hash_flags |=
+ (ind->elf_link_hash_flags & (ELF_LINK_HASH_REF_DYNAMIC
+ | ELF_LINK_HASH_REF_REGULAR
+ | ELF_LINK_HASH_REF_REGULAR_NONWEAK));
+ else
+ _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
}
static int
struct elf_sh_link_hash_table *htab;
const Elf_Internal_Rela *rel;
const Elf_Internal_Rela *rel_end;
- bfd *dynobj;
bfd_vma *local_got_offsets;
asection *sgot;
asection *srelgot;
srelgot = NULL;
sreloc = NULL;
- if (info->relocateable)
+ if (info->relocatable)
return TRUE;
symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
sym_hashes_end -= symtab_hdr->sh_info;
htab = sh_elf_hash_table (info);
- dynobj = htab->root.dynobj;
local_got_offsets = elf_local_got_offsets (abfd);
rel_end = relocs + sec->reloc_count;
case R_SH_TLS_GD_32:
case R_SH_TLS_LD_32:
case R_SH_TLS_IE_32:
- if (dynobj == NULL)
- htab->root.dynobj = dynobj = abfd;
- if (! create_got_section (dynobj, info))
- return FALSE;
+ if (htab->sgot == NULL)
+ {
+ if (htab->root.dynobj == NULL)
+ htab->root.dynobj = abfd;
+ if (!create_got_section (htab->root.dynobj, info))
+ return FALSE;
+ }
break;
default:
return FALSE;
break;
- force_got:
case R_SH_TLS_IE_32:
if (info->shared)
info->flags |= DF_STATIC_TLS;
/* FALLTHROUGH */
+ force_got:
case R_SH_TLS_GD_32:
case R_SH_GOT32:
#ifdef INCLUDE_SHMEDIA
struct elf_sh_dyn_relocs *p;
struct elf_sh_dyn_relocs **head;
- if (dynobj == NULL)
- htab->root.dynobj = dynobj = abfd;
+ if (htab->root.dynobj == NULL)
+ htab->root.dynobj = abfd;
/* When creating a shared object, we must copy these
reloc types into the output file. We create a reloc
&& strcmp (bfd_get_section_name (abfd, sec),
name + 5) == 0);
- sreloc = bfd_get_section_by_name (dynobj, name);
+ sreloc = bfd_get_section_by_name (htab->root.dynobj, name);
if (sreloc == NULL)
{
flagword flags;
- sreloc = bfd_make_section (dynobj, name);
+ sreloc = bfd_make_section (htab->root.dynobj, name);
flags = (SEC_HAS_CONTENTS | SEC_READONLY
| SEC_IN_MEMORY | SEC_LINKER_CREATED);
if ((sec->flags & SEC_ALLOC) != 0)
flags |= SEC_ALLOC | SEC_LOAD;
if (sreloc == NULL
- || ! bfd_set_section_flags (dynobj, sreloc, flags)
- || ! bfd_set_section_alignment (dynobj, sreloc, 2))
+ || ! bfd_set_section_flags (htab->root.dynobj,
+ sreloc, flags)
+ || ! bfd_set_section_alignment (htab->root.dynobj,
+ sreloc, 2))
return FALSE;
}
if (sec->flags & SEC_READONLY)
if (p == NULL || p->sec != sec)
{
bfd_size_type amt = sizeof (*p);
- p = ((struct elf_sh_dyn_relocs *) bfd_alloc (dynobj, amt));
+ p = bfd_alloc (htab->root.dynobj, amt);
if (p == NULL)
return FALSE;
p->next = *head;
p->sec = sec;
p->count = 0;
p->pc_count = 0;
- p->tls_tpoff32 = FALSE;
}
p->count += 1;
return FALSE;
}
- if (ELF32_R_TYPE (rel->r_info) == R_SH_TLS_LD_32)
- break;
+ break;
- /* FALLTHROUGH */
case R_SH_TLS_LDO_32:
- /* We make a R_SH_TLS_TPOFF32 relocation. Count it as a
- copy relocation. */
- if (! info->shared)
- {
- struct elf_sh_dyn_relocs *p;
- struct elf_sh_dyn_relocs **head;
-
- if (dynobj == NULL)
- htab->root.dynobj = dynobj = abfd;
-
- if (sreloc == NULL)
- {
- const char *name;
-
- name = (bfd_elf_string_from_elf_section
- (abfd,
- elf_elfheader (abfd)->e_shstrndx,
- elf_section_data (sec)->rel_hdr.sh_name));
- if (name == NULL)
- return FALSE;
-
- BFD_ASSERT (strncmp (name, ".rela", 5) == 0
- && strcmp (bfd_get_section_name (abfd, sec),
- name + 5) == 0);
-
- sreloc = bfd_get_section_by_name (dynobj, name);
- if (sreloc == NULL)
- {
- flagword flags;
-
- sreloc = bfd_make_section (dynobj, name);
- flags = (SEC_HAS_CONTENTS | SEC_READONLY
- | SEC_IN_MEMORY | SEC_LINKER_CREATED);
- if ((sec->flags & SEC_ALLOC) != 0)
- flags |= SEC_ALLOC | SEC_LOAD;
- if (sreloc == NULL
- || ! bfd_set_section_flags (dynobj, sreloc, flags)
- || ! bfd_set_section_alignment (dynobj, sreloc, 2))
- return FALSE;
- }
- elf_section_data (sec)->sreloc = sreloc;
- if (sec->flags & SEC_READONLY)
- info->flags |= DF_TEXTREL;
- }
-
- /* If this is a global symbol, we count the number of
- relocations we need for this symbol. */
- if (h != NULL)
- head = &((struct elf_sh_link_hash_entry *) h)->dyn_relocs;
- else
- {
- asection *s;
-
- /* Track dynamic relocs needed for local syms too. */
- s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
- sec, r_symndx);
- if (s == NULL)
- return FALSE;
-
- head = ((struct elf_sh_dyn_relocs **)
- &elf_section_data (s)->local_dynrel);
- }
-
- p = *head;
- if (p == NULL || p->sec != sec)
- {
- bfd_size_type amt = sizeof (*p);
- p = ((struct elf_sh_dyn_relocs *) bfd_alloc (dynobj, amt));
- if (p == NULL)
- return FALSE;
- p->next = *head;
- *head = p;
- p->sec = sec;
- p->count = 0;
- p->pc_count = 0;
- p->tls_tpoff32 = FALSE;
- }
-
- p->count += 1;
- p->tls_tpoff32 = TRUE;
- }
+ /* Nothing to do. */
break;
default:
Elf_Internal_Sym *sym;
{
struct elf_sh_link_hash_table *htab;
- bfd *dynobj;
htab = sh_elf_hash_table (info);
- dynobj = htab->root.dynobj;
if (h->plt.offset != (bfd_vma) -1)
{
struct bfd_link_info *info;
{
struct elf_sh_link_hash_table *htab;
- bfd *dynobj;
asection *sgot;
asection *sdyn;
htab = sh_elf_hash_table (info);
- dynobj = htab->root.dynobj;
-
sgot = htab->sgotplt;
- sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
+ sdyn = bfd_get_section_by_name (htab->root.dynobj, ".dynamic");
if (htab->root.dynamic_sections_created)
{
const char *name;
#endif
- bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
+ bfd_elf32_swap_dyn_in (htab->root.dynobj, dyncon, &dyn);
switch (dyn.d_tag)
{