/* CRIS-specific support for 32-bit ELF.
- Copyright 2000, 2001 Free Software Foundation, Inc.
+ Copyright 2000, 2001, 2002, 2003 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.
-This file is part of BFD, the Binary File Descriptor library.
+ This file is part of BFD, the Binary File Descriptor library.
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "bfd.h"
#include "sysdep.h"
PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
static void cris_info_to_howto_rela
- PARAMS ((bfd *, arelent *, Elf32_Internal_Rela *));
+ PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
-static boolean cris_elf_grok_prstatus
+static bfd_boolean cris_elf_grok_prstatus
PARAMS ((bfd *abfd, Elf_Internal_Note *note));
-static boolean cris_elf_grok_psinfo
+static bfd_boolean cris_elf_grok_psinfo
PARAMS ((bfd *abfd, Elf_Internal_Note *note));
-static boolean cris_elf_relocate_section
+static bfd_boolean cris_elf_relocate_section
PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
PARAMS ((reloc_howto_type *, bfd *, asection *, bfd_byte *,
Elf_Internal_Rela *, bfd_vma));
-static boolean cris_elf_gc_sweep_hook
+static bfd_boolean cris_elf_gc_sweep_hook
PARAMS ((bfd *, struct bfd_link_info *, asection *,
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 bfd_boolean cris_elf_object_p PARAMS ((bfd *));
-static void cris_elf_final_write_processing PARAMS ((bfd *, boolean));
+static void cris_elf_final_write_processing PARAMS ((bfd *, bfd_boolean));
-static boolean cris_elf_print_private_bfd_data PARAMS ((bfd *, PTR));
+static bfd_boolean cris_elf_print_private_bfd_data PARAMS ((bfd *, PTR));
-static boolean cris_elf_merge_private_bfd_data PARAMS ((bfd *, bfd *));
+static bfd_boolean cris_elf_merge_private_bfd_data PARAMS ((bfd *, bfd *));
struct elf_cris_link_hash_entry;
-static boolean elf_cris_discard_excess_dso_dynamics
+static bfd_boolean elf_cris_discard_excess_dso_dynamics
PARAMS ((struct elf_cris_link_hash_entry *, PTR));
-static boolean elf_cris_discard_excess_program_dynamics
+static bfd_boolean elf_cris_discard_excess_program_dynamics
PARAMS ((struct elf_cris_link_hash_entry *, PTR));
-static boolean elf_cris_adjust_gotplt_to_got
+static bfd_boolean elf_cris_adjust_gotplt_to_got
PARAMS ((struct elf_cris_link_hash_entry *, PTR));
-static boolean elf_cris_try_fold_plt_to_got
+static bfd_boolean elf_cris_try_fold_plt_to_got
PARAMS ((struct elf_cris_link_hash_entry *, PTR));
static struct bfd_hash_entry *elf_cris_link_hash_newfunc
PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
static struct bfd_link_hash_table *elf_cris_link_hash_table_create
PARAMS ((bfd *));
-static boolean elf_cris_adjust_dynamic_symbol
+static bfd_boolean elf_cris_adjust_dynamic_symbol
PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
-static boolean cris_elf_check_relocs
+static bfd_boolean cris_elf_check_relocs
PARAMS ((bfd *, struct bfd_link_info *, asection *,
const Elf_Internal_Rela *));
-static boolean elf_cris_size_dynamic_sections
+static bfd_boolean elf_cris_size_dynamic_sections
PARAMS ((bfd *, struct bfd_link_info *));
-static boolean elf_cris_finish_dynamic_symbol
+static bfd_boolean elf_cris_finish_dynamic_symbol
PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
Elf_Internal_Sym *));
-static boolean elf_cris_finish_dynamic_sections
+static bfd_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 *, bfd_boolean));
static enum elf_reloc_type_class elf_cris_reloc_type_class
PARAMS ((const Elf_Internal_Rela *));
0, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
32, /* bitsize */
- false, /* pc_relative */
+ FALSE, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_CRIS_NONE", /* name */
- false, /* partial_inplace */
+ FALSE, /* partial_inplace */
0, /* src_mask */
0, /* dst_mask */
- false), /* pcrel_offset */
+ FALSE), /* pcrel_offset */
/* An 8 bit absolute relocation. */
HOWTO (R_CRIS_8, /* type */
0, /* rightshift */
0, /* size (0 = byte, 1 = short, 2 = long) */
8, /* bitsize */
- false, /* pc_relative */
+ FALSE, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_CRIS_8", /* name */
- false, /* partial_inplace */
+ FALSE, /* partial_inplace */
0x0000, /* src_mask */
0x00ff, /* dst_mask */
- false), /* pcrel_offset */
+ FALSE), /* pcrel_offset */
/* A 16 bit absolute relocation. */
HOWTO (R_CRIS_16, /* type */
0, /* rightshift */
1, /* size (0 = byte, 1 = short, 2 = long) */
16, /* bitsize */
- false, /* pc_relative */
+ FALSE, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_CRIS_16", /* name */
- false, /* partial_inplace */
+ FALSE, /* partial_inplace */
0x00000000, /* src_mask */
0x0000ffff, /* dst_mask */
- false), /* pcrel_offset */
+ FALSE), /* pcrel_offset */
/* A 32 bit absolute relocation. */
HOWTO (R_CRIS_32, /* type */
0, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
32, /* bitsize */
- false, /* pc_relative */
+ FALSE, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_CRIS_32", /* name */
- false, /* partial_inplace */
+ FALSE, /* partial_inplace */
0x00000000, /* src_mask */
0xffffffff, /* dst_mask */
- false), /* pcrel_offset */
+ FALSE), /* pcrel_offset */
/* An 8 bit PC-relative relocation. */
HOWTO (R_CRIS_8_PCREL, /* type */
0, /* rightshift */
0, /* size (0 = byte, 1 = short, 2 = long) */
8, /* bitsize */
- true, /* pc_relative */
+ TRUE, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_CRIS_8_PCREL", /* name */
- false, /* partial_inplace */
+ FALSE, /* partial_inplace */
0x0000, /* src_mask */
0x00ff, /* dst_mask */
- true), /* pcrel_offset */
+ TRUE), /* pcrel_offset */
/* A 16 bit PC-relative relocation. */
HOWTO (R_CRIS_16_PCREL, /* type */
0, /* rightshift */
1, /* size (0 = byte, 1 = short, 2 = long) */
16, /* bitsize */
- true, /* pc_relative */
+ TRUE, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
- "R_CRIS_16", /* name */
- false, /* partial_inplace */
+ "R_CRIS_16_PCREL", /* name */
+ FALSE, /* partial_inplace */
0x00000000, /* src_mask */
0x0000ffff, /* dst_mask */
- true), /* pcrel_offset */
+ TRUE), /* pcrel_offset */
/* A 32 bit PC-relative relocation. */
HOWTO (R_CRIS_32_PCREL, /* type */
0, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
32, /* bitsize */
- true, /* pc_relative */
+ TRUE, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
- "R_CRIS_32", /* name */
- false, /* partial_inplace */
+ "R_CRIS_32_PCREL", /* name */
+ FALSE, /* partial_inplace */
0x00000000, /* src_mask */
0xffffffff, /* dst_mask */
- true), /* pcrel_offset */
+ TRUE), /* pcrel_offset */
/* GNU extension to record C++ vtable hierarchy. */
HOWTO (R_CRIS_GNU_VTINHERIT, /* type */
0, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
0, /* bitsize */
- false, /* pc_relative */
+ FALSE, /* pc_relative */
0, /* bitpos */
complain_overflow_dont, /* complain_on_overflow */
NULL, /* special_function */
"R_CRIS_GNU_VTINHERIT", /* name */
- false, /* partial_inplace */
+ FALSE, /* partial_inplace */
0, /* src_mask */
0, /* dst_mask */
- false), /* pcrel_offset */
+ FALSE), /* pcrel_offset */
/* GNU extension to record C++ vtable member usage. */
HOWTO (R_CRIS_GNU_VTENTRY, /* type */
0, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
0, /* bitsize */
- false, /* pc_relative */
+ FALSE, /* pc_relative */
0, /* bitpos */
complain_overflow_dont, /* complain_on_overflow */
_bfd_elf_rel_vtable_reloc_fn, /* special_function */
"R_CRIS_GNU_VTENTRY", /* name */
- false, /* partial_inplace */
+ FALSE, /* partial_inplace */
0, /* src_mask */
0, /* dst_mask */
- false), /* pcrel_offset */
+ FALSE), /* pcrel_offset */
/* This is used only by the dynamic linker. The symbol should exist
both in the object being run and in some shared library. The
0, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
32, /* bitsize */
- false, /* pc_relative */
+ FALSE, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_CRIS_COPY", /* name */
- false, /* partial_inplace */
+ FALSE, /* partial_inplace */
0, /* src_mask */
0, /* dst_mask */
- false), /* pcrel_offset */
+ FALSE), /* pcrel_offset */
/* Like R_CRIS_32, but used when setting global offset table entries. */
HOWTO (R_CRIS_GLOB_DAT, /* type */
0, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
32, /* bitsize */
- false, /* pc_relative */
+ FALSE, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_CRIS_GLOB_DAT", /* name */
- false, /* partial_inplace */
+ FALSE, /* partial_inplace */
0, /* src_mask */
0xffffffff, /* dst_mask */
- false), /* pcrel_offset */
+ FALSE), /* pcrel_offset */
/* Marks a procedure linkage table entry for a symbol. */
HOWTO (R_CRIS_JUMP_SLOT, /* type */
0, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
32, /* bitsize */
- false, /* pc_relative */
+ FALSE, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_CRIS_JUMP_SLOT", /* name */
- false, /* partial_inplace */
+ FALSE, /* partial_inplace */
0, /* src_mask */
0, /* dst_mask */
- false), /* pcrel_offset */
+ FALSE), /* pcrel_offset */
/* Used only by the dynamic linker. When the object is run, this
longword is set to the load address of the object, plus the
0, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
32, /* bitsize */
- false, /* pc_relative */
+ FALSE, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_CRIS_RELATIVE", /* name */
- false, /* partial_inplace */
+ FALSE, /* partial_inplace */
0, /* src_mask */
0xffffffff, /* dst_mask */
- false), /* pcrel_offset */
+ FALSE), /* pcrel_offset */
/* Like R_CRIS_32, but referring to the GOT table entry for the symbol. */
HOWTO (R_CRIS_16_GOT, /* type */
0, /* rightshift */
1, /* size (0 = byte, 1 = short, 2 = long) */
16, /* bitsize */
- false, /* pc_relative */
+ FALSE, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_CRIS_16_GOT", /* name */
- false, /* partial_inplace */
+ FALSE, /* partial_inplace */
0, /* src_mask */
0xffff, /* dst_mask */
- false), /* pcrel_offset */
+ FALSE), /* pcrel_offset */
HOWTO (R_CRIS_32_GOT, /* type */
0, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
32, /* bitsize */
- false, /* pc_relative */
+ FALSE, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_CRIS_32_GOT", /* name */
- false, /* partial_inplace */
+ FALSE, /* partial_inplace */
0, /* src_mask */
0xffffffff, /* dst_mask */
- false), /* pcrel_offset */
+ FALSE), /* pcrel_offset */
/* Like R_CRIS_32_GOT, but referring to (and requesting a) PLT part of
the GOT table for the symbol. */
0, /* rightshift */
1, /* size (0 = byte, 1 = short, 2 = long) */
16, /* bitsize */
- false, /* pc_relative */
+ FALSE, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_CRIS_16_GOTPLT", /* name */
- false, /* partial_inplace */
+ FALSE, /* partial_inplace */
0, /* src_mask */
0xffff, /* dst_mask */
- false), /* pcrel_offset */
+ FALSE), /* pcrel_offset */
HOWTO (R_CRIS_32_GOTPLT, /* type */
0, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
32, /* bitsize */
- false, /* pc_relative */
+ FALSE, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_CRIS_32_GOTPLT", /* name */
- false, /* partial_inplace */
+ FALSE, /* partial_inplace */
0, /* src_mask */
0xffffffff, /* dst_mask */
- false), /* pcrel_offset */
+ FALSE), /* pcrel_offset */
/* A 32-bit offset from GOT to (local const) symbol: no GOT entry should
be necessary. */
0, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
32, /* bitsize */
- false, /* pc_relative */
+ FALSE, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_CRIS_32_GOTREL", /* name */
- false, /* partial_inplace */
+ FALSE, /* partial_inplace */
0, /* src_mask */
0xffffffff, /* dst_mask */
- false), /* pcrel_offset */
+ FALSE), /* pcrel_offset */
/* A 32-bit offset from GOT to entry for this symbol in PLT and request
to create PLT entry for symbol. */
0, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
32, /* bitsize */
- false, /* pc_relative */
+ FALSE, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_CRIS_32_PLT_GOTREL", /* name */
- false, /* partial_inplace */
+ FALSE, /* partial_inplace */
0, /* src_mask */
0xffffffff, /* dst_mask */
- false), /* pcrel_offset */
+ FALSE), /* pcrel_offset */
/* A 32-bit offset from PC (location after the relocation) + addend to
entry for this symbol in PLT and request to create PLT entry for
0, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
32, /* bitsize */
- true, /* pc_relative */
+ TRUE, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_CRIS_32_PLT_PCREL", /* name */
- false, /* partial_inplace */
+ FALSE, /* partial_inplace */
0, /* src_mask */
0xffffffff, /* dst_mask */
- true) /* pcrel_offset */
+ TRUE) /* pcrel_offset */
};
\f
/* Map BFD reloc types to CRIS ELF reloc types. */
cris_info_to_howto_rela (abfd, cache_ptr, dst)
bfd * abfd ATTRIBUTE_UNUSED;
arelent * cache_ptr;
- Elf32_Internal_Rela * dst;
+ Elf_Internal_Rela * dst;
{
unsigned int r_type;
\f
/* Support for core dump NOTE sections. */
-static boolean
+static bfd_boolean
cris_elf_grok_prstatus (abfd, note)
bfd *abfd;
Elf_Internal_Note *note;
switch (note->descsz)
{
default:
- return false;
+ return FALSE;
case 214: /* Linux/CRIS */
/* pr_cursig */
raw_size, note->descpos + offset);
}
-static boolean
+static bfd_boolean
cris_elf_grok_psinfo (abfd, note)
bfd *abfd;
Elf_Internal_Note *note;
switch (note->descsz)
{
default:
- return false;
+ return FALSE;
case 124: /* Linux/CRIS elf_prpsinfo */
elf_tdata (abfd)->core_program
command[n - 1] = '\0';
}
- return true;
+ return TRUE;
}
\f
/* The name of the dynamic interpreter. This is put in the .interp
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 */
#define elf_cris_link_hash_traverse(table, func, info) \
(elf_link_hash_traverse \
(&(table)->root, \
- (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
+ (bfd_boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
(info)))
/* Get the CRIS ELF linker hash table from a link_info structure. */
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;
}
/* Relocate an CRIS ELF section. See elf32-fr30.c, from where this was
copied, for further comments. */
-static boolean
+static bfd_boolean
cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
contents, relocs, local_syms, local_sections)
- bfd * output_bfd ATTRIBUTE_UNUSED;
- struct bfd_link_info * info;
- bfd * input_bfd;
- asection * input_section;
- bfd_byte * contents;
- Elf_Internal_Rela * relocs;
- Elf_Internal_Sym * local_syms;
- asection ** local_sections;
+ bfd *output_bfd ATTRIBUTE_UNUSED;
+ struct bfd_link_info *info;
+ bfd *input_bfd;
+ asection *input_section;
+ bfd_byte *contents;
+ Elf_Internal_Rela *relocs;
+ Elf_Internal_Sym *local_syms;
+ asection **local_sections;
{
bfd *dynobj;
- Elf_Internal_Shdr * symtab_hdr;
- struct elf_link_hash_entry ** sym_hashes;
+ Elf_Internal_Shdr *symtab_hdr;
+ struct elf_link_hash_entry **sym_hashes;
bfd_vma *local_got_offsets;
asection *sgot;
asection *splt;
asection *sreloc;
- Elf_Internal_Rela * rel;
- Elf_Internal_Rela * relend;
+ Elf_Internal_Rela *rel;
+ Elf_Internal_Rela *relend;
+
+ if (info->relocatable)
+ return TRUE;
dynobj = elf_hash_table (info)->dynobj;
local_got_offsets = elf_local_got_offsets (input_bfd);
sym_hashes = elf_sym_hashes (input_bfd);
relend = relocs + input_section->reloc_count;
- /* It seems this can happen with erroneous or unsupported input (mixing
- a.out and elf in an archive, for example.) */
- if (sym_hashes == NULL)
- return false;
-
sgot = NULL;
splt = NULL;
sreloc = NULL;
for (rel = relocs; rel < relend; rel ++)
{
- reloc_howto_type * howto;
- unsigned long r_symndx;
- Elf_Internal_Sym * sym;
- asection * sec;
- struct elf_link_hash_entry * h;
- bfd_vma relocation;
- bfd_reloc_status_type r;
- const char * symname = NULL;
- int r_type;
+ reloc_howto_type *howto;
+ unsigned long r_symndx;
+ Elf_Internal_Sym *sym;
+ asection *sec;
+ struct elf_link_hash_entry *h;
+ bfd_vma relocation;
+ bfd_reloc_status_type r;
+ const char *symname = NULL;
+ int r_type;
r_type = ELF32_R_TYPE (rel->r_info);
|| r_type == R_CRIS_GNU_VTENTRY)
continue;
- r_symndx = ELF32_R_SYM (rel->r_info);
-
- if (info->relocateable)
- {
- /* This is a relocateable 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. */
- if (r_symndx < symtab_hdr->sh_info)
- {
- sym = local_syms + r_symndx;
-
- if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
- {
- sec = local_sections [r_symndx];
- rel->r_addend += sec->output_offset + sym->st_value;
- }
- }
-
- continue;
- }
-
/* This is a final link. */
+ r_symndx = ELF32_R_SYM (rel->r_info);
howto = cris_elf_howto_table + r_type;
h = NULL;
sym = NULL;
}
else
{
+ /* It seems this can happen with erroneous or unsupported input
+ (mixing a.out and elf in an archive, for example.) */
+ if (sym_hashes == NULL)
+ return FALSE;
+
h = sym_hashes [r_symndx - symtab_hdr->sh_info];
while (h->root.type == bfd_link_hash_indirect
symname,
bfd_get_section_name (input_bfd, input_section));
bfd_set_error (bfd_error_bad_value);
- return false;
+ return FALSE;
}
}
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;
input_section, rel->r_offset,
(!info->shared || info->no_undefined
|| ELF_ST_VISIBILITY (h->other)))))
- return false;
+ return FALSE;
relocation = 0;
}
}
do; this is probably an internal error. But it is true
that we didn't like that particular input. */
bfd_set_error (bfd_error_bad_value);
- return false;
+ return FALSE;
}
/* Fall through. */
BFD_ASSERT (off != (bfd_vma) -1);
if (!elf_hash_table (info)->dynamic_sections_created
- || (! info->shared && h->dynindx == -1)
+ || (! info->shared
+ && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
|| (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
+ must hold there if we get here; the symbol must be
+ defined in the regular program, or be undefweak. */
+ BFD_ASSERT (!elf_hash_table (info)->dynamic_sections_created
+ || info->shared
|| (h->elf_link_hash_flags
- & (ELF_LINK_HASH_REF_DYNAMIC
- | ELF_LINK_HASH_DEF_DYNAMIC)) == 0);
+ & ELF_LINK_HASH_DEF_REGULAR) != 0
+ || h->root.type == bfd_link_hash_undefweak);
/* 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, 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
- 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. */
+ -Bsymbolic link and the symbol is defined locally,
+ or is undefweak, or the symbol was forced to be
+ local because of a version file, or we're not
+ creating 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 we have
+ initialized it already.
+
+ If this GOT entry should be runtime-initialized, we
+ will 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
if (info->shared)
{
- asection *srelgot;
+ asection *s;
Elf_Internal_Rela outrel;
+ bfd_byte *loc;
- srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
- BFD_ASSERT (srelgot != NULL);
+ s = bfd_get_section_by_name (dynobj, ".rela.got");
+ BFD_ASSERT (s != NULL);
outrel.r_offset = (sgot->output_section->vma
+ sgot->output_offset
+ off);
outrel.r_info = ELF32_R_INFO (0, R_CRIS_RELATIVE);
outrel.r_addend = relocation;
- bfd_elf32_swap_reloca_out (output_bfd, &outrel,
- (((Elf32_External_Rela *)
- srelgot->contents)
- + srelgot->reloc_count));
- ++srelgot->reloc_count;
+ loc = s->contents;
+ loc += s->reloc_count++ * sizeof (Elf32_External_Rela);
+ bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
}
local_got_offsets[r_symndx] |= 1;
bfd_get_section_name (input_bfd, input_section));
bfd_set_error (bfd_error_bad_value);
- return false;
+ return FALSE;
}
}
break;
case R_CRIS_32_GOTREL:
- /* This relocation must only be performed against local symbols. */
- if (h != NULL)
+ /* This relocation must only be performed against local symbols.
+ It's also ok when we link a program and the symbol is either
+ defined in an ordinary (non-DSO) object or is undefined weak. */
+ if (h != NULL
+ && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
+ && !(!info->shared
+ && ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
+ || ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
+ && h->root.type == bfd_link_hash_undefweak))))
{
(*_bfd_error_handler)
(_("%s: relocation %s is not allowed for global symbol: `%s' from %s section"),
symname,
bfd_get_section_name (input_bfd, input_section));
bfd_set_error (bfd_error_bad_value);
- return false;
+ 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
/* Resolve a PLT_PCREL reloc against a local symbol directly,
without using the procedure linkage table. */
- if (h == NULL)
+ if (h == NULL || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
break;
if (h->plt.offset == (bfd_vma) -1
/* Resolve a PLT_GOTREL reloc against a local symbol directly,
without using the procedure linkage table. */
- if (h == NULL)
+ if (h == NULL || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
break;
if (h->plt.offset == (bfd_vma) -1
case R_CRIS_16_PCREL:
case R_CRIS_32_PCREL:
/* If the symbol was local, we need no shlib-specific handling. */
- if (h == NULL)
+ if (h == NULL || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
break;
/* Fall through. */
& ELF_LINK_HASH_DEF_REGULAR) == 0)))
{
Elf_Internal_Rela outrel;
- boolean skip, relocate;
+ bfd_byte *loc;
+ bfd_boolean skip, relocate;
/* When generating a shared object, these relocations
are copied into the output file to be resolved at run
elf_elfheader (input_bfd)->e_shstrndx,
elf_section_data (input_section)->rel_hdr.sh_name));
if (name == NULL)
- return false;
+ return FALSE;
BFD_ASSERT (strncmp (name, ".rela", 5) == 0
&& strcmp (bfd_get_section_name (input_bfd,
name);
bfd_set_error (bfd_error_bad_value);
- return false;
+ return FALSE;
}
}
- skip = false;
-
- if (elf_section_data (input_section)->stab_info == NULL)
- outrel.r_offset = rel->r_offset;
- else
- {
- bfd_vma off;
-
- off = (_bfd_stab_section_offset
- (output_bfd, &elf_hash_table (info)->stab_info,
- input_section,
- &elf_section_data (input_section)->stab_info,
- rel->r_offset));
- if (off == (bfd_vma) -1)
- skip = true;
- outrel.r_offset = off;
- }
+ 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;
}
{
if (r_type == R_CRIS_32)
{
- relocate = true;
+ relocate = TRUE;
outrel.r_info = ELF32_R_INFO (0, R_CRIS_RELATIVE);
outrel.r_addend = relocation + rel->r_addend;
}
else if (sec == NULL || sec->owner == NULL)
{
bfd_set_error (bfd_error_bad_value);
- return false;
+ return FALSE;
}
else
{
BFD_ASSERT (indx > 0);
}
- relocate = false;
outrel.r_info = ELF32_R_INFO (indx, r_type);
outrel.r_addend = relocation + rel->r_addend;
}
}
- bfd_elf32_swap_reloca_out (output_bfd, &outrel,
- (((Elf32_External_Rela *)
- sreloc->contents)
- + sreloc->reloc_count));
- ++sreloc->reloc_count;
+ loc = sreloc->contents;
+ loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
+ bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
/* This reloc will be computed at runtime, so there's no
need to do anything now, except for R_CRIS_32 relocations
case bfd_reloc_undefined:
r = info->callbacks->undefined_symbol
(info, symname, input_bfd, input_section, rel->r_offset,
- true);
+ TRUE);
break;
case bfd_reloc_outofrange:
(info, msg, symname, input_bfd, input_section, rel->r_offset);
if (! r)
- return false;
+ return FALSE;
}
}
- return true;
+ return TRUE;
}
\f
/* Finish up dynamic symbol handling. We set the contents of various
dynamic sections here. */
-static boolean
+static bfd_boolean
elf_cris_finish_dynamic_symbol (output_bfd, info, h, sym)
bfd *output_bfd;
struct bfd_link_info *info;
bfd_vma gotplt_offset
= ((struct elf_cris_link_hash_entry *) h)->gotplt_offset;
Elf_Internal_Rela rela;
- boolean has_gotplt = gotplt_offset != 0;
+ bfd_byte *loc;
+ bfd_boolean has_gotplt = gotplt_offset != 0;
/* Get the index in the procedure linkage table which
corresponds to this symbol. This is the index of this symbol
+ got_offset);
rela.r_info = ELF32_R_INFO (h->dynindx, R_CRIS_JUMP_SLOT);
rela.r_addend = 0;
- bfd_elf32_swap_reloca_out (output_bfd, &rela,
- ((Elf32_External_Rela *) srela->contents
- + gotplt_index));
+ loc = srela->contents + gotplt_index * sizeof (Elf32_External_Rela);
+ bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
}
if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
}
/* We don't emit .got relocs for symbols that aren't in the
- dynamic-symbols table for an ordinary program. */
+ dynamic-symbols table for an ordinary program and are either defined
+ by the program or are undefined weak symbols. */
if (h->got.offset != (bfd_vma) -1
- && (info->shared || h->dynindx != -1))
+ && (info->shared
+ || (h->dynindx != -1
+ && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0
+ && h->root.type != bfd_link_hash_undefweak)))
{
asection *sgot;
asection *srela;
Elf_Internal_Rela rela;
+ bfd_byte *loc;
bfd_byte *where;
/* This symbol has an entry in the global offset table. Set it up. */
rela.r_addend = 0;
}
- bfd_elf32_swap_reloca_out (output_bfd, &rela,
- ((Elf32_External_Rela *) srela->contents
- + srela->reloc_count));
- ++srela->reloc_count;
+ loc = srela->contents;
+ loc += srela->reloc_count++ * sizeof (Elf32_External_Rela);
+ bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
}
if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
{
asection *s;
Elf_Internal_Rela rela;
+ bfd_byte *loc;
/* This symbol needs a copy reloc. Set it up. */
+ h->root.u.def.section->output_offset);
rela.r_info = ELF32_R_INFO (h->dynindx, R_CRIS_COPY);
rela.r_addend = 0;
- bfd_elf32_swap_reloca_out (output_bfd, &rela,
- ((Elf32_External_Rela *) s->contents
- + s->reloc_count));
- ++s->reloc_count;
+ loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
+ bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
}
/* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
|| strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
sym->st_shndx = SHN_ABS;
- return true;
+ return TRUE;
}
\f
/* Finish up the dynamic sections. */
-static boolean
+static bfd_boolean
elf_cris_finish_dynamic_sections (output_bfd, info)
bfd *output_bfd;
struct bfd_link_info *info;
elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
- return true;
+ return TRUE;
}
\f
/* Return the section that should be marked against GC for a given
relocation. */
static asection *
-cris_elf_gc_mark_hook (abfd, info, rel, h, sym)
- bfd * abfd;
- struct bfd_link_info * info ATTRIBUTE_UNUSED;
- Elf_Internal_Rela * rel;
- struct elf_link_hash_entry * h;
- Elf_Internal_Sym * sym;
+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;
+ Elf_Internal_Sym *sym;
{
if (h != NULL)
{
}
}
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;
}
/* Update the got entry reference counts for the section being removed. */
-static boolean
+static bfd_boolean
cris_elf_gc_sweep_hook (abfd, info, sec, relocs)
- bfd * abfd ATTRIBUTE_UNUSED;
- struct bfd_link_info * info ATTRIBUTE_UNUSED;
- asection * sec ATTRIBUTE_UNUSED;
- const Elf_Internal_Rela * relocs ATTRIBUTE_UNUSED;
+ bfd *abfd ATTRIBUTE_UNUSED;
+ struct bfd_link_info *info ATTRIBUTE_UNUSED;
+ asection *sec ATTRIBUTE_UNUSED;
+ const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED;
{
Elf_Internal_Shdr *symtab_hdr;
struct elf_link_hash_entry **sym_hashes;
dynobj = elf_hash_table (info)->dynobj;
if (dynobj == NULL)
- return true;
+ return TRUE;
sgot = bfd_get_section_by_name (dynobj, ".got");
srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
if (r_symndx >= symtab_hdr->sh_info)
{
h = sym_hashes[r_symndx - symtab_hdr->sh_info];
- if (h->plt.refcount > 0)
+ if (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
+ && h->plt.refcount > 0)
--h->plt.refcount;
}
break;
}
}
- return true;
+ return TRUE;
}
/* Make sure we emit a GOT entry if the symbol was supposed to have a PLT
or elf_cris_size_dynamic_sections if no dynamic sections will be
created (we're only linking static objects). */
-static boolean
+static bfd_boolean
elf_cris_adjust_gotplt_to_got (h, p)
struct elf_cris_link_hash_entry *h;
PTR p;
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;
+ return TRUE;
if (h->root.got.refcount > 0)
{
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;
srelgot->_raw_size += sizeof (Elf32_External_Rela);
}
- return true;
+ return TRUE;
}
/* Try to fold PLT entries with GOT entries. There are two cases when we
version scripts. The differing cases are handled by
elf_cris_hide_symbol. */
-static boolean
+static bfd_boolean
elf_cris_try_fold_plt_to_got (h, p)
struct elf_cris_link_hash_entry *h;
PTR p;
other reference so there's nothing to do. Likewise if there are no
PLT references; GOTPLT references included. */
if (h->root.got.refcount <= 0 || h->root.plt.refcount <= 0)
- return true;
+ return TRUE;
/* GOTPLT relocs are supposed to be included into the PLT refcount. */
BFD_ASSERT (h->gotplt_refcount <= h->root.plt.refcount);
/* 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;
+ return FALSE;
/* Clear the PLT references, so no PLT will be created. */
h->root.plt.offset = (bfd_vma) -1;
}
- return true;
+ return TRUE;
}
/* Our own version of hide_symbol, so that we can adjust a GOTPLT reloc
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;
+ bfd_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
change the definition to something the rest of the link can
understand. */
-static boolean
+static bfd_boolean
elf_cris_adjust_dynamic_symbol (info, h)
struct bfd_link_info *info;
struct elf_link_hash_entry *h;
if (h->type == STT_FUNC
|| (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
{
+ /* If we link a program (not a DSO), we'll get rid of unnecessary
+ PLT entries; we point to the actual symbols -- even for pic
+ relocs, because a program built with -fpic should have the same
+ result as one built without -fpic, specifically considering weak
+ symbols.
+ FIXME: m68k and i386 differ here, for unclear reasons. */
if (! info->shared
- && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
- && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0
- /* We must always create the plt entry if it was referenced by a
- PLT relocation. In this case we already recorded it as a
- dynamic symbol. */
- /* FIXME: m68k and i386 differ here, for unclear reasons. */
- && h->dynindx == -1)
+ && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0)
{
/* 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, or
+ but the symbol was not defined by a dynamic object. In such
+ a case, we don't actually need to build a procedure linkage
+ table, and we can just do an absolute or 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->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
h->plt.offset = (bfd_vma) -1;
-
return
elf_cris_adjust_gotplt_to_got ((struct
elf_cris_link_hash_entry *) h,
PLT entry, get rid of the PLT. */
if (! elf_cris_try_fold_plt_to_got ((struct elf_cris_link_hash_entry *)
h, info))
- return false;
+ return FALSE;
/* GC or folding may have rendered this entry unused. */
if (h->plt.refcount <= 0)
{
h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
h->plt.offset = (bfd_vma) -1;
- return true;
+ return TRUE;
}
/* Make sure this symbol is output as a dynamic symbol. */
if (h->dynindx == -1)
{
if (! bfd_elf32_link_record_dynamic_symbol (info, h))
- return false;
+ return FALSE;
}
s = bfd_get_section_by_name (dynobj, ".plt");
/* If this symbol is not defined in a regular file, and we are
not generating a shared library, then set the symbol to this
- location in the .plt. This is required to make function
- pointers compare as equal between the normal executable and
- the shared library. */
+ location in the .plt. */
if (!info->shared
&& (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
{
/* Make room for this entry. */
s->_raw_size += PLT_ENTRY_SIZE;
- return true;
+ return TRUE;
}
/* No GOT reference for this symbol; prepare for an ordinary PLT. */
BFD_ASSERT (s != NULL);
s->_raw_size += sizeof (Elf32_External_Rela);
- return true;
+ return TRUE;
}
/* Reinitialize the plt offset now that it is not used as a reference
|| 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;
- return true;
+ return TRUE;
}
/* This is a reference to a symbol defined by a dynamic object which
For such cases we need not do anything here; the relocations will
be handled correctly by relocate_section. */
if (info->shared)
- return true;
+ return TRUE;
/* If there are no references to this symbol that do not use the
GOT, we don't need to generate a copy reloc. */
if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0)
- return true;
+ return TRUE;
/* We must allocate the symbol in our .dynbss section, which will
become part of the .bss section of the executable. There will be
if (power_of_two > bfd_get_section_alignment (dynobj, s))
{
if (!bfd_set_section_alignment (dynobj, s, power_of_two))
- return false;
+ return FALSE;
}
/* Define the symbol as being at this point in the section. */
/* Increment the section size to make room for the symbol. */
s->_raw_size += h->size;
- return true;
+ return TRUE;
}
/* Look through the relocs for a section during the first phase. */
-static boolean
+static bfd_boolean
cris_elf_check_relocs (abfd, info, sec, relocs)
bfd *abfd;
struct bfd_link_info *info;
asection *srelgot;
asection *sreloc;
- if (info->relocateable)
- return true;
+ if (info->relocatable)
+ return TRUE;
dynobj = elf_hash_table (info)->dynobj;
symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
/* Create the .got section, so we can assume it's always
present whenever there's a dynobj. */
if (!_bfd_elf_create_got_section (dynobj, info))
- return false;
+ return FALSE;
}
break;
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)
amt *= sizeof (bfd_signed_vma);
local_got_refcounts = ((bfd_signed_vma *) bfd_zalloc (abfd, amt));
if (local_got_refcounts == NULL)
- return false;
+ return FALSE;
local_got_refcounts++;
elf_local_got_refcounts (abfd) = local_got_refcounts;
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)
if (h->dynindx == -1)
{
if (!bfd_elf32_link_record_dynamic_symbol (info, h))
- return false;
+ return FALSE;
}
/* Allocate space in the .got section. */
/* If this is a local symbol, we resolve it directly without
creating a procedure linkage table entry. */
- if (h == NULL)
+ if (h == NULL || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
continue;
h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
/* Make sure a plt entry is created for this symbol if it
turns out to be a function defined by a dynamic object. */
- h->plt.refcount++;
+ if (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
+ h->plt.refcount++;
}
/* If we are creating a shared library and this is not a local
|| r_type == R_CRIS_32_PCREL)
{
/* If the symbol is local, then we can eliminate the reloc. */
- if (h == NULL)
+ if (h == NULL || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
break;
/* If this is with -Bsymbolic and the symbol isn't weak, and
elf_elfheader (abfd)->e_shstrndx,
elf_section_data (sec)->rel_hdr.sh_name));
if (name == NULL)
- return false;
+ return FALSE;
BFD_ASSERT (strncmp (name, ".rela", 5) == 0
&& strcmp (bfd_get_section_name (abfd, sec),
| SEC_LINKER_CREATED
| SEC_READONLY))
|| !bfd_set_section_alignment (dynobj, sreloc, 2))
- return false;
+ return FALSE;
}
if (sec->flags & SEC_READONLY)
info->flags |= DF_TEXTREL;
p = ((struct elf_cris_pcrel_relocs_copied *)
bfd_alloc (dynobj, (bfd_size_type) sizeof *p));
if (p == NULL)
- return false;
+ return FALSE;
p->next = eh->pcrel_relocs_copied;
eh->pcrel_relocs_copied = p;
p->section = sreloc;
Reconstruct it for later use during GC. */
case R_CRIS_GNU_VTINHERIT:
if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
- return false;
+ return FALSE;
break;
/* This relocation describes which C++ vtable entries are actually
used. Record for later use during GC. */
case R_CRIS_GNU_VTENTRY:
if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend))
- return false;
+ return FALSE;
break;
default:
/* Other relocs do not appear here. */
bfd_set_error (bfd_error_bad_value);
- return false;
+ return FALSE;
}
}
- return true;
+ return TRUE;
}
/* Set the sizes of the dynamic sections. */
-static boolean
+static bfd_boolean
elf_cris_size_dynamic_sections (output_bfd, info)
bfd *output_bfd ATTRIBUTE_UNUSED;
struct bfd_link_info *info;
{
bfd *dynobj;
asection *s;
- boolean plt;
- boolean relocs;
+ bfd_boolean plt;
+ bfd_boolean relocs;
dynobj = elf_hash_table (info)->dynobj;
BFD_ASSERT (dynobj != NULL);
/* The check_relocs and adjust_dynamic_symbol entry points have
determined the sizes of the various dynamic sections. Allocate
memory for them. */
- plt = false;
- relocs = false;
+ plt = FALSE;
+ relocs = FALSE;
for (s = dynobj->sections; s != NULL; s = s->next)
{
const char *name;
- boolean strip;
+ bfd_boolean strip;
if ((s->flags & SEC_LINKER_CREATED) == 0)
continue;
of the dynobj section names depend upon the input files. */
name = bfd_get_section_name (dynobj, s);
- strip = false;
+ strip = FALSE;
if (strcmp (name, ".plt") == 0)
{
{
/* Strip this section if we don't need it; see the
comment below. */
- strip = true;
+ strip = TRUE;
}
else
{
/* Remember whether there is a PLT. */
- plt = true;
+ plt = TRUE;
}
}
else if (strncmp (name, ".rela", 5) == 0)
adjust_dynamic_symbol is called, and it is that
function which decides whether anything needs to go
into these sections. */
- strip = true;
+ strip = TRUE;
}
else
{
/* Remember whether there are any reloc sections other
than .rela.plt. */
if (strcmp (name, ".rela.plt") != 0)
- relocs = true;
+ relocs = TRUE;
/* We use the reloc_count field as a counter if we need
to copy relocs into the output file. */
this will make entries have the type R_CRIS_NONE. */
s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
if (s->contents == NULL && s->_raw_size != 0)
- return false;
+ return FALSE;
}
if (elf_hash_table (info)->dynamic_sections_created)
if (!info->shared)
{
if (!add_dynamic_entry (DT_DEBUG, 0))
- return false;
+ return FALSE;
}
if (plt)
|| !add_dynamic_entry (DT_PLTRELSZ, 0)
|| !add_dynamic_entry (DT_PLTREL, DT_RELA)
|| !add_dynamic_entry (DT_JMPREL, 0))
- return false;
+ 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;
+ return FALSE;
}
if ((info->flags & DF_TEXTREL) != 0)
{
if (!add_dynamic_entry (DT_TEXTREL, 0))
- return false;
+ return FALSE;
info->flags |= DF_TEXTREL;
}
}
#undef add_dynamic_entry
- return true;
+ return TRUE;
}
/* This function is called via elf_cris_link_hash_traverse if we are
check_relocs routine, but we won't fill them in in the
relocate_section routine. */
-static boolean
+static bfd_boolean
elf_cris_discard_excess_dso_dynamics (h, inf)
struct elf_cris_link_hash_entry *h;
PTR inf;
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. */
s->section->_raw_size -= s->count * sizeof (Elf32_External_Rela);
}
- return true;
+ 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
+static bfd_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 (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
- 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)
+ (or rather, not 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_DEF_DYNAMIC) == 0)
{
if (h->root.got.refcount > 0
/* The size of this section is only valid and in sync with the
/* 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.elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0)
+ {
+ h->root.dynindx = -1;
+ _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
+ h->root.dynstr_index);
+ }
}
- return true;
+ return TRUE;
}
/* Reject a file depending on presence and expectation of prefixed
underscores on symbols. */
-static boolean
+static bfd_boolean
cris_elf_object_p (abfd)
bfd *abfd;
{
static void
cris_elf_final_write_processing (abfd, linker)
bfd *abfd;
- boolean linker ATTRIBUTE_UNUSED;
+ bfd_boolean linker ATTRIBUTE_UNUSED;
{
if (bfd_get_symbol_leading_char (abfd) == '_')
elf_elfheader (abfd)->e_flags |= EF_CRIS_UNDERSCORE;
/* Display the flags field. */
-static boolean
+static bfd_boolean
cris_elf_print_private_bfd_data (abfd, ptr)
bfd *abfd;
PTR ptr;
fprintf (file, _(" [symbols have a _ prefix]"));
fputc ('\n', file);
- return true;
+ return TRUE;
}
/* Don't mix files with and without a leading underscore. */
-static boolean
+static bfd_boolean
cris_elf_merge_private_bfd_data (ibfd, obfd)
bfd *ibfd;
bfd *obfd;
{
flagword old_flags, new_flags;
- if (_bfd_generic_verify_endian_match (ibfd, obfd) == false)
- return false;
+ if (! _bfd_generic_verify_endian_match (ibfd, obfd))
+ return FALSE;
if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
|| bfd_get_flavour (obfd) != bfd_target_elf_flavour)
- return true;
+ return TRUE;
if (! elf_flags_init (obfd))
{
/* This happens when ld starts out with a 'blank' output file. */
- elf_flags_init (obfd) = true;
+ elf_flags_init (obfd) = TRUE;
/* Set flags according to current bfd_target. */
- cris_elf_final_write_processing (obfd, false);
+ cris_elf_final_write_processing (obfd, FALSE);
}
old_flags = elf_elfheader (obfd)->e_flags;
: _("%s: uses non-prefixed symbols, but writing file with _-prefixed symbols"),
bfd_archive_filename (ibfd));
bfd_set_error (bfd_error_bad_value);
- return false;
+ return FALSE;
}
- return true;
+ return TRUE;
}
take the easy route. */
#define elf_backend_may_use_rel_p 0
#define elf_backend_may_use_rela_p 1
+#define elf_backend_rela_normal 1
#include "elf32-target.h"