Clean up elf32-i386-vxworks:

* elf32-i386.c (struct elf_i386_backend_data): New type.
	(get_elf_i386_backend_data): New macro.
	(elf_i386_arch_bed): New variable.
	(elf_backend_arch_data): New macro.
	(struct elf_i386_link_hash_table): Remove plt0_pad_byte and is_vxworks.
	(elf_i386_link_hash_table_create): Don't initialize them.
	(elf_i386_create_dynamic_sections): Find is_vxworks flags in
	elf_i386_backend_data, not elf_i386_link_hash_table.
	(elf_i386_adjust_dynamic_symbol): Likewise.
	(elf_i386_allocate_dynrelocs): Likewise.
	(elf_i386_readonly_dynrelocs): Likewise.
	(elf_i386_size_dynamic_sections): Likewise.
	(elf_i386_relocate_section): Likewise.
	(elf_i386_finish_dynamic_symbol): Likewise.
	(elf_i386_finish_dynamic_sections): Likewise.  Same for plt0_pad_byte.
	(elf_i386_vxworks_link_hash_table_create): Function removed.
	(elf_i386_vxworks_arch_bed): New variable.
	(elf_backend_arch_data): New macro in elf32-i386-vxworks stanza.

	* elf-bfd.h (elf_backend_data): New member arch_backend_data.
	* elfxx-target.h (elf_backend_arch_data): New macro.
	(elfNN_bed): Use it as initializer for the new member.
This commit is contained in:
Roland McGrath
2011-07-28 17:39:20 +00:00
parent 9aec20268e
commit 23209a7853
4 changed files with 97 additions and 57 deletions

View File

@ -1,3 +1,28 @@
2011-07-28 Roland McGrath <mcgrathr@google.com>
* elf32-i386.c (struct elf_i386_backend_data): New type.
(get_elf_i386_backend_data): New macro.
(elf_i386_arch_bed): New variable.
(elf_backend_arch_data): New macro.
(struct elf_i386_link_hash_table): Remove plt0_pad_byte and is_vxworks.
(elf_i386_link_hash_table_create): Don't initialize them.
(elf_i386_create_dynamic_sections): Find is_vxworks flags in
elf_i386_backend_data, not elf_i386_link_hash_table.
(elf_i386_adjust_dynamic_symbol): Likewise.
(elf_i386_allocate_dynrelocs): Likewise.
(elf_i386_readonly_dynrelocs): Likewise.
(elf_i386_size_dynamic_sections): Likewise.
(elf_i386_relocate_section): Likewise.
(elf_i386_finish_dynamic_symbol): Likewise.
(elf_i386_finish_dynamic_sections): Likewise. Same for plt0_pad_byte.
(elf_i386_vxworks_link_hash_table_create): Function removed.
(elf_i386_vxworks_arch_bed): New variable.
(elf_backend_arch_data): New macro in elf32-i386-vxworks stanza.
* elf-bfd.h (elf_backend_data): New member arch_backend_data.
* elfxx-target.h (elf_backend_arch_data): New macro.
(elfNN_bed): Use it as initializer for the new member.
2011-07-28 Mikulas Patocka <mikulas@artax.karlin.mff.cuni.cz> 2011-07-28 Mikulas Patocka <mikulas@artax.karlin.mff.cuni.cz>
* elf64-hppa.c (elf_hppa_final_link_relocate): Fix handling of out * elf64-hppa.c (elf_hppa_final_link_relocate): Fix handling of out

View File

@ -714,6 +714,10 @@ struct elf_backend_data
/* The BFD flags applied to sections created for dynamic linking. */ /* The BFD flags applied to sections created for dynamic linking. */
flagword dynamic_sec_flags; flagword dynamic_sec_flags;
/* Architecture-specific data for this backend.
This is actually a pointer to some type like struct elf_ARCH_data. */
const void *arch_data;
/* A function to translate an ELF RELA relocation to a BFD arelent /* A function to translate an ELF RELA relocation to a BFD arelent
structure. */ structure. */
void (*elf_info_to_howto) void (*elf_info_to_howto)

View File

@ -620,6 +620,30 @@ static const bfd_byte elf_i386_eh_frame_plt[] =
#define PLTRESOLVE_RELOCS 2 #define PLTRESOLVE_RELOCS 2
#define PLT_NON_JUMP_SLOT_RELOCS 2 #define PLT_NON_JUMP_SLOT_RELOCS 2
/* Architecture-specific backend data for i386. */
struct elf_i386_backend_data
{
/* Value used to fill the unused bytes of the first PLT entry. */
bfd_byte plt0_pad_byte;
/* True if the target system is VxWorks. */
int is_vxworks;
};
#define get_elf_i386_backend_data(abfd) \
((const struct elf_i386_backend_data *) \
get_elf_backend_data (abfd)->arch_data)
/* These are the standard parameters. */
static const struct elf_i386_backend_data elf_i386_arch_bed =
{
0, /* plt0_pad_byte */
0, /* is_vxworks */
};
#define elf_backend_arch_data &elf_i386_arch_bed
/* i386 ELF linker hash entry. */ /* i386 ELF linker hash entry. */
struct elf_i386_link_hash_entry struct elf_i386_link_hash_entry
@ -720,14 +744,8 @@ struct elf_i386_link_hash_table
/* The (unloaded but important) .rel.plt.unloaded section on VxWorks. */ /* The (unloaded but important) .rel.plt.unloaded section on VxWorks. */
asection *srelplt2; asection *srelplt2;
/* True if the target system is VxWorks. */
int is_vxworks;
/* The index of the next unused R_386_TLS_DESC slot in .rel.plt. */ /* The index of the next unused R_386_TLS_DESC slot in .rel.plt. */
bfd_vma next_tls_desc_index; bfd_vma next_tls_desc_index;
/* Value used to fill the last word of the first plt entry. */
bfd_byte plt0_pad_byte;
}; };
/* Get the i386 ELF linker hash table from a link_info structure. */ /* Get the i386 ELF linker hash table from a link_info structure. */
@ -866,9 +884,7 @@ elf_i386_link_hash_table_create (bfd *abfd)
ret->next_tls_desc_index = 0; ret->next_tls_desc_index = 0;
ret->sgotplt_jump_table_size = 0; ret->sgotplt_jump_table_size = 0;
ret->sym_cache.abfd = NULL; ret->sym_cache.abfd = NULL;
ret->is_vxworks = 0;
ret->srelplt2 = NULL; ret->srelplt2 = NULL;
ret->plt0_pad_byte = 0;
ret->tls_module_base = NULL; ret->tls_module_base = NULL;
ret->loc_hash_table = htab_try_create (1024, ret->loc_hash_table = htab_try_create (1024,
@ -924,7 +940,7 @@ elf_i386_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
|| (!info->shared && !htab->srelbss)) || (!info->shared && !htab->srelbss))
abort (); abort ();
if (htab->is_vxworks if (get_elf_i386_backend_data (dynobj)->is_vxworks
&& !elf_vxworks_create_dynamic_sections (dynobj, info, && !elf_vxworks_create_dynamic_sections (dynobj, info,
&htab->srelplt2)) &htab->srelplt2))
return FALSE; return FALSE;
@ -2079,7 +2095,8 @@ elf_i386_adjust_dynamic_symbol (struct bfd_link_info *info,
we can keep the dynamic relocs and avoid the copy reloc. This we can keep the dynamic relocs and avoid the copy reloc. This
doesn't work on VxWorks, where we can not have dynamic relocations doesn't work on VxWorks, where we can not have dynamic relocations
(other than copy and jump slot relocations) in an executable. */ (other than copy and jump slot relocations) in an executable. */
if (ELIMINATE_COPY_RELOCS && !htab->is_vxworks) if (ELIMINATE_COPY_RELOCS
&& !get_elf_i386_backend_data (info->output_bfd)->is_vxworks)
{ {
struct elf_i386_link_hash_entry * eh; struct elf_i386_link_hash_entry * eh;
struct elf_dyn_relocs *p; struct elf_dyn_relocs *p;
@ -2205,7 +2222,8 @@ elf_i386_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
htab->elf.srelplt->size += sizeof (Elf32_External_Rel); htab->elf.srelplt->size += sizeof (Elf32_External_Rel);
htab->next_tls_desc_index++; htab->next_tls_desc_index++;
if (htab->is_vxworks && !info->shared) if (get_elf_i386_backend_data (info->output_bfd)->is_vxworks
&& !info->shared)
{ {
/* VxWorks has a second set of relocations for each PLT entry /* VxWorks has a second set of relocations for each PLT entry
in executables. They go in a separate relocation section, in executables. They go in a separate relocation section,
@ -2335,7 +2353,7 @@ elf_i386_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
} }
} }
if (htab->is_vxworks) if (get_elf_i386_backend_data (info->output_bfd)->is_vxworks)
{ {
struct elf_dyn_relocs **pp; struct elf_dyn_relocs **pp;
for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
@ -2469,8 +2487,7 @@ elf_i386_readonly_dynrelocs (struct elf_link_hash_entry *h, void *inf)
/* Set the sizes of the dynamic sections. */ /* Set the sizes of the dynamic sections. */
static bfd_boolean static bfd_boolean
elf_i386_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, elf_i386_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
struct bfd_link_info *info)
{ {
struct elf_i386_link_hash_table *htab; struct elf_i386_link_hash_table *htab;
bfd *dynobj; bfd *dynobj;
@ -2530,7 +2547,7 @@ elf_i386_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
linker script /DISCARD/, so we'll be discarding linker script /DISCARD/, so we'll be discarding
the relocs too. */ the relocs too. */
} }
else if (htab->is_vxworks else if (get_elf_i386_backend_data (output_bfd)->is_vxworks
&& strcmp (p->sec->output_section->name, && strcmp (p->sec->output_section->name,
".tls_vars") == 0) ".tls_vars") == 0)
{ {
@ -2779,7 +2796,7 @@ elf_i386_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
return FALSE; return FALSE;
} }
} }
if (htab->is_vxworks if (get_elf_i386_backend_data (output_bfd)->is_vxworks
&& !elf_vxworks_add_dynamic_entries (output_bfd, info)) && !elf_vxworks_add_dynamic_entries (output_bfd, info))
return FALSE; return FALSE;
} }
@ -2954,7 +2971,8 @@ elf_i386_relocate_section (bfd *output_bfd,
local_tlsdesc_gotents = elf_i386_local_tlsdesc_gotent (input_bfd); local_tlsdesc_gotents = elf_i386_local_tlsdesc_gotent (input_bfd);
/* We have to handle relocations in vxworks .tls_vars sections /* We have to handle relocations in vxworks .tls_vars sections
specially, because the dynamic loader is 'weird'. */ specially, because the dynamic loader is 'weird'. */
is_vxworks_tls = (htab->is_vxworks && info->shared is_vxworks_tls = (get_elf_i386_backend_data (output_bfd)->is_vxworks
&& info->shared
&& !strcmp (input_section->output_section->name, && !strcmp (input_section->output_section->name,
".tls_vars")); ".tls_vars"));
@ -4301,7 +4319,7 @@ elf_i386_finish_dynamic_symbol (bfd *output_bfd,
+ got_offset), + got_offset),
plt->contents + h->plt.offset + 2); plt->contents + h->plt.offset + 2);
if (htab->is_vxworks) if (get_elf_i386_backend_data (output_bfd)->is_vxworks)
{ {
int s, k, reloc_index; int s, k, reloc_index;
@ -4500,7 +4518,8 @@ do_glob_dat:
is relative to the ".got" section. */ is relative to the ".got" section. */
if (sym != NULL if (sym != NULL
&& (strcmp (h->root.root.string, "_DYNAMIC") == 0 && (strcmp (h->root.root.string, "_DYNAMIC") == 0
|| (!htab->is_vxworks && h == htab->elf.hgot))) || (!get_elf_i386_backend_data (output_bfd)->is_vxworks
&& h == htab->elf.hgot)))
sym->st_shndx = SHN_ABS; sym->st_shndx = SHN_ABS;
return TRUE; return TRUE;
@ -4576,7 +4595,7 @@ elf_i386_finish_dynamic_sections (bfd *output_bfd,
switch (dyn.d_tag) switch (dyn.d_tag)
{ {
default: default:
if (htab->is_vxworks if (get_elf_i386_backend_data (output_bfd)->is_vxworks
&& elf_vxworks_finish_dynamic_entry (output_bfd, &dyn)) && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn))
break; break;
continue; continue;
@ -4633,7 +4652,7 @@ elf_i386_finish_dynamic_sections (bfd *output_bfd,
memcpy (htab->elf.splt->contents, elf_i386_pic_plt0_entry, memcpy (htab->elf.splt->contents, elf_i386_pic_plt0_entry,
sizeof (elf_i386_pic_plt0_entry)); sizeof (elf_i386_pic_plt0_entry));
memset (htab->elf.splt->contents + sizeof (elf_i386_pic_plt0_entry), memset (htab->elf.splt->contents + sizeof (elf_i386_pic_plt0_entry),
htab->plt0_pad_byte, get_elf_i386_backend_data (output_bfd)->plt0_pad_byte,
PLT_ENTRY_SIZE - sizeof (elf_i386_pic_plt0_entry)); PLT_ENTRY_SIZE - sizeof (elf_i386_pic_plt0_entry));
} }
else else
@ -4641,7 +4660,7 @@ elf_i386_finish_dynamic_sections (bfd *output_bfd,
memcpy (htab->elf.splt->contents, elf_i386_plt0_entry, memcpy (htab->elf.splt->contents, elf_i386_plt0_entry,
sizeof(elf_i386_plt0_entry)); sizeof(elf_i386_plt0_entry));
memset (htab->elf.splt->contents + sizeof (elf_i386_plt0_entry), memset (htab->elf.splt->contents + sizeof (elf_i386_plt0_entry),
htab->plt0_pad_byte, get_elf_i386_backend_data (output_bfd)->plt0_pad_byte,
PLT_ENTRY_SIZE - sizeof (elf_i386_plt0_entry)); PLT_ENTRY_SIZE - sizeof (elf_i386_plt0_entry));
bfd_put_32 (output_bfd, bfd_put_32 (output_bfd,
(htab->elf.sgotplt->output_section->vma (htab->elf.sgotplt->output_section->vma
@ -4654,7 +4673,7 @@ elf_i386_finish_dynamic_sections (bfd *output_bfd,
+ 8), + 8),
htab->elf.splt->contents + 8); htab->elf.splt->contents + 8);
if (htab->is_vxworks) if (get_elf_i386_backend_data (output_bfd)->is_vxworks)
{ {
Elf_Internal_Rela rel; Elf_Internal_Rela rel;
@ -4684,7 +4703,8 @@ elf_i386_finish_dynamic_sections (bfd *output_bfd,
->this_hdr.sh_entsize = 4; ->this_hdr.sh_entsize = 4;
/* Correct the .rel.plt.unloaded relocations. */ /* Correct the .rel.plt.unloaded relocations. */
if (htab->is_vxworks && !info->shared) if (get_elf_i386_backend_data (output_bfd)->is_vxworks
&& !info->shared)
{ {
int num_plts = (htab->elf.splt->size / PLT_ENTRY_SIZE) - 1; int num_plts = (htab->elf.splt->size / PLT_ENTRY_SIZE) - 1;
unsigned char *p; unsigned char *p;
@ -4938,31 +4958,17 @@ elf_i386_fbsd_post_process_headers (bfd *abfd, struct bfd_link_info *info)
#define TARGET_LITTLE_NAME "elf32-i386-vxworks" #define TARGET_LITTLE_NAME "elf32-i386-vxworks"
#undef ELF_OSABI #undef ELF_OSABI
/* Like elf_i386_link_hash_table_create but with tweaks for VxWorks. */ static const struct elf_i386_backend_data elf_i386_vxworks_arch_bed =
static struct bfd_link_hash_table *
elf_i386_vxworks_link_hash_table_create (bfd *abfd)
{ {
struct bfd_link_hash_table *ret; 0x90, /* plt0_pad_byte */
struct elf_i386_link_hash_table *htab; 1, /* is_vxworks */
};
ret = elf_i386_link_hash_table_create (abfd);
if (ret)
{
htab = (struct elf_i386_link_hash_table *) ret;
htab->is_vxworks = 1;
htab->plt0_pad_byte = 0x90;
}
return ret;
}
#undef elf_backend_arch_data
#define elf_backend_arch_data &elf_i386_vxworks_arch_bed
#undef elf_backend_relocs_compatible #undef elf_backend_relocs_compatible
#undef elf_backend_post_process_headers #undef elf_backend_post_process_headers
#undef bfd_elf32_bfd_link_hash_table_create
#define bfd_elf32_bfd_link_hash_table_create \
elf_i386_vxworks_link_hash_table_create
#undef elf_backend_add_symbol_hook #undef elf_backend_add_symbol_hook
#define elf_backend_add_symbol_hook \ #define elf_backend_add_symbol_hook \
elf_vxworks_add_symbol_hook elf_vxworks_add_symbol_hook

View File

@ -310,6 +310,10 @@
#define elf_info_to_howto_rel 0 #define elf_info_to_howto_rel 0
#endif #endif
#ifndef elf_backend_arch_data
#define elf_backend_arch_data NULL
#endif
#ifndef ELF_TARGET_ID #ifndef ELF_TARGET_ID
#define ELF_TARGET_ID GENERIC_ELF_DATA #define ELF_TARGET_ID GENERIC_ELF_DATA
#endif #endif
@ -668,6 +672,7 @@ static struct elf_backend_data elfNN_bed =
ELF_MINPAGESIZE, /* minpagesize */ ELF_MINPAGESIZE, /* minpagesize */
ELF_COMMONPAGESIZE, /* commonpagesize */ ELF_COMMONPAGESIZE, /* commonpagesize */
ELF_DYNAMIC_SEC_FLAGS, /* dynamic_sec_flags */ ELF_DYNAMIC_SEC_FLAGS, /* dynamic_sec_flags */
elf_backend_arch_data,
elf_info_to_howto, elf_info_to_howto,
elf_info_to_howto_rel, elf_info_to_howto_rel,
elf_backend_sym_is_global, elf_backend_sym_is_global,