/* CRIS-specific support for 32-bit ELF.
- Copyright 2000, 2001 Free Software Foundation, Inc.
+ Copyright 2000, 2001, 2002 Free Software Foundation, Inc.
Contributed by Axis Communications AB.
Written by Hans-Peter Nilsson, based on elf32-fr30.c
PIC and shlib bits based primarily on elf32-m68k.c and elf32-i386.c.
const Elf_Internal_Rela *));
static asection * cris_elf_gc_mark_hook
- PARAMS ((bfd *, struct bfd_link_info *, Elf_Internal_Rela *,
+ PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,
struct elf_link_hash_entry *, Elf_Internal_Sym *));
static boolean cris_elf_object_p PARAMS ((bfd *));
static boolean elf_cris_finish_dynamic_sections
PARAMS ((bfd *, struct bfd_link_info *));
static void elf_cris_hide_symbol
- PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
+ PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *, boolean));
static enum elf_reloc_type_class elf_cris_reloc_type_class
PARAMS ((const Elf_Internal_Rela *));
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
- "R_CRIS_16", /* name */
+ "R_CRIS_16_PCREL", /* name */
false, /* partial_inplace */
0x00000000, /* src_mask */
0x0000ffff, /* dst_mask */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
- "R_CRIS_32", /* name */
+ "R_CRIS_32_PCREL", /* name */
false, /* partial_inplace */
0x00000000, /* src_mask */
0xffffffff, /* dst_mask */
static const bfd_byte elf_cris_plt0_entry[PLT_ENTRY_SIZE] =
{
0xfc, 0xe1,
- 0x7e, 0x7e, /* push mof. */
+ 0x7e, 0x7e, /* push mof. */
0x7f, 0x0d, /* (dip [pc+]) */
0, 0, 0, 0, /* Replaced with address of .got + 4. */
0x30, 0x7a, /* move [...],mof */
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, amt));
+ ret = ((struct elf_cris_link_hash_table *) bfd_malloc (amt));
if (ret == (struct elf_cris_link_hash_table *) NULL)
return NULL;
if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
elf_cris_link_hash_newfunc))
{
- bfd_release (abfd, ret);
+ free (ret);
return NULL;
}
return false;
}
+ /* This can happen if we get a link error with the input ELF
+ variant mismatching the output variant. Emit an error so
+ it's noticed if it happens elsewhere. */
+ if (sgot == NULL)
+ {
+ (*_bfd_error_handler)
+ (_("%s: relocation %s in section %s with no GOT created"),
+ bfd_archive_filename (input_bfd),
+ cris_elf_howto_table[r_type].name,
+ bfd_get_section_name (input_bfd, input_section));
+ bfd_set_error (bfd_error_bad_value);
+ return false;
+ }
+
/* This relocation is like a PC-relative one, except the
reference point is the location of GOT. Note that
sgot->output_offset is not involved in this calculation. We
}
skip = false;
+ relocate = false;
outrel.r_offset =
_bfd_elf_section_offset (output_bfd, info, input_section,
rel->r_offset);
if (outrel.r_offset == (bfd_vma) -1)
skip = true;
+ else if (outrel.r_offset == (bfd_vma) -2)
+ skip = true, relocate = true;
outrel.r_offset += (input_section->output_section->vma
+ input_section->output_offset);
if (skip)
- {
- memset (&outrel, 0, sizeof outrel);
- relocate = false;
- }
+ memset (&outrel, 0, sizeof outrel);
/* h->dynindx may be -1 if the symbol was marked to
become local. */
else if (h != NULL
& ELF_LINK_HASH_DEF_REGULAR) == 0))
{
BFD_ASSERT (h->dynindx != -1);
- relocate = false;
outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
outrel.r_addend = relocation + rel->r_addend;
}
BFD_ASSERT (indx > 0);
}
- relocate = false;
outrel.r_info = ELF32_R_INFO (indx, r_type);
outrel.r_addend = relocation + rel->r_addend;
}
relocation. */
static asection *
-cris_elf_gc_mark_hook (abfd, info, rel, h, sym)
- bfd * abfd;
+cris_elf_gc_mark_hook (sec, info, rel, h, sym)
+ asection * sec;
struct bfd_link_info * info ATTRIBUTE_UNUSED;
Elf_Internal_Rela * rel;
struct elf_link_hash_entry * h;
}
}
else
- {
- if (!(elf_bad_symtab (abfd)
- && ELF_ST_BIND (sym->st_info) != STB_LOCAL)
- && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE)
- && sym->st_shndx != SHN_COMMON))
- {
- return bfd_section_from_elf_index (abfd, sym->st_shndx);
- }
- }
+ return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
return NULL;
}
BFD_ASSERT (dynobj != NULL);
+ if (h->root.root.type == bfd_link_hash_warning)
+ h = (struct elf_cris_link_hash_entry *) h->root.root.u.i.link;
+
/* If nobody wanted a GOTPLT with this symbol, we're done. */
if (h->gotplt_refcount <= 0)
return true;
h->gotplt_refcount = -1;
- /* We always have a .got section when there are dynamic
- relocs. */
- BFD_ASSERT (sgot != NULL /* Surely have .got section. */);
-
- /* We might have had a PLT but with no GOT entry and
- further no GOT reloc section at all needed before.
- Add it. */
- if (srelgot == NULL)
- {
- srelgot = bfd_make_section (dynobj, ".rela.got");
-
- if (srelgot == NULL
- || !bfd_set_section_flags (dynobj, srelgot,
- (SEC_ALLOC
- | SEC_LOAD
- | SEC_HAS_CONTENTS
- | SEC_IN_MEMORY
- | SEC_LINKER_CREATED
- | SEC_READONLY))
- || !bfd_set_section_alignment (dynobj, srelgot, 2))
- return false;
- }
+ /* We always have a .got and a .rela.got section if there were
+ GOTPLT relocs in input. */
+ BFD_ASSERT (sgot != NULL && srelgot != NULL);
/* Allocate space in the .got section. */
sgot->_raw_size += 4;
entry. */
static void
-elf_cris_hide_symbol (info, h)
+elf_cris_hide_symbol (info, h, force_local)
struct bfd_link_info *info;
struct elf_link_hash_entry *h;
+ boolean force_local;
{
elf_cris_adjust_gotplt_to_got ((struct elf_cris_link_hash_entry *) h, info);
- _bfd_elf_link_hash_hide_symbol (info, h);
+ _bfd_elf_link_hash_hide_symbol (info, h, force_local);
}
/* Adjust a symbol defined by a dynamic object and referenced by a
specific GOT entry). */
switch (r_type)
{
+ /* For R_CRIS_16_GOTPLT and R_CRIS_32_GOTPLT, we need a GOT
+ entry only for local symbols. Unfortunately, we don't know
+ until later on if there's a version script that forces the
+ symbol local. We must have the .rela.got section in place
+ before we know if the symbol looks global now, so we need
+ to treat the reloc just like for R_CRIS_16_GOT and
+ R_CRIS_32_GOT. */
+ case R_CRIS_16_GOTPLT:
+ case R_CRIS_32_GOTPLT:
case R_CRIS_16_GOT:
case R_CRIS_32_GOT:
+ if (srelgot == NULL
+ && (h != NULL || info->shared))
+ {
+ srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
+ if (srelgot == NULL)
+ {
+ srelgot = bfd_make_section (dynobj, ".rela.got");
+ if (srelgot == NULL
+ || !bfd_set_section_flags (dynobj, srelgot,
+ (SEC_ALLOC
+ | SEC_LOAD
+ | SEC_HAS_CONTENTS
+ | SEC_IN_MEMORY
+ | SEC_LINKER_CREATED
+ | SEC_READONLY))
+ || !bfd_set_section_alignment (dynobj, srelgot, 2))
+ return false;
+ }
+ }
+ /* Fall through. */
+
case R_CRIS_32_GOTREL:
case R_CRIS_32_PLT_GOTREL:
if (sgot == NULL)
case R_CRIS_16_GOT:
case R_CRIS_32_GOT:
/* This symbol requires a global offset table entry. */
-
- if (srelgot == NULL
- && (h != NULL || info->shared))
- {
- srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
- if (srelgot == NULL)
- {
- srelgot = bfd_make_section (dynobj, ".rela.got");
- if (srelgot == NULL
- || !bfd_set_section_flags (dynobj, srelgot,
- (SEC_ALLOC
- | SEC_LOAD
- | SEC_HAS_CONTENTS
- | SEC_IN_MEMORY
- | SEC_LINKER_CREATED
- | SEC_READONLY))
- || !bfd_set_section_alignment (dynobj, srelgot, 2))
- return false;
- }
- }
-
if (h != NULL)
{
if (h->got.refcount == 0)
struct elf_cris_pcrel_relocs_copied *s;
struct bfd_link_info *info = (struct bfd_link_info *) inf;
+ if (h->root.root.type == bfd_link_hash_warning)
+ h = (struct elf_cris_link_hash_entry *) h->root.root.u.i.link;
+
/* If a symbol has been forced local or we have found a regular
definition for the symbolic link case, then we won't be needing
any relocs. */
{
struct bfd_link_info *info = (struct bfd_link_info *) inf;
+ if (h->root.root.type == bfd_link_hash_warning)
+ h = (struct elf_cris_link_hash_entry *) h->root.root.u.i.link;
+
/* 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
/* 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;
+ introduce new problems. Of course we don't do this if we're
+ exporting all dynamic symbols. */
+ if (! info->export_dynamic)
+ {
+ h->root.dynindx = -1;
+ _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
+ h->root.dynstr_index);
+ }
}
return true;
{
flagword old_flags, new_flags;
- if (_bfd_generic_verify_endian_match (ibfd, obfd) == false)
+ if (! _bfd_generic_verify_endian_match (ibfd, obfd))
return false;
if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour