static boolean cris_elf_merge_private_bfd_data PARAMS ((bfd *, bfd *));
struct elf_cris_link_hash_entry;
-static boolean elf_cris_discard_copies
+static boolean elf_cris_discard_excess_dso_dynamics
+ PARAMS ((struct elf_cris_link_hash_entry *, PTR));
+static boolean elf_cris_discard_excess_program_dynamics
PARAMS ((struct elf_cris_link_hash_entry *, PTR));
static boolean elf_cris_adjust_gotplt_to_got
PARAMS ((struct elf_cris_link_hash_entry *, PTR));
PARAMS ((bfd *));
static boolean elf_cris_adjust_dynamic_symbol
PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
+static boolean cris_elf_check_relocs
+ PARAMS ((bfd *, struct bfd_link_info *, asection *,
+ const Elf_Internal_Rela *));
+
static boolean elf_cris_size_dynamic_sections
PARAMS ((bfd *, struct bfd_link_info *));
static boolean elf_cris_finish_dynamic_symbol
PARAMS ((bfd *, struct bfd_link_info *));
static void elf_cris_hide_symbol
PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
+static enum elf_reloc_type_class elf_cris_reloc_type_class
+ PARAMS ((int));
static reloc_howto_type cris_elf_howto_table [] =
{
bfd *abfd;
{
struct elf_cris_link_hash_table *ret;
+ bfd_size_type amt = sizeof (struct elf_cris_link_hash_table);
- ret = ((struct elf_cris_link_hash_table *)
- bfd_alloc (abfd, sizeof (struct elf_cris_link_hash_table)));
+ ret = ((struct elf_cris_link_hash_table *) bfd_alloc (abfd, amt));
if (ret == (struct elf_cris_link_hash_table *) NULL)
return NULL;
struct elf_link_hash_entry * h;
bfd_vma relocation;
bfd_reloc_status_type r;
- const char * name = NULL;
+ const char * symname = NULL;
int r_type;
r_type = ELF32_R_TYPE (rel->r_info);
+ sec->output_offset
+ sym->st_value);
- name = bfd_elf_string_from_elf_section
- (input_bfd, symtab_hdr->sh_link, sym->st_name);
- name = (name == NULL) ? bfd_section_name (input_bfd, sec) : name;
+ symname = (bfd_elf_string_from_elf_section
+ (input_bfd, symtab_hdr->sh_link, sym->st_name));
+ if (symname == NULL)
+ symname = bfd_section_name (input_bfd, sec);
}
else
{
|| h->root.type == bfd_link_hash_warning)
h = (struct elf_link_hash_entry *) h->root.u.i.link;
- name = h->root.root.string;
+ symname = h->root.root.string;
if (h->root.type == bfd_link_hash_defined
|| h->root.type == bfd_link_hash_defweak)
bfd_get_filename (bfd_my_archive (input_bfd)),
bfd_get_filename (input_bfd),
cris_elf_howto_table[r_type].name,
- name,
+ symname,
bfd_get_section_name (input_bfd, input_section));
else
(*_bfd_error_handler)
(_("%s: unresolvable relocation %s against symbol `%s' from %s section"),
bfd_get_filename (input_bfd),
cris_elf_howto_table[r_type].name,
- name,
+ symname,
bfd_get_section_name (input_bfd, input_section));
bfd_set_error (bfd_error_bad_value);
return false;
else
{
if (!(info->callbacks->undefined_symbol
- (info, name, input_bfd,
+ (info, symname, input_bfd,
input_section, rel->r_offset,
(!info->shared || info->no_undefined
|| ELF_ST_VISIBILITY (h->other)))))
break;
}
- /* We didn't make a PLT entry for this symbol, or everything is
+ /* We didn't make a PLT entry for this symbol. Maybe everything is
folded into the GOT. Other than folding, this happens when
statically linking PIC code, or when using -Bsymbolic. Check
that we instead have a GOT entry as done for us by
(_("%s: No PLT nor GOT for relocation %s against symbol `%s' from %s section"),
bfd_get_filename (input_bfd),
cris_elf_howto_table[r_type].name,
- name[0] != '\0' ? name : _("[whose name is lost]"),
+ symname[0] != '\0' ? symname : _("[whose name is lost]"),
bfd_get_section_name (input_bfd, input_section));
/* FIXME: Perhaps blaming input is not the right thing to
BFD_ASSERT (off != (bfd_vma) -1);
if (!elf_hash_table (info)->dynamic_sections_created
+ || (! info->shared && h->dynindx == -1)
|| (info->shared
&& (info->symbolic || h->dynindx == -1)
&& (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
{
+ /* This wasn't checked above for ! info->shared, but
+ must hold there if we get here; the symbol must not
+ be used in, or defined by a DSO. (Note that
+ checking for ELF_LINK_HASH_DEF_REGULAR doesn't
+ catch all cases.) */
+ BFD_ASSERT (info->shared
+ || (h->elf_link_hash_flags
+ & (ELF_LINK_HASH_REF_DYNAMIC
+ | ELF_LINK_HASH_DEF_DYNAMIC)) == 0);
+
/* This is actually a static link, or it is a
-Bsymbolic link and the symbol is defined
locally, or the symbol was forced to be local
- because of a version file. We must initialize
+ because of a version file, or we're not creating a
+ dynamic object and the symbol isn't referred to by
+ a dynamic object. We must initialize
this entry in the global offset table. Since
the offset must always be a multiple of 4, we
use the least significant bit to record whether
bfd_get_filename (input_bfd),
cris_elf_howto_table[r_type].name,
rel->r_addend,
- name[0] != '\0' ? name : _("[whose name is lost]"),
+ symname[0] != '\0' ? symname : _("[whose name is lost]"),
bfd_get_section_name (input_bfd, input_section));
bfd_set_error (bfd_error_bad_value);
(_("%s: relocation %s is not allowed for global symbol: `%s' from %s section"),
bfd_get_filename (input_bfd),
cris_elf_howto_table[r_type].name,
- name,
+ symname,
bfd_get_section_name (input_bfd, input_section));
bfd_set_error (bfd_error_bad_value);
return false;
{
case bfd_reloc_overflow:
r = info->callbacks->reloc_overflow
- (info, name, howto->name, (bfd_vma) 0,
+ (info, symname, howto->name, (bfd_vma) 0,
input_bfd, input_section, rel->r_offset);
break;
case bfd_reloc_undefined:
r = info->callbacks->undefined_symbol
- (info, name, input_bfd, input_section, rel->r_offset,
+ (info, symname, input_bfd, input_section, rel->r_offset,
true);
break;
if (msg)
r = info->callbacks->warning
- (info, msg, name, input_bfd, input_section, rel->r_offset);
+ (info, msg, symname, input_bfd, input_section, rel->r_offset);
if (! r)
return false;
}
}
- if (h->got.offset != (bfd_vma) -1)
+ /* We don't emit .got relocs for symbols that aren't in the
+ dynamic-symbols table for an ordinary program. */
+ if (h->got.offset != (bfd_vma) -1
+ && (info->shared || h->dynindx != -1))
{
asection *sgot;
asection *srela;
Elf_Internal_Rela rela;
+ bfd_byte *where;
/* This symbol has an entry in the global offset table. Set it up. */
rela.r_offset = (sgot->output_section->vma
+ sgot->output_offset
- + (h->got.offset &~ 1));
+ + (h->got.offset &~ (bfd_vma) 1));
/* If this is a static link, or it is a -Bsymbolic link and the
symbol is defined locally or was forced to be local because
of a version file, we just want to emit a RELATIVE reloc.
The entry in the global offset table will already have been
initialized in the relocate_section function. */
+ where = sgot->contents + (h->got.offset &~ (bfd_vma) 1);
if (! elf_hash_table (info)->dynamic_sections_created
|| (info->shared
&& (info->symbolic || h->dynindx == -1)
&& (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
{
rela.r_info = ELF32_R_INFO (0, R_CRIS_RELATIVE);
- rela.r_addend = bfd_get_signed_32 (output_bfd,
- (sgot->contents
- + (h->got.offset & ~1)));
+ rela.r_addend = bfd_get_signed_32 (output_bfd, where);
}
else
{
- bfd_put_32 (output_bfd, (bfd_vma) 0,
- sgot->contents + (h->got.offset & ~1));
+ bfd_put_32 (output_bfd, (bfd_vma) 0, where);
rela.r_info = ELF32_R_INFO (h->dynindx, R_CRIS_GLOB_DAT);
rela.r_addend = 0;
}
/* Make sure we emit a GOT entry if the symbol was supposed to have a PLT
entry but we found we will not create any. Called when we find we will
- not have any PLT for this symbol, by elf_cris_adjust_dynamic_symbol
- when we're doing a proper dynamic link, or
- elf_cris_size_dynamic_sections if no dynamic sections will be created
- (we're only linking static objects). */
+ not have any PLT for this symbol, by for example
+ elf_cris_adjust_dynamic_symbol when we're doing a proper dynamic link,
+ or elf_cris_size_dynamic_sections if no dynamic sections will be
+ created (we're only linking static objects). */
static boolean
elf_cris_adjust_gotplt_to_got (h, p)
}
else
{
- /* No GOT entry for this symbol. We need to create one.
- FIXME: This should be a *local* got, not a global one.
- Seriously. */
+ /* No GOT entry for this symbol. We need to create one. */
asection *sgot = bfd_get_section_by_name (dynobj, ".got");
asection *srelgot
= bfd_get_section_by_name (dynobj, ".rela.got");
if (h->gotplt_refcount == h->root.plt.refcount)
{
- /* Th only PLT references are GOTPLT references, and there are GOT
+ /* The only PLT references are GOTPLT references, and there are GOT
references. Convert PLT to GOT references. */
if (! elf_cris_adjust_gotplt_to_got (h, info))
return false;
/* This case can occur if we saw a PLT reloc in an input file,
but the symbol was never referred to by a dynamic object. In
such a case, we don't actually need to build a procedure
- linkage table, and we can just do a PC reloc instead. */
+ linkage table, and we can just do a PC reloc instead, or
+ change a .got.plt index to a .got index for GOTPLT relocs. */
BFD_ASSERT ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0);
h->plt.offset = (bfd_vma) -1;
h->root.u.def.value = s->_raw_size;
}
- /* If there's already a GOT entry, use that, not a .got.plt. The
- GOT fields still have a reference count when we get here; it's
- not yet changed to offsets. */
+ /* If there's already a GOT entry, use that, not a .got.plt. A
+ GOT field still has a reference count when we get here; it's
+ not yet changed to an offset. */
if (h->got.refcount > 0)
{
h->got.refcount += h->plt.refcount;
/* Some relocs require a global offset table (but perhaps not a
specific GOT entry). */
- switch (ELF32_R_TYPE (rel->r_info))
+ switch (r_type)
{
case R_CRIS_16_GOT:
case R_CRIS_32_GOT:
if (local_got_refcounts == NULL)
{
- size_t size;
+ bfd_size_type amt;
/* We use index local_got_refcounts[-1] to count all
GOT-relative relocations that do not have explicit
GOT entries. */
- size = (symtab_hdr->sh_info + 1) * sizeof (bfd_signed_vma);
- local_got_refcounts = ((bfd_signed_vma *)
- bfd_alloc (abfd, size));
+ amt = symtab_hdr->sh_info + 1;
+ amt *= sizeof (bfd_signed_vma);
+ local_got_refcounts = ((bfd_signed_vma *) bfd_alloc (abfd, amt));
if (local_got_refcounts == NULL)
return false;
- memset (local_got_refcounts, -1, size);
+ memset (local_got_refcounts, -1, (size_t) amt);
local_got_refcounts++;
elf_local_got_refcounts (abfd) = local_got_refcounts;
break;
}
- switch (ELF32_R_TYPE (rel->r_info))
+ switch (r_type)
{
case R_CRIS_16_GOTPLT:
case R_CRIS_32_GOTPLT:
bfd_get_filename (bfd_my_archive (abfd)),
bfd_get_filename (abfd),
sec->name,
- cris_elf_howto_table[ELF32_R_TYPE (rel->r_info)].name);
+ cris_elf_howto_table[r_type].name);
else
(*_bfd_error_handler)
(_("%s, section %s:\n relocation %s should not be used in a shared object; recompile with -fPIC"),
bfd_get_filename (abfd),
sec->name,
- cris_elf_howto_table[ELF32_R_TYPE (rel->r_info)].name);
+ cris_elf_howto_table[r_type].name);
}
/* Fall through. */
|| !bfd_set_section_alignment (dynobj, sreloc, 2))
return false;
}
+ if (sec->flags & SEC_READONLY)
+ info->flags |= DF_TEXTREL;
}
sreloc->_raw_size += sizeof (Elf32_External_Rela);
we can discard them again if the symbol is later defined by a
regular object. We know that h is really a pointer to an
elf_cris_link_hash_entry. */
- if ((ELF32_R_TYPE (rel->r_info) == R_CRIS_8_PCREL
- || ELF32_R_TYPE (rel->r_info) == R_CRIS_16_PCREL
- || ELF32_R_TYPE (rel->r_info) == R_CRIS_32_PCREL)
+ if ((r_type == R_CRIS_8_PCREL
+ || r_type == R_CRIS_16_PCREL
+ || r_type == R_CRIS_32_PCREL)
&& info->symbolic)
{
struct elf_cris_link_hash_entry *eh;
if (p == NULL)
{
p = ((struct elf_cris_pcrel_relocs_copied *)
- bfd_alloc (dynobj, sizeof *p));
+ bfd_alloc (dynobj, (bfd_size_type) sizeof *p));
if (p == NULL)
return false;
p->next = eh->pcrel_relocs_copied;
if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend))
return false;
break;
+
+ default:
+ /* Other relocs do not appear here. */
+ bfd_set_error (bfd_error_bad_value);
+ return false;
}
}
static boolean
elf_cris_size_dynamic_sections (output_bfd, info)
- bfd *output_bfd;
+ bfd *output_bfd ATTRIBUTE_UNUSED;
struct bfd_link_info *info;
{
bfd *dynobj;
asection *s;
boolean plt;
boolean relocs;
- boolean reltext;
dynobj = elf_hash_table (info)->dynobj;
BFD_ASSERT (dynobj != NULL);
allocated space for them in the check_relocs routine, but we will not
fill them in in the relocate_section routine. We also discard space
for relocs that have become for local symbols due to symbol
- visibility changes. */
+ visibility changes. For programs, we discard space for relocs for
+ symbols not referenced by any dynamic object. */
if (info->shared)
elf_cris_link_hash_traverse (elf_cris_hash_table (info),
- elf_cris_discard_copies,
+ elf_cris_discard_excess_dso_dynamics,
+ (PTR) info);
+ else
+ elf_cris_link_hash_traverse (elf_cris_hash_table (info),
+ elf_cris_discard_excess_program_dynamics,
(PTR) info);
/* The check_relocs and adjust_dynamic_symbol entry points have
memory for them. */
plt = false;
relocs = false;
- reltext = false;
for (s = dynobj->sections; s != NULL; s = s->next)
{
const char *name;
}
else
{
- asection *target;
-
/* Remember whether there are any reloc sections other
than .rela.plt. */
if (strcmp (name, ".rela.plt") != 0)
- {
- const char *outname;
-
relocs = true;
- /* If this relocation section applies to a read only
- section, then we probably need a DT_TEXTREL entry.
- The entries in the .rela.plt section are actually
- associated with .got.plt, which we created ourselves
- and so know is not readonly. */
- outname = bfd_get_section_name (output_bfd,
- s->output_section);
- target
- = bfd_get_section_by_name (output_bfd,
- outname + strlen (".rela"));
-
- /* We have to test the .text section by name, becase for
- some reason it does not have SEC_READONLY set at this
- time. That flag is actually set in ldmain.c:main
- specifically for ".text" at a time long after this
- function is called. FIXME: This might be due to a
- general bug. FIXME: Have testcase for this. */
- if (target != NULL
- && (target->flags & SEC_ALLOC) != 0
- && ((target->flags & SEC_READONLY) != 0
- || strcmp (outname + strlen (".rela"),
- ".text") == 0))
- reltext = true;
- }
-
/* We use the reloc_count field as a counter if we need
to copy relocs into the output file. */
s->reloc_count = 0;
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_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
+
if (!info->shared)
{
- if (!bfd_elf32_add_dynamic_entry (info, DT_DEBUG, 0))
+ if (!add_dynamic_entry (DT_DEBUG, 0))
return false;
}
if (plt)
{
- if (!bfd_elf32_add_dynamic_entry (info, DT_PLTGOT, 0)
- || !bfd_elf32_add_dynamic_entry (info, DT_PLTRELSZ, 0)
- || !bfd_elf32_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
- || !bfd_elf32_add_dynamic_entry (info, DT_JMPREL, 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;
}
if (relocs)
{
- if (!bfd_elf32_add_dynamic_entry (info, DT_RELA, 0)
- || !bfd_elf32_add_dynamic_entry (info, DT_RELASZ, 0)
- || !bfd_elf32_add_dynamic_entry (info, DT_RELAENT,
- sizeof (Elf32_External_Rela)))
+ 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 (reltext)
+ if ((info->flags & DF_TEXTREL) != 0)
{
- if (!bfd_elf32_add_dynamic_entry (info, DT_TEXTREL, 0))
+ if (!add_dynamic_entry (DT_TEXTREL, 0))
return false;
info->flags |= DF_TEXTREL;
}
}
+#undef add_dynamic_entry
return true;
}
relocate_section routine. */
static boolean
-elf_cris_discard_copies (h, inf)
+elf_cris_discard_excess_dso_dynamics (h, inf)
struct elf_cris_link_hash_entry *h;
PTR inf;
{
|| info->symbolic))
{
for (s = h->pcrel_relocs_copied; s != NULL; s = s->next)
- s->section->_raw_size -= s->count * sizeof (Elf32_External_Rel);
+ s->section->_raw_size -= s->count * sizeof (Elf32_External_Rela);
+ }
+
+ return true;
+}
+
+/* This function is called via elf_cris_link_hash_traverse if we are *not*
+ creating a shared object. We discard space for relocs for symbols put
+ in the .got, but which we found we do not have to resolve at run-time. */
+
+static boolean
+elf_cris_discard_excess_program_dynamics (h, inf)
+ struct elf_cris_link_hash_entry *h;
+ PTR inf;
+{
+ struct bfd_link_info *info = (struct bfd_link_info *) inf;
+
+ /* If we're not creating a shared library and have a symbol which is
+ referred to by .got references, but the symbol is defined locally,
+ (or rather, not referred to by a DSO and not defined by a DSO) then
+ lose the reloc for the .got (don't allocate room for it). */
+ if ((h->root.elf_link_hash_flags
+ & (ELF_LINK_HASH_REF_DYNAMIC | ELF_LINK_HASH_DEF_DYNAMIC)) == 0)
+ {
+ if (h->root.got.refcount > 0
+ /* The size of this section is only valid and in sync with the
+ various reference counts if we do dynamic; don't decrement it
+ otherwise. */
+ && elf_hash_table (info)->dynamic_sections_created)
+ {
+ bfd *dynobj = elf_hash_table (info)->dynobj;
+ asection *srelgot;
+
+ BFD_ASSERT (dynobj != NULL);
+
+ srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
+
+ BFD_ASSERT (srelgot != NULL);
+
+ srelgot->_raw_size -= sizeof (Elf32_External_Rela);
+ }
+
+ /* If the locally-defined symbol isn't used by a DSO, then we don't
+ have to export it as a dynamic symbol. This was already done for
+ functions; doing this for all symbols would presumably not
+ introduce new problems. */
+ h->root.dynindx = -1;
}
return true;
return true;
}
+
+
+static enum elf_reloc_type_class
+elf_cris_reloc_type_class (type)
+ int type;
+{
+ switch (type)
+ {
+ case R_CRIS_RELATIVE:
+ return reloc_class_relative;
+ case R_CRIS_JUMP_SLOT:
+ return reloc_class_plt;
+ case R_CRIS_COPY:
+ return reloc_class_copy;
+ default:
+ return reloc_class_normal;
+ }
+}
\f
#define ELF_ARCH bfd_arch_cris
#define ELF_MACHINE_CODE EM_CRIS
#define bfd_elf32_bfd_final_link \
_bfd_elf32_gc_common_final_link
#define elf_backend_hide_symbol elf_cris_hide_symbol
+#define elf_backend_reloc_type_class elf_cris_reloc_type_class
#define elf_backend_want_got_plt 1
#define elf_backend_plt_readonly 1