/* 32-bit ELF support for ARM
- Copyright 1998, 1999, 2000 Free Software Foundation, Inc.
+ Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
static insn32 insert_thumb_branch
PARAMS ((insn32, int));
static struct elf_link_hash_entry *find_thumb_glue
- PARAMS ((struct bfd_link_info *, CONST char *, bfd *));
+ PARAMS ((struct bfd_link_info *, const char *, bfd *));
static struct elf_link_hash_entry *find_arm_glue
- PARAMS ((struct bfd_link_info *, CONST char *, bfd *));
+ PARAMS ((struct bfd_link_info *, const char *, bfd *));
static void record_arm_to_thumb_glue
PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
static void record_thumb_to_arm_glue
static int elf32_thumb_to_arm_stub
PARAMS ((struct bfd_link_info *, const char *, bfd *, bfd *, asection *,
bfd_byte *, asection *, bfd_vma, bfd_signed_vma, bfd_vma));
+static boolean elf32_arm_relocate_section
+ PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
+ Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
+static asection * elf32_arm_gc_mark_hook
+ PARAMS ((bfd *, struct bfd_link_info *, Elf_Internal_Rela *,
+ struct elf_link_hash_entry *, Elf_Internal_Sym *));
+static boolean elf32_arm_gc_sweep_hook
+ PARAMS ((bfd *, struct bfd_link_info *, asection *,
+ const Elf_Internal_Rela *));
+static boolean elf32_arm_check_relocs
+ PARAMS ((bfd *, struct bfd_link_info *, asection *,
+ const Elf_Internal_Rela *));
+static boolean elf32_arm_find_nearest_line
+ PARAMS ((bfd *, asection *, asymbol **, bfd_vma, const char **,
+ const char **, unsigned int *));
+static boolean elf32_arm_adjust_dynamic_symbol
+ PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
+static boolean elf32_arm_size_dynamic_sections
+ PARAMS ((bfd *, struct bfd_link_info *));
+static boolean elf32_arm_finish_dynamic_symbol
+ PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
+ Elf_Internal_Sym *));
+static boolean elf32_arm_finish_dynamic_sections
+ PARAMS ((bfd *, struct bfd_link_info *));
+static struct bfd_hash_entry * elf32_arm_link_hash_newfunc
+ PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
+#ifdef USE_REL
+static void arm_add_to_rel
+ PARAMS ((bfd *, bfd_byte *, reloc_howto_type *, bfd_signed_vma));
+#endif
+
+boolean bfd_elf32_arm_allocate_interworking_sections
+ PARAMS ((struct bfd_link_info *));
+boolean bfd_elf32_arm_get_bfd_for_interworking
+ PARAMS ((bfd *, struct bfd_link_info *));
+boolean bfd_elf32_arm_process_before_allocation
+ PARAMS ((bfd *, struct bfd_link_info *, int));
+static enum elf_reloc_type_class elf32_arm_reloc_type_class
+ PARAMS ((int));
#define INTERWORK_FLAG(abfd) (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK)
this. It is set up so that any shared library function that is
called before the relocation has been set up calls the dynamic
linker first. */
-static const bfd_byte elf32_arm_plt0_entry [PLT_ENTRY_SIZE] =
-{
- 0x04, 0xe0, 0x2d, 0xe5, /* str lr, [sp, #-4]! */
- 0x10, 0xe0, 0x9f, 0xe5, /* ldr lr, [pc, #16] */
- 0x0e, 0xe0, 0x8f, 0xe0, /* adr lr, pc, lr */
- 0x08, 0xf0, 0xbe, 0xe5 /* ldr pc, [lr, #8]! */
-};
+static const unsigned long elf32_arm_plt0_entry [PLT_ENTRY_SIZE / 4] =
+ {
+ 0xe52de004, /* str lr, [sp, #-4]! */
+ 0xe59fe010, /* ldr lr, [pc, #16] */
+ 0xe08fe00e, /* add lr, pc, lr */
+ 0xe5bef008 /* ldr pc, [lr, #8]! */
+ };
/* Subsequent entries in a procedure linkage table look like
this. */
-static const bfd_byte elf32_arm_plt_entry [PLT_ENTRY_SIZE] =
-{
- 0x04, 0xc0, 0x9f, 0xe5, /* ldr ip, [pc, #4] */
- 0x0c, 0xc0, 0x8f, 0xe0, /* add ip, pc, ip */
- 0x00, 0xf0, 0x9c, 0xe5, /* ldr pc, [ip] */
- 0x00, 0x00, 0x00, 0x00 /* offset to symbol in got */
-};
+static const unsigned long elf32_arm_plt_entry [PLT_ENTRY_SIZE / 4] =
+ {
+ 0xe59fc004, /* ldr ip, [pc, #4] */
+ 0xe08fc00c, /* add ip, pc, ip */
+ 0xe59cf000, /* ldr pc, [ip] */
+ 0x00000000 /* offset to symbol in got */
+ };
/* The ARM linker needs to keep track of the number of relocs that it
decides to copy in check_relocs for each symbol. This is so that
/* This structure keeps track of the number of PC relative relocs we
have copied for a given symbol. */
struct elf32_arm_pcrel_relocs_copied
-{
- /* Next section. */
- struct elf32_arm_pcrel_relocs_copied * next;
- /* A section in dynobj. */
- asection * section;
- /* Number of relocs copied in this section. */
- bfd_size_type count;
-};
+ {
+ /* Next section. */
+ struct elf32_arm_pcrel_relocs_copied * next;
+ /* A section in dynobj. */
+ asection * section;
+ /* Number of relocs copied in this section. */
+ bfd_size_type count;
+ };
/* Arm ELF linker hash entry. */
struct elf32_arm_link_hash_entry
-{
- struct elf_link_hash_entry root;
+ {
+ struct elf_link_hash_entry root;
- /* Number of PC relative relocs copied for this symbol. */
- struct elf32_arm_pcrel_relocs_copied * pcrel_relocs_copied;
-};
+ /* Number of PC relative relocs copied for this symbol. */
+ struct elf32_arm_pcrel_relocs_copied * pcrel_relocs_copied;
+ };
/* Declare this now that the above structures are defined. */
static boolean elf32_arm_discard_copies
/* ARM ELF linker hash table. */
struct elf32_arm_link_hash_table
-{
- /* The main hash table. */
- struct elf_link_hash_table root;
+ {
+ /* The main hash table. */
+ struct elf_link_hash_table root;
- /* The size in bytes of the section containg the Thumb-to-ARM glue. */
- long int thumb_glue_size;
+ /* The size in bytes of the section containg the Thumb-to-ARM glue. */
+ long int thumb_glue_size;
- /* The size in bytes of the section containg the ARM-to-Thumb glue. */
- long int arm_glue_size;
+ /* The size in bytes of the section containg the ARM-to-Thumb glue. */
+ long int arm_glue_size;
- /* An arbitary input BFD chosen to hold the glue sections. */
- bfd * bfd_of_glue_owner;
+ /* An arbitary input BFD chosen to hold the glue sections. */
+ bfd * bfd_of_glue_owner;
- /* A boolean indicating whether knowledge of the ARM's pipeline
- length should be applied by the linker. */
- int no_pipeline_knowledge;
-};
+ /* A boolean indicating whether knowledge of the ARM's pipeline
+ length should be applied by the linker. */
+ int no_pipeline_knowledge;
+ };
/* Create an entry in an ARM ELF linker hash table. */
static struct elf_link_hash_entry *
find_thumb_glue (link_info, name, input_bfd)
struct bfd_link_info *link_info;
- CONST char *name;
+ const char *name;
bfd *input_bfd;
{
char *tmp_name;
static struct elf_link_hash_entry *
find_arm_glue (link_info, name, input_bfd)
struct bfd_link_info *link_info;
- CONST char *name;
+ const char *name;
bfd *input_bfd;
{
char *tmp_name;
bfd_signed_vma signed_addend;
struct elf32_arm_link_hash_table * globals;
+ /* If the start address has been set, then set the EF_ARM_HASENTRY
+ flag. Setting this more than once is redundant, but the cost is
+ not too high, and it keeps the code simple.
+
+ The test is done here, rather than somewhere else, because the
+ start address is only set just before the final link commences.
+
+ Note - if the user deliberately sets a start address of 0, the
+ flag will not be set. */
+ if (bfd_get_start_address (output_bfd) != 0)
+ elf_elfheader (output_bfd)->e_flags |= EF_ARM_HASENTRY;
+
globals = elf32_arm_hash_table (info);
dynobj = elf_hash_table (info)->dynobj;
into the output file to be resolved at run time. */
if (info->shared
&& (r_type != R_ARM_PC24
- || (h != NULL
+ || (h != NULL
&& h->dynindx != -1
&& (! info->symbolic
|| (h->elf_link_hash_flags
case R_ARM_REL32:
value -= (input_section->output_section->vma
- + input_section->output_offset);
+ + input_section->output_offset + rel->r_offset);
value += addend;
break;
}
corresponding bit one in the target address will be set from bit
one of the source address. */
lower_insn &= ~1;
-#endif
+#endif
/* Put the relocated value back in the object file: */
bfd_put_16 (input_bfd, upper_insn, hit_data);
bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
calculation. */
value -= sgot->output_section->vma;
return _bfd_final_link_relocate (howto, input_bfd, input_section,
- contents, rel->r_offset, value,
- (bfd_vma) 0);
+ contents, rel->r_offset, value,
+ (bfd_vma) 0);
case R_ARM_GOTPC:
/* Use global offset table as symbol value. */
value = sgot->output_section->vma;
return _bfd_final_link_relocate (howto, input_bfd, input_section,
- contents, rel->r_offset, value,
- (bfd_vma) 0);
+ contents, rel->r_offset, value,
+ (bfd_vma) 0);
case R_ARM_GOT32:
/* Relocation is to the entry for this symbol in the
}
return _bfd_final_link_relocate (howto, input_bfd, input_section,
- contents, rel->r_offset, value,
- (bfd_vma) 0);
+ contents, rel->r_offset, value,
+ (bfd_vma) 0);
case R_ARM_PLT32:
/* Relocation is to the entry for this symbol in the
without using the procedure linkage table. */
if (h == NULL)
return _bfd_final_link_relocate (howto, input_bfd, input_section,
- contents, rel->r_offset, value,
- (bfd_vma) 0);
+ contents, rel->r_offset, value,
+ (bfd_vma) 0);
if (h->plt.offset == (bfd_vma) -1)
/* We didn't make a PLT entry for this symbol. This
+ splt->output_offset
+ h->plt.offset);
return _bfd_final_link_relocate (howto, input_bfd, input_section,
- contents, rel->r_offset, value,
- (bfd_vma) 0);
+ contents, rel->r_offset, value,
+ (bfd_vma) 0);
case R_ARM_SBREL32:
return bfd_reloc_notsupported;
|| r_type == R_ARM_GNU_VTINHERIT)
continue;
- elf32_arm_info_to_howto (input_bfd, & bfd_reloc, rel);
+ elf32_arm_info_to_howto (input_bfd, & bfd_reloc, (Elf32_Internal_Rel *) rel);
howto = bfd_reloc.howto;
if (info->relocateable)
arm_add_to_rel (input_bfd, contents + rel->r_offset,
howto, sec->output_offset + sym->st_value);
#else
- rel->r_addend += (sec->output_offset + sym->st_value)
- >> howto->rightshift;
+ rel->r_addend += (sec->output_offset + sym->st_value);
#endif
}
}
case R_ARM_ABS32:
if (info->shared
&& (
- (!info->symbolic && h->dynindx != -1)
+ (!info->symbolic && h->dynindx != -1)
|| (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0
)
&& ((input_section->flags & SEC_ALLOC) != 0
if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
_bfd_error_handler (_("\
Warning: %s %s interworking, whereas %s %s"),
- bfd_get_filename (ibfd),
- in_flags & EF_ARM_INTERWORK ? _("supports") : _("does not support"),
- bfd_get_filename (obfd),
- out_flags & EF_ARM_INTERWORK ? _("does not") : _("does"));
+ bfd_get_filename (ibfd),
+ in_flags & EF_ARM_INTERWORK ? _("supports") : _("does not support"),
+ bfd_get_filename (obfd),
+ out_flags & EF_ARM_INTERWORK ? _("does") : _("does not"));
}
return flags_compatible;
if (flags & EF_ARM_MAPSYMSFIRST)
fprintf (file, _(" [mapping symbols precede others]"));
- flags &= ~(EF_ARM_SYMSARESORTED | EF_ARM_DYNSYMSUSESEGIDX
+ flags &= ~(EF_ARM_SYMSARESORTED | EF_ARM_DYNSYMSUSESEGIDX
| EF_ARM_MAPSYMSFIRST);
break;
srelgot = bfd_make_section (dynobj, ".rel.got");
if (srelgot == NULL
|| ! bfd_set_section_flags (dynobj, srelgot,
- (SEC_ALLOC
+ (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
}
else
{
- /* This is a global offset table entry for a local
+ /* This is a global offset table entry for a local
symbol. */
if (local_got_offsets == NULL)
{
sgot->_raw_size += 4;
break;
- case R_ARM_PLT32:
+ case R_ARM_PLT32:
/* This symbol requires a procedure linkage table entry. We
actually build the entry in adjust_dynamic_symbol,
because this might be a case of linking PIC code which is
return false;
BFD_ASSERT (strncmp (name, ".rel", 4) == 0
- && strcmp (bfd_get_section_name (abfd, sec),
+ && strcmp (bfd_get_section_name (abfd, sec),
name + 4) == 0);
sreloc = bfd_get_section_by_name (dynobj, name);
|| ! bfd_set_section_alignment (dynobj, sreloc, 2))
return false;
}
+ if (sec->flags & SEC_READONLY)
+ info->flags |= DF_TEXTREL;
}
sreloc->_raw_size += sizeof (Elf32_External_Rel);
asection * section;
asymbol ** symbols;
bfd_vma offset;
- CONST char ** filename_ptr;
- CONST char ** functionname_ptr;
+ const char ** filename_ptr;
+ const char ** functionname_ptr;
unsigned int * line_ptr;
{
boolean found;
static boolean
elf32_arm_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);
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 .rel.plt. */
if (strcmp (name, ".rel.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 .rel.plt section
- really apply to the .got section, 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 + 4);
-
- if (target != NULL
- && (target->flags & SEC_READONLY) != 0
- && (target->flags & SEC_ALLOC) != 0)
- reltext = true;
- }
+ relocs = true;
/* We use the reloc_count field as a counter if we need
to copy relocs into the output file. */
return false;
}
- if (reltext)
+ if ((info->flags & DF_TEXTREL) != 0)
{
if (! bfd_elf32_add_dynamic_entry (info, DT_TEXTREL, 0))
return false;
got_offset = (plt_index + 3) * 4;
/* Fill in the entry in the procedure linkage table. */
- memcpy (splt->contents + h->plt.offset,
- elf32_arm_plt_entry,
- PLT_ENTRY_SIZE);
+ bfd_put_32 (output_bfd, elf32_arm_plt_entry[0],
+ splt->contents + h->plt.offset + 0);
+ bfd_put_32 (output_bfd, elf32_arm_plt_entry[1],
+ splt->contents + h->plt.offset + 4);
+ bfd_put_32 (output_bfd, elf32_arm_plt_entry[2],
+ splt->contents + h->plt.offset + 8);
bfd_put_32 (output_bfd,
(sgot->output_section->vma
+ sgot->output_offset
/* Mark the symbol as undefined, rather than as defined in
the .plt section. Leave the value alone. */
sym->st_shndx = SHN_UNDEF;
+ /* If the symbol is weak, we do need to clear the value.
+ Otherwise, the PLT entry would provide a definition for
+ the symbol even if the symbol wasn't defined anywhere,
+ and so the symbol would never be NULL. */
+ if ((h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR_NONWEAK)
+ == 0)
+ sym->st_value = 0;
}
}
/* Fill in the first entry in the procedure linkage table. */
if (splt->_raw_size > 0)
- memcpy (splt->contents, elf32_arm_plt0_entry, PLT_ENTRY_SIZE);
+ {
+ bfd_put_32 (output_bfd, elf32_arm_plt0_entry[0], splt->contents + 0);
+ bfd_put_32 (output_bfd, elf32_arm_plt0_entry[1], splt->contents + 4);
+ bfd_put_32 (output_bfd, elf32_arm_plt0_entry[2], splt->contents + 8);
+ bfd_put_32 (output_bfd, elf32_arm_plt0_entry[3], splt->contents + 12);
+ }
/* UnixWare sets the entsize of .plt to 4, although that doesn't
really seem like the right value. */
i_ehdrp->e_ident[EI_ABIVERSION] = ARM_ELF_ABI_VERSION;
}
+static enum elf_reloc_type_class
+elf32_arm_reloc_type_class (type)
+ int type;
+{
+ switch (type)
+ {
+ case R_ARM_RELATIVE:
+ return reloc_class_relative;
+ case R_ARM_JUMP_SLOT:
+ return reloc_class_plt;
+ case R_ARM_COPY:
+ return reloc_class_copy;
+ default:
+ return reloc_class_normal;
+ }
+}
+
+
#define ELF_ARCH bfd_arch_arm
#define ELF_MACHINE_CODE EM_ARM
#define ELF_MAXPAGESIZE 0x8000
-#define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
-#define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
+#define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
+#define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
#define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
#define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
#define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
-#define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
+#define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
#define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
#define elf_backend_get_symbol_type elf32_arm_get_symbol_type
#define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
#define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
#define elf_backend_check_relocs elf32_arm_check_relocs
-#define elf_backend_relocate_section elf32_arm_relocate_section
+#define elf_backend_relocate_section elf32_arm_relocate_section
#define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
#define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
#define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
#define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
#define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
#define elf_backend_post_process_headers elf32_arm_post_process_headers
+#define elf_backend_reloc_type_class elf32_arm_reloc_type_class
#define elf_backend_can_gc_sections 1
#define elf_backend_plt_readonly 1