* elf32-arm.c: Add prefix bfd_ to elf32_arm_get_bfd_for_interworking,

elf32_arm_allocate_interworking_sections and
       elf32_arm_process_before_allocation.

        * bfd-in.h: Ammend prototype for
        elf32_arm_process_before_allocation to remove surplus third
        argument.

        * bfd-in2.h: Regenerate.
This commit is contained in:
Catherine Moore
1998-08-18 16:55:29 +00:00
parent 803f5d55cd
commit 2c3c46ad0c
2 changed files with 1307 additions and 426 deletions

View File

@ -1,3 +1,19 @@
start-sanitize-armelf
Tue Aug 18 11:48:12 1998 Catherine Moore <clm@cygnus.com>
* elf32-arm.c: Add prefix bfd_ to elf32_arm_get_bfd_for_interworking,
elf32_arm_allocate_interworking_sections and
elf32_arm_process_before_allocation.
Tue Aug 18 11:46:00 1998 Nick Clifton <nickc@cygnus.com>
* bfd-in.h: Ammend prototype for
elf32_arm_process_before_allocation to remove surplus third
argument.
* bfd-in2.h: Regenerate.
end-sanitize-armelf
Sat Aug 15 20:55:08 1998 Richard Henderson <rth@cygnus.com>
* elf64-alpha.c (elf64_alpha_relax_section): Handle indirect symbols.

View File

@ -25,6 +25,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "elf/arm.h"
typedef unsigned long int insn32;
typedef unsigned short int insn16;
static reloc_howto_type *elf32_arm_reloc_type_lookup
PARAMS ((bfd * abfd, bfd_reloc_code_real_type code));
static void elf32_arm_info_to_howto
@ -37,6 +40,608 @@ static boolean elf32_arm_merge_private_bfd_data
PARAMS ((bfd *, bfd *));
static boolean elf32_arm_print_private_bfd_data
PARAMS ((bfd *, PTR));
static struct bfd_link_hash_table *elf32_arm_link_hash_table_create
PARAMS ((bfd *));
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 *));
static struct elf_link_hash_entry *find_arm_glue
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
PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
/* The linker script knows the section names for placement.
The entry_names are used to do simple name mangling on the stubs.
Given a function name, and its type, the stub can be found. The
name can be changed. The only requirement is the %s be present.
*/
#define INTERWORK_FLAG( abfd ) (elf_elfheader (abfd)->e_flags & EF_INTERWORK)
#define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
#define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
#define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
#define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
/* Get the ARM elf linker hash table from a link_info structure. */
#define elf32_arm_hash_table(info) \
((struct elf32_arm_link_hash_table *) ((info)->hash))
/* ARM ELF linker hash table */
struct elf32_arm_link_hash_table
{
/* 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 ARM-to-Thumb glue. */
long int arm_glue_size;
/* An arbitary input BFD chosen to hold the glue sections. */
bfd *bfd_of_glue_owner;
};
/* Create an ARM elf linker hash table */
static struct bfd_link_hash_table *
elf32_arm_link_hash_table_create (abfd)
bfd *abfd;
{
struct elf32_arm_link_hash_table *ret;
ret = ((struct elf32_arm_link_hash_table *)
bfd_alloc (abfd, sizeof (struct elf32_arm_link_hash_table)));
if (ret == (struct elf32_arm_link_hash_table *) NULL)
return NULL;
if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
_bfd_elf_link_hash_newfunc))
{
bfd_release (abfd, ret);
return NULL;
}
ret->thumb_glue_size = 0;
ret->arm_glue_size = 0;
ret->bfd_of_glue_owner = NULL;
return &ret->root.root;
}
static struct elf_link_hash_entry *
find_thumb_glue (link_info, name, input_bfd)
struct bfd_link_info *link_info;
CONST char *name;
bfd *input_bfd;
{
char *tmp_name;
struct elf_link_hash_entry *hash;
struct elf32_arm_link_hash_table *hash_table;
/* We need a pointer to the armelf specific hash table. */
hash_table = elf32_arm_hash_table (link_info);
tmp_name = ((char *)
bfd_malloc (strlen (name) + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1));
BFD_ASSERT (tmp_name);
sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
hash = elf_link_hash_lookup
(&(hash_table)->root, tmp_name, false, false, true);
if (hash == NULL)
/* xgettext:c-format */
_bfd_error_handler (_ ("%s: unable to find THUMB glue '%s' for `%s'"),
bfd_get_filename (input_bfd), tmp_name, name);
free (tmp_name);
return hash;
}
static struct elf_link_hash_entry *
find_arm_glue (link_info, name, input_bfd)
struct bfd_link_info *link_info;
CONST char *name;
bfd *input_bfd;
{
char *tmp_name;
struct elf_link_hash_entry *myh;
struct elf32_arm_link_hash_table *hash_table;
/* We need a pointer to the elfarm specific hash table. */
hash_table = elf32_arm_hash_table (link_info);
tmp_name = ((char *)
bfd_malloc (strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1));
BFD_ASSERT (tmp_name);
sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
myh = elf_link_hash_lookup
(&(hash_table)->root, tmp_name, false, false, true);
if (myh == NULL)
/* xgettext:c-format */
_bfd_error_handler (_ ("%s: unable to find ARM glue '%s' for `%s'"),
bfd_get_filename (input_bfd), tmp_name, name);
free (tmp_name);
return myh;
}
/*
ARM->Thumb glue:
.arm
__func_from_arm:
ldr r12, __func_addr
bx r12
__func_addr:
.word func @ behave as if you saw a ARM_32 reloc
*/
#define ARM2THUMB_GLUE_SIZE 12
static const insn32 a2t1_ldr_insn = 0xe59fc000;
static const insn32 a2t2_bx_r12_insn = 0xe12fff1c;
static const insn32 a2t3_func_addr_insn = 0x00000001;
/*
Thumb->ARM: Thumb->(non-interworking aware) ARM
.thumb .thumb
.align 2 .align 2
__func_from_thumb: __func_from_thumb:
bx pc push {r6, lr}
nop ldr r6, __func_addr
.arm mov lr, pc
__func_change_to_arm: bx r6
b func .arm
__func_back_to_thumb:
ldmia r13! {r6, lr}
bx lr
__func_addr:
.word func
*/
#define THUMB2ARM_GLUE_SIZE 8
static const insn16 t2a1_bx_pc_insn = 0x4778;
static const insn16 t2a2_noop_insn = 0x46c0;
static const insn32 t2a3_b_insn = 0xea000000;
static const insn16 t2a1_push_insn = 0xb540;
static const insn16 t2a2_ldr_insn = 0x4e03;
static const insn16 t2a3_mov_insn = 0x46fe;
static const insn16 t2a4_bx_insn = 0x4730;
static const insn32 t2a5_pop_insn = 0xe8bd4040;
static const insn32 t2a6_bx_insn = 0xe12fff1e;
boolean
bfd_elf32_arm_allocate_interworking_sections (info)
struct bfd_link_info *info;
{
asection *s;
bfd_byte *foo;
struct elf32_arm_link_hash_table *globals;
globals = elf32_arm_hash_table (info);
BFD_ASSERT (globals != NULL);
if (globals->arm_glue_size != 0)
{
BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
s = bfd_get_section_by_name
(globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME);
BFD_ASSERT (s != NULL);
foo = (bfd_byte *) bfd_alloc
(globals->bfd_of_glue_owner, globals->arm_glue_size);
s->_raw_size = s->_cooked_size = globals->arm_glue_size;
s->contents = foo;
}
if (globals->thumb_glue_size != 0)
{
BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
s = bfd_get_section_by_name
(globals->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
BFD_ASSERT (s != NULL);
foo = (bfd_byte *) bfd_alloc
(globals->bfd_of_glue_owner, globals->thumb_glue_size);
s->_raw_size = s->_cooked_size = globals->thumb_glue_size;
s->contents = foo;
}
return true;
}
static void
record_arm_to_thumb_glue (link_info, h)
struct bfd_link_info *link_info;
struct elf_link_hash_entry *h;
{
const char *name = h->root.root.string;
register asection *s;
char *tmp_name;
struct elf_link_hash_entry *myh;
struct elf32_arm_link_hash_table *globals;
globals = elf32_arm_hash_table (link_info);
BFD_ASSERT (globals != NULL);
BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
s = bfd_get_section_by_name
(globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME);
BFD_ASSERT (s != NULL);
tmp_name = ((char *)
bfd_malloc (strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1));
BFD_ASSERT (tmp_name);
sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
myh = elf_link_hash_lookup
(&(globals)->root, tmp_name, false, false, true);
if (myh != NULL)
{
free (tmp_name);
return; /* we've already seen this guy */
}
/* The only trick here is using hash_table->arm_glue_size as the value. Even
though the section isn't allocated yet, this is where we will be putting
it. */
_bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner, tmp_name,
BSF_GLOBAL,
s, globals->arm_glue_size + 1,
NULL, true, false,
(struct bfd_link_hash_entry **) &myh);
free (tmp_name);
globals->arm_glue_size += ARM2THUMB_GLUE_SIZE;
return;
}
static void
record_thumb_to_arm_glue (link_info, h)
struct bfd_link_info *link_info;
struct elf_link_hash_entry *h;
{
const char *name = h->root.root.string;
register asection *s;
char *tmp_name;
struct elf_link_hash_entry *myh;
struct elf32_arm_link_hash_table *hash_table;
hash_table = elf32_arm_hash_table (link_info);
BFD_ASSERT (hash_table != NULL);
BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL);
s = bfd_get_section_by_name
(hash_table->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
BFD_ASSERT (s != NULL);
tmp_name = (char *) bfd_malloc (strlen (name) + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
BFD_ASSERT (tmp_name);
sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
myh = elf_link_hash_lookup
(&(hash_table)->root, tmp_name, false, false, true);
if (myh != NULL)
{
free (tmp_name);
return; /* we've already seen this guy */
}
_bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner, tmp_name,
BSF_GLOBAL, s, hash_table->thumb_glue_size + 1,
NULL, true, false,
(struct bfd_link_hash_entry **) &myh);
/* If we mark it 'thumb', the disassembler will do a better job. */
myh->other = C_THUMBEXTFUNC;
free (tmp_name);
/* Allocate another symbol to mark where we switch to arm mode. */
#define CHANGE_TO_ARM "__%s_change_to_arm"
#define BACK_FROM_ARM "__%s_back_from_arm"
tmp_name = (char *) bfd_malloc (strlen (name) + strlen (CHANGE_TO_ARM) + 1);
BFD_ASSERT (tmp_name);
sprintf (tmp_name, CHANGE_TO_ARM, name);
myh = NULL;
_bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner, tmp_name,
BSF_LOCAL, s, hash_table->thumb_glue_size + 4,
NULL, true, false,
(struct bfd_link_hash_entry **) &myh);
free (tmp_name);
hash_table->thumb_glue_size += THUMB2ARM_GLUE_SIZE;
return;
}
/* Select a BFD to be used to hold the sections used by the glue code.
This function is called from the linker scripts in ld/emultempl/
{armelf/pe}.em */
boolean
bfd_elf32_arm_get_bfd_for_interworking (abfd, info)
bfd *abfd;
struct bfd_link_info *info;
{
struct elf32_arm_link_hash_table *globals;
flagword flags;
asection *sec;
/* If we are only performing a partial link do not bother
getting a bfd to hold the glue. */
if (info->relocateable)
return true;
globals = elf32_arm_hash_table (info);
BFD_ASSERT (globals != NULL);
if (globals->bfd_of_glue_owner != NULL)
return true;
sec = bfd_get_section_by_name (abfd, ARM2THUMB_GLUE_SECTION_NAME);
if (sec == NULL)
{
flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY;
sec = bfd_make_section (abfd, ARM2THUMB_GLUE_SECTION_NAME);
if (sec == NULL
|| !bfd_set_section_flags (abfd, sec, flags)
|| !bfd_set_section_alignment (abfd, sec, 2))
return false;
}
sec = bfd_get_section_by_name (abfd, THUMB2ARM_GLUE_SECTION_NAME);
if (sec == NULL)
{
flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY;
sec = bfd_make_section (abfd, THUMB2ARM_GLUE_SECTION_NAME);
if (sec == NULL
|| !bfd_set_section_flags (abfd, sec, flags)
|| !bfd_set_section_alignment (abfd, sec, 2))
return false;
}
/* Save the bfd for later use. */
globals->bfd_of_glue_owner = abfd;
return true;
}
boolean
bfd_elf32_arm_process_before_allocation (abfd, link_info)
bfd *abfd;
struct bfd_link_info *link_info;
{
Elf_Internal_Shdr *symtab_hdr;
Elf_Internal_Rela *free_relocs = NULL;
Elf_Internal_Rela *irel, *irelend;
bfd_byte *contents = NULL;
bfd_byte *free_contents = NULL;
Elf32_External_Sym *extsyms = NULL;
Elf32_External_Sym *free_extsyms = NULL;
asection *sec;
struct elf32_arm_link_hash_table *globals;
/* If we are only performing a partial link do not bother
to construct any glue. */
if (link_info->relocateable)
return true;
/* Here we have a bfd that is to be included on the link. We have a hook
to do reloc rummaging, before section sizes are nailed down. */
/* _bfd_coff_get_external_symbols (abfd); */
globals = elf32_arm_hash_table (link_info);
BFD_ASSERT (globals != NULL);
BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
/* Rummage around all the relocs and map the glue vectors. */
sec = abfd->sections;
if (sec == NULL)
return true;
for (; sec != NULL; sec = sec->next)
{
struct internal_reloc *i;
struct internal_reloc *rel;
if (sec->reloc_count == 0)
continue;
symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
/* Load the relocs. */
irel = (_bfd_elf32_link_read_relocs (abfd, sec, (PTR) NULL,
(Elf_Internal_Rela *) NULL, false));
BFD_ASSERT (i != 0);
irelend = irel + sec->reloc_count;
for (; irel < irelend; irel++)
{
long r_type;
unsigned long r_index;
unsigned char code;
struct elf_link_hash_entry *h;
r_type = ELF32_R_TYPE (irel->r_info);
r_index = ELF32_R_SYM (irel->r_info);
/* These are the only relocation types we care about */
if (r_type != R_ARM_PC24
&& r_type != R_ARM_THM_PC22)
continue;
/* Get the section contents if we haven't done so already. */
if (contents == NULL)
{
/* Get cached copy if it exists. */
if (elf_section_data (sec)->this_hdr.contents != NULL)
contents = elf_section_data (sec)->this_hdr.contents;
else
{
/* Go get them off disk. */
contents = (bfd_byte *) bfd_malloc (sec->_raw_size);
if (contents == NULL)
goto error_return;
free_contents = contents;
if (!bfd_get_section_contents (abfd, sec, contents,
(file_ptr) 0, sec->_raw_size))
goto error_return;
}
}
/* Read this BFD's symbols if we haven't done so already. */
if (extsyms == NULL)
{
/* Get cached copy if it exists. */
if (symtab_hdr->contents != NULL)
extsyms = (Elf32_External_Sym *) symtab_hdr->contents;
else
{
/* Go get them off disk. */
extsyms = ((Elf32_External_Sym *)
bfd_malloc (symtab_hdr->sh_size));
if (extsyms == NULL)
goto error_return;
free_extsyms = extsyms;
if (bfd_seek (abfd, symtab_hdr->sh_offset, SEEK_SET) != 0
|| (bfd_read (extsyms, 1, symtab_hdr->sh_size, abfd)
!= symtab_hdr->sh_size))
goto error_return;
}
}
/* If the relocation is not against a symbol it cannot concern us. */
h = NULL;
/* We don't care about local symbols */
if (r_index < symtab_hdr->sh_info)
continue;
/* This is an external symbol */
r_index -= symtab_hdr->sh_info;
h = (struct elf_link_hash_entry *)
elf_sym_hashes (abfd)[r_index];
/* If the relocation is against a static symbol it must be within
the current section and so cannot be a cross ARM/Thumb relocation. */
if (h == NULL)
continue;
switch (r_type)
{
case R_ARM_PC24:
/* This one is a call from arm code. We need to look up
the target of the call. If it is a thumb target, we
insert glue. */
if (h->other == C_THUMBEXTFUNC)
record_arm_to_thumb_glue (link_info, h);
break;
case R_ARM_THM_PC22:
/* This one is a call from thumb code. We used to look
for ARM_THUMB9 and ARM_THUMB12 as well. We need to look
up the target of the call. If it is an arm target, we
insert glue. If the symbol does not exist it will be
given a class of C_EXT and so we will generate a stub
for it. This is not really a problem, since the link
is doomed anyway. */
switch (h->other)
{
case C_EXT:
case C_STAT:
case C_LABEL:
record_thumb_to_arm_glue (link_info, h);
break;
default:
;
}
break;
default:
break;
}
}
}
return true;
error_return:
if (free_relocs != NULL)
free (free_relocs);
if (free_contents != NULL)
free (free_contents);
if (free_extsyms != NULL)
free (free_extsyms);
return false;
}
#define USE_RELA
#define TARGET_UNDERSCORE '_'
@ -348,11 +953,248 @@ elf32_arm_info_to_howto (abfd, bfd_reloc, elf_reloc)
bfd_reloc->howto = &elf32_arm_howto_table[r_type];
}
/* The thumb form of a long branch is a bit finicky, because the offset
encoding is split over two fields, each in it's own instruction. They
can occur in any order. So given a thumb form of long branch, and an
offset, insert the offset into the thumb branch and return finished
instruction.
It takes two thumb instructions to encode the target address. Each has
11 bits to invest. The upper 11 bits are stored in one (identifed by
H-0.. see below), the lower 11 bits are stored in the other (identified
by H-1).
Combine together and shifted left by 1 (it's a half word address) and
there you have it.
Op: 1111 = F,
H-0, upper address-0 = 000
Op: 1111 = F,
H-1, lower address-0 = 800
They can be ordered either way, but the arm tools I've seen always put
the lower one first. It probably doesn't matter. krk@cygnus.com
XXX: Actually the order does matter. The second instruction (H-1)
moves the computed address into the PC, so it must be the second one
in the sequence. The problem, however is that whilst little endian code
stores the instructions in HI then LOW order, big endian code does the
reverse. nickc@cygnus.com */
#define LOW_HI_ORDER 0xF800F000
#define HI_LOW_ORDER 0xF000F800
static insn32
insert_thumb_branch (br_insn, rel_off)
insn32 br_insn;
int rel_off;
{
unsigned int low_bits;
unsigned int high_bits;
BFD_ASSERT ((rel_off & 1) != 1);
rel_off >>= 1; /* half word aligned address */
low_bits = rel_off & 0x000007FF; /* the bottom 11 bits */
high_bits = (rel_off >> 11) & 0x000007FF; /* the top 11 bits */
if ((br_insn & LOW_HI_ORDER) == LOW_HI_ORDER)
br_insn = LOW_HI_ORDER | (low_bits << 16) | high_bits;
else if ((br_insn & HI_LOW_ORDER) == HI_LOW_ORDER)
br_insn = HI_LOW_ORDER | (high_bits << 16) | low_bits;
else
abort (); /* error - not a valid branch instruction form */
/* FIXME: abort is probably not the right call. krk@cygnus.com */
return br_insn;
}
elf32_thumb_to_arm_stub (info, name, input_bfd, output_bfd, input_section,
hit_data, sym_sec, offset, addend, val)
struct bfd_link_info *info;
char *name;
bfd *input_bfd;
bfd *output_bfd;
asection *input_section;
bfd_byte *hit_data;
asection *sym_sec;
int offset;
int addend;
bfd_vma val;
{
/* Thumb code calling an ARM function */
asection *s = 0;
long int my_offset;
unsigned long int tmp;
long int ret_offset;
struct elf_link_hash_entry *myh;
struct elf32_arm_link_hash_table *globals;
myh = find_thumb_glue (info, name, input_bfd);
if (myh == NULL)
return false;
globals = elf32_arm_hash_table (info);
BFD_ASSERT (globals != NULL);
BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
my_offset = myh->root.u.def.value;
s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
THUMB2ARM_GLUE_SECTION_NAME);
BFD_ASSERT (s != NULL);
BFD_ASSERT (s->contents != NULL);
BFD_ASSERT (s->output_section != NULL);
if ((my_offset & 0x01) == 0x01)
{
if (sym_sec->owner != NULL
&& !INTERWORK_FLAG (sym_sec->owner))
{
_bfd_error_handler
(_ ("%s(%s): warning: interworking not enabled."),
bfd_get_filename (sym_sec->owner), name);
_bfd_error_handler
(_ (" first occurrence: %s: thumb call to arm"),
bfd_get_filename (input_bfd));
}
--my_offset;
myh->root.u.def.value = my_offset;
bfd_put_16 (output_bfd, t2a1_bx_pc_insn,
s->contents + my_offset);
bfd_put_16 (output_bfd, t2a2_noop_insn,
s->contents + my_offset + 2);
ret_offset =
((bfd_signed_vma) val) /* Address of destination of the stub */
- ((bfd_signed_vma)
(s->output_offset /* Offset from the start of the current section to the start of the stubs. */
+ my_offset /* Offset of the start of this stub from the start of the stubs. */
+ s->output_section->vma) /* Address of the start of the current section. */
+ 4 /* The branch instruction is 4 bytes into the stub. */
+ 8); /* ARM branches work from the pc of the instruction + 8. */
bfd_put_32 (output_bfd,
t2a3_b_insn | ((ret_offset >> 2) & 0x00FFFFFF),
s->contents + my_offset + 4);
}
BFD_ASSERT (my_offset <= globals->thumb_glue_size);
/* Now go back and fix up the original BL insn to point
to here. */
ret_offset =
s->output_offset
+ my_offset
- (input_section->output_offset
+ offset + addend)
- 4;
tmp = bfd_get_32 (input_bfd, hit_data
- input_section->vma);
bfd_put_32 (output_bfd,
insert_thumb_branch (tmp, ret_offset),
hit_data - input_section->vma);
}
elf32_arm_to_thumb_stub (info, name, input_bfd, output_bfd, input_section,
hit_data, sym_sec, offset, addend, val)
struct bfd_link_info *info;
char *name;
bfd *input_bfd;
bfd *output_bfd;
asection *input_section;
bfd_byte *hit_data;
asection *sym_sec;
int offset;
int addend;
bfd_vma val;
{
/* Arm code calling a Thumb function */
unsigned long int tmp;
long int my_offset;
asection *s;
long int ret_offset;
struct elf_link_hash_entry *myh;
struct elf32_arm_link_hash_table *globals;
myh = find_arm_glue (info, name, input_bfd);
if (myh == NULL)
return false;
globals = elf32_arm_hash_table (info);
BFD_ASSERT (globals != NULL);
BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
my_offset = myh->root.u.def.value;
s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
ARM2THUMB_GLUE_SECTION_NAME);
BFD_ASSERT (s != NULL);
BFD_ASSERT (s->contents != NULL);
BFD_ASSERT (s->output_section != NULL);
if ((my_offset & 0x01) == 0x01)
{
if (sym_sec->owner != NULL
&& !INTERWORK_FLAG (sym_sec->owner))
{
_bfd_error_handler
(_ ("%s(%s): warning: interworking not enabled."),
bfd_get_filename (sym_sec->owner), name);
_bfd_error_handler
(_ (" first occurrence: %s: arm call to thumb"),
bfd_get_filename (input_bfd));
}
--my_offset;
myh->root.u.def.value = my_offset;
bfd_put_32 (output_bfd, a2t1_ldr_insn,
s->contents + my_offset);
bfd_put_32 (output_bfd, a2t2_bx_r12_insn,
s->contents + my_offset + 4);
/* It's a thumb address. Add the low order bit. */
bfd_put_32 (output_bfd, val | a2t3_func_addr_insn,
s->contents + my_offset + 8);
}
BFD_ASSERT (my_offset <= globals->arm_glue_size);
tmp = bfd_get_32 (input_bfd, hit_data);
tmp = tmp & 0xFF000000;
/* Somehow these are both 4 too far, so subtract 8. */
ret_offset = s->output_offset
+ my_offset
+ s->output_section->vma
- (input_section->output_offset
+ input_section->output_section->vma
+ offset + addend)
- 8;
tmp = tmp | ((ret_offset >> 2) & 0x00FFFFFF);
bfd_put_32 (output_bfd, tmp, hit_data
- input_section->vma);
}
/* Perform a relocation as part of a final link. */
static bfd_reloc_status_type
elf32_arm_final_link_relocate (howto, input_bfd, output_bfd,
input_section, contents, offset, value,
addend, info, sym_sec, sym_flags)
addend, info, sym_sec, sym_name, sym_flags)
reloc_howto_type *howto;
bfd *input_bfd;
bfd *output_bfd;
@ -363,6 +1205,7 @@ elf32_arm_final_link_relocate (howto, input_bfd, output_bfd,
bfd_vma addend;
struct bfd_link_info *info;
asection *sym_sec;
char *sym_name;
unsigned char sym_flags;
{
unsigned long r_type = howto->type;
@ -375,9 +1218,22 @@ elf32_arm_final_link_relocate (howto, input_bfd, output_bfd,
return bfd_reloc_ok;
case R_ARM_PC24:
value -= (input_section->output_offset + offset + 8);
value += addend;
value = value >> 2;
/* Arm B/BL instruction */
/* check for arm calling thumb function */
if (sym_flags == C_THUMBSTATFUNC
|| sym_flags == C_THUMBEXTFUNC)
{
elf32_arm_to_thumb_stub (info, sym_name, input_bfd, output_bfd,
input_section, hit_data, sym_sec, offset, addend, value);
return bfd_reloc_ok;
}
value = value + addend;
value -= (input_section->output_section->vma
+ input_section->output_offset + 8);
value -= offset;
value = value >> howto->rightshift;
value &= 0xffffff;
value |= (bfd_get_32 (input_bfd, hit_data) & 0xff000000);
@ -386,11 +1242,9 @@ elf32_arm_final_link_relocate (howto, input_bfd, output_bfd,
case R_ARM_ABS32:
value += addend;
if (sym_flags == C_THUMBSTATFUNC
|| sym_flags == C_THUMBEXTFUNC)
value = value | 1;
value |= 1;
bfd_put_32 (input_bfd, value, hit_data);
return bfd_reloc_ok;
@ -458,6 +1312,15 @@ elf32_arm_final_link_relocate (howto, input_bfd, output_bfd,
bfd_vma add;
bfd_signed_vma signed_add;
if (sym_flags == C_EXT
|| sym_flags == C_STAT
|| sym_flags == C_LABEL)
{
elf32_thumb_to_arm_stub (info, sym_name, input_bfd, output_bfd, input_section,
hit_data, sym_sec, offset, addend, value);
return bfd_reloc_ok;
}
relocation = value + addend;
relocation -= (input_section->output_section->vma + input_section->output_offset);
relocation -= offset;
@ -645,7 +1508,8 @@ elf32_arm_relocate_section (output_bfd, info, input_bfd, input_section,
input_section,
contents, rel->r_offset,
relocation, rel->r_addend,
info, sec, (h ? h->other : sym->st_other));
info, sec, (h ? h->root.root.string : 0),
(h ? h->other : sym->st_other));
if (r != bfd_reloc_ok)
@ -903,7 +1767,7 @@ elf32_arm_print_private_bfd_data (abfd, ptr)
if (elf_elfheader (abfd)->e_flags & EF_APCS_FLOAT)
fprintf (file, _ (" [floats passed in float registers]"));
else
fprintf (file, _(" [floats passed in intgere registers]"));
fprintf (file, _ (" [floats passed in integer registers]"));
if (elf_elfheader (abfd)->e_flags & EF_PIC)
fprintf (file, _ (" [position independent]"));
@ -931,6 +1795,7 @@ elf32_arm_print_private_bfd_data (abfd, ptr)
#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 elf_symbol_leading_char '_'