From: H.J. Lu Date: Sat, 14 Oct 2017 18:32:29 +0000 (-0700) Subject: x86: Add elf_x86_backend_data X-Git-Tag: users/ARM/embedded-binutils-master-2017q4~581 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=851b6fa13707d187e068c8773f21d376391387a9;p=external%2Fbinutils.git x86: Add elf_x86_backend_data Add plt0_pad_byte and target_os fields to elf_x86_link_hash_table. Replace elf_i386_backend_data and elf_x86_64_backend_data with elf_x86_backend_data. * elf32-i386.c (elf_i386_backend_data): Removed. (get_elf_i386_backend_data): Likewise. (elf_i386_arch_bed): Replace elf_i386_backend_data with elf_x86_backend_data. (elf_i386_get_synthetic_symtab): Likewise. (elf_i386_nacl_arch_bed): Likewise. (elf_i386_vxworks_arch_bed): Likewise. (elf_i386_relocate_section): Check target_os instead of is_vxworks. (elf_i386_finish_dynamic_symbol): Likewise. (elf_i386_finish_dynamic_sections): Use htab->plt0_pad_byte. Check target_os instead of is_vxworks. (elf_i386_link_setup_gnu_properties): Remove normal_target and is_vxworks. Initialize plt0_pad_byte. * elf64-x86-64.c (elf_x86_64_backend_data); Removed. (get_elf_x86_64_arch_data): Likewise. (get_elf_x86_64_backend_data): Likewise. (elf_x86_64_arch_bed): Replace elf_x86_64_backend_data with elf_x86_backend_data. (elf_x86_64_get_synthetic_symtab): Likewise. (elf_x86_64_nacl_arch_bed): Likewise. (elf_x86_64_link_setup_gnu_properties): Remove is_vxworks and normal_target. Initialize plt0_pad_byte. * elfxx-x86.c (elf_x86_allocate_dynrelocs): Check target_os instead of is_vxworks. (_bfd_x86_elf_size_dynamic_sections): Likewise. (_bfd_x86_elf_finish_dynamic_sections): Likewise. (_bfd_x86_elf_adjust_dynamic_symbol): Likewise. (_bfd_x86_elf_link_hash_table_create): Initialize target_os. (_bfd_x86_elf_link_setup_gnu_properties): Remove is_vxworks. Update normal_target. Set up plt0_pad_byte. Check target_os instead of is_vxworks. * elfxx-x86.h (elf_x86_target_os): New. (elf_x86_backend_data): Likewise. (get_elf_x86_backend_data): Likewise. (elf_x86_link_hash_table): Remove is_vxworks. Add plt0_pad_byte and target_os. (elf_x86_init_table): Remove normal_target and is_vxworks. Add plt0_pad_byte. --- diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 474572f..5a94bd1 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,5 +1,47 @@ 2017-10-14 H.J. Lu + * elf32-i386.c (elf_i386_backend_data): Removed. + (get_elf_i386_backend_data): Likewise. + (elf_i386_arch_bed): Replace elf_i386_backend_data with + elf_x86_backend_data. + (elf_i386_get_synthetic_symtab): Likewise. + (elf_i386_nacl_arch_bed): Likewise. + (elf_i386_vxworks_arch_bed): Likewise. + (elf_i386_relocate_section): Check target_os instead of + is_vxworks. + (elf_i386_finish_dynamic_symbol): Likewise. + (elf_i386_finish_dynamic_sections): Use htab->plt0_pad_byte. + Check target_os instead of is_vxworks. + (elf_i386_link_setup_gnu_properties): Remove normal_target and + is_vxworks. Initialize plt0_pad_byte. + * elf64-x86-64.c (elf_x86_64_backend_data); Removed. + (get_elf_x86_64_arch_data): Likewise. + (get_elf_x86_64_backend_data): Likewise. + (elf_x86_64_arch_bed): Replace elf_x86_64_backend_data with + elf_x86_backend_data. + (elf_x86_64_get_synthetic_symtab): Likewise. + (elf_x86_64_nacl_arch_bed): Likewise. + (elf_x86_64_link_setup_gnu_properties): Remove is_vxworks and + normal_target. Initialize plt0_pad_byte. + * elfxx-x86.c (elf_x86_allocate_dynrelocs): Check target_os + instead of is_vxworks. + (_bfd_x86_elf_size_dynamic_sections): Likewise. + (_bfd_x86_elf_finish_dynamic_sections): Likewise. + (_bfd_x86_elf_adjust_dynamic_symbol): Likewise. + (_bfd_x86_elf_link_hash_table_create): Initialize target_os. + (_bfd_x86_elf_link_setup_gnu_properties): Remove is_vxworks. + Update normal_target. Set up plt0_pad_byte. Check target_os + instead of is_vxworks. + * elfxx-x86.h (elf_x86_target_os): New. + (elf_x86_backend_data): Likewise. + (get_elf_x86_backend_data): Likewise. + (elf_x86_link_hash_table): Remove is_vxworks. Add plt0_pad_byte + and target_os. + (elf_x86_init_table): Remove normal_target and is_vxworks. Add + plt0_pad_byte. + +2017-10-14 H.J. Lu + * elf32-i386.c (elf_i386_finish_dynamic_sections): Call _bfd_x86_elf_finish_dynamic_sections. * elf64-x86-64.c (elf_x86_64_finish_dynamic_sections): Likewise. diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c index 166ca9d..4b57b65 100644 --- a/bfd/elf32-i386.c +++ b/bfd/elf32-i386.c @@ -824,30 +824,9 @@ static const struct elf_x86_non_lazy_plt_layout elf_i386_non_lazy_ibt_plt = #define PLTRESOLVE_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; - - /* Target system. */ - enum - { - is_normal, - is_vxworks, - is_nacl - } os; -}; - -#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 = +static const struct elf_x86_backend_data elf_i386_arch_bed = { - 0, /* plt0_pad_byte */ is_normal /* os */ }; @@ -2022,7 +2001,7 @@ elf_i386_relocate_section (bfd *output_bfd, local_tlsdesc_gotents = elf_x86_local_tlsdesc_gotent (input_bfd); /* We have to handle relocations in vxworks .tls_vars sections specially, because the dynamic loader is 'weird'. */ - is_vxworks_tls = (htab->is_vxworks + is_vxworks_tls = (htab->target_os == is_vxworks && bfd_link_pic (info) && !strcmp (input_section->output_section->name, ".tls_vars")); @@ -3635,7 +3614,7 @@ elf_i386_finish_dynamic_symbol (bfd *output_bfd, resolved_plt->contents + plt_offset + htab->plt.plt_got_offset); - if (htab->is_vxworks) + if (htab->target_os == is_vxworks) { int s, k, reloc_index; @@ -4031,13 +4010,10 @@ elf_i386_finish_dynamic_sections (bfd *output_bfd, { /* Fill in the special first entry in the procedure linkage table. */ - const struct elf_i386_backend_data *abed - = get_elf_i386_backend_data (output_bfd); - memcpy (htab->elf.splt->contents, htab->plt.plt0_entry, htab->lazy_plt->plt0_entry_size); memset (htab->elf.splt->contents + htab->lazy_plt->plt0_entry_size, - abed->plt0_pad_byte, + htab->plt0_pad_byte, htab->plt.plt_entry_size - htab->lazy_plt->plt0_entry_size); if (!bfd_link_pic (info)) { @@ -4054,7 +4030,7 @@ elf_i386_finish_dynamic_sections (bfd *output_bfd, htab->elf.splt->contents + htab->lazy_plt->plt0_got2_offset); - if (htab->is_vxworks) + if (htab->target_os == is_vxworks) { Elf_Internal_Rela rel; int num_plts = (htab->elf.splt->size @@ -4195,7 +4171,7 @@ elf_i386_get_synthetic_symtab (bfd *abfd, lazy_plt = NULL; non_lazy_ibt_plt = NULL; lazy_ibt_plt = NULL; - switch (get_elf_i386_backend_data (abfd)->os) + switch (get_elf_x86_backend_data (abfd)->target_os) { case is_normal: non_lazy_plt = &elf_i386_non_lazy_plt; @@ -4354,25 +4330,24 @@ elf_i386_link_setup_gnu_properties (struct bfd_link_info *info) { struct elf_x86_init_table init_table; - init_table.normal_target = FALSE; - init_table.is_vxworks = FALSE; - switch (get_elf_i386_backend_data (info->output_bfd)->os) + switch (get_elf_x86_backend_data (info->output_bfd)->target_os) { case is_normal: + init_table.plt0_pad_byte = 0x0; init_table.lazy_plt = &elf_i386_lazy_plt; init_table.non_lazy_plt = &elf_i386_non_lazy_plt; init_table.lazy_ibt_plt = &elf_i386_lazy_ibt_plt; init_table.non_lazy_ibt_plt = &elf_i386_non_lazy_ibt_plt; - init_table.normal_target = TRUE; break; case is_vxworks: + init_table.plt0_pad_byte = 0x90; init_table.lazy_plt = &elf_i386_lazy_plt; init_table.non_lazy_plt = NULL; init_table.lazy_ibt_plt = NULL; init_table.non_lazy_ibt_plt = NULL; - init_table.is_vxworks = TRUE; break; case is_nacl: + init_table.plt0_pad_byte = 0x90; init_table.lazy_plt = &elf_i386_nacl_plt; init_table.non_lazy_plt = NULL; init_table.lazy_ibt_plt = NULL; @@ -4728,7 +4703,7 @@ static const bfd_byte elf_i386_nacl_eh_frame_plt[] = || PLT_FDE_LENGTH != 36 \ || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \ || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12) -# error "Need elf_i386_backend_data parameters for eh_frame_plt offsets!" +# error "Need elf_x86_backend_data parameters for eh_frame_plt offsets!" #endif PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */ 0, 0, 0, 0, /* CIE ID */ @@ -4782,9 +4757,8 @@ static const struct elf_x86_lazy_plt_layout elf_i386_nacl_plt = sizeof (elf_i386_nacl_eh_frame_plt) /* eh_frame_plt_size */ }; -static const struct elf_i386_backend_data elf_i386_nacl_arch_bed = +static const struct elf_x86_backend_data elf_i386_nacl_arch_bed = { - 0x90, /* plt0_pad_byte: nop insn */ is_nacl /* os */ }; @@ -4828,9 +4802,8 @@ elf32_i386_nacl_elf_object_p (bfd *abfd) #undef elf_backend_plt_alignment #define elf_backend_plt_alignment 4 -static const struct elf_i386_backend_data elf_i386_vxworks_arch_bed = +static const struct elf_x86_backend_data elf_i386_vxworks_arch_bed = { - 0x90, /* plt0_pad_byte */ is_vxworks /* os */ }; diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c index 047e78a..6a5159d 100644 --- a/bfd/elf64-x86-64.c +++ b/bfd/elf64-x86-64.c @@ -820,24 +820,6 @@ static const bfd_byte elf_x86_64_eh_frame_non_lazy_plt[] = DW_CFA_nop, DW_CFA_nop, DW_CFA_nop }; -/* Architecture-specific backend data for x86-64. */ - -struct elf_x86_64_backend_data -{ - /* Target system. */ - enum - { - is_normal, - is_nacl - } os; -}; - -#define get_elf_x86_64_arch_data(bed) \ - ((const struct elf_x86_64_backend_data *) (bed)->arch_data) - -#define get_elf_x86_64_backend_data(abfd) \ - get_elf_x86_64_arch_data (get_elf_backend_data (abfd)) - /* These are the standard parameters. */ static const struct elf_x86_lazy_plt_layout elf_x86_64_lazy_plt = { @@ -967,7 +949,7 @@ static const struct elf_x86_non_lazy_plt_layout elf_x32_non_lazy_ibt_plt = sizeof (elf_x86_64_eh_frame_non_lazy_plt) /* eh_frame_plt_size */ }; -static const struct elf_x86_64_backend_data elf_x86_64_arch_bed = +static const struct elf_x86_backend_data elf_x86_64_arch_bed = { is_normal /* os */ }; @@ -4529,7 +4511,7 @@ elf_x86_64_get_synthetic_symtab (bfd *abfd, if (relsize <= 0) return -1; - if (get_elf_x86_64_backend_data (abfd)->os == is_normal) + if (get_elf_x86_backend_data (abfd)->target_os == is_normal) { lazy_plt = &elf_x86_64_lazy_plt; non_lazy_plt = &elf_x86_64_non_lazy_plt; @@ -4877,8 +4859,11 @@ elf_x86_64_link_setup_gnu_properties (struct bfd_link_info *info) != (int) R_X86_64_GNU_VTENTRY)) abort (); - init_table.is_vxworks = FALSE; - if (get_elf_x86_64_backend_data (info->output_bfd)->os == is_normal) + /* This is unused for x86-64. */ + init_table.plt0_pad_byte = 0x90; + + if (get_elf_x86_backend_data (info->output_bfd)->target_os + == is_normal) { if (info->bndplt) { @@ -4901,7 +4886,6 @@ elf_x86_64_link_setup_gnu_properties (struct bfd_link_info *info) init_table.lazy_ibt_plt = &elf_x32_lazy_ibt_plt; init_table.non_lazy_ibt_plt = &elf_x32_non_lazy_ibt_plt; } - init_table.normal_target = TRUE; } else { @@ -4909,7 +4893,6 @@ elf_x86_64_link_setup_gnu_properties (struct bfd_link_info *info) init_table.non_lazy_plt = NULL; init_table.lazy_ibt_plt = NULL; init_table.non_lazy_ibt_plt = NULL; - init_table.normal_target = FALSE; } if (ABI_64_P (info->output_bfd)) @@ -5176,7 +5159,7 @@ static const bfd_byte elf_x86_64_nacl_eh_frame_plt[] = || PLT_FDE_LENGTH != 36 \ || PLT_FDE_START_OFFSET != 4 + PLT_CIE_LENGTH + 8 \ || PLT_FDE_LEN_OFFSET != 4 + PLT_CIE_LENGTH + 12) -# error "Need elf_x86_64_backend_data parameters for eh_frame_plt offsets!" +# error "Need elf_x86_backend_data parameters for eh_frame_plt offsets!" #endif PLT_CIE_LENGTH, 0, 0, 0, /* CIE length */ 0, 0, 0, 0, /* CIE ID */ @@ -5230,7 +5213,7 @@ static const struct elf_x86_lazy_plt_layout elf_x86_64_nacl_plt = sizeof (elf_x86_64_nacl_eh_frame_plt) /* eh_frame_plt_size */ }; -static const struct elf_x86_64_backend_data elf_x86_64_nacl_arch_bed = +static const struct elf_x86_backend_data elf_x86_64_nacl_arch_bed = { is_nacl /* os */ }; diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c index 1aad33f..f4466eb 100644 --- a/bfd/elfxx-x86.c +++ b/bfd/elfxx-x86.c @@ -261,7 +261,7 @@ elf_x86_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) } } - if (htab->is_vxworks && !bfd_link_pic (info)) + if (htab->target_os == is_vxworks && !bfd_link_pic (info)) { /* VxWorks has a second set of relocations for each PLT entry in executables. They go in a separate relocation section, @@ -405,7 +405,7 @@ elf_x86_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) } } - if (htab->is_vxworks) + if (htab->target_os == is_vxworks) { struct elf_dyn_relocs **pp; for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) @@ -799,6 +799,7 @@ _bfd_x86_elf_link_hash_table_create (bfd *abfd) } } ret->target_id = bed->target_id; + ret->target_os = get_elf_x86_backend_data (abfd)->target_os; ret->loc_hash_table = htab_try_create (1024, _bfd_x86_elf_local_htab_hash, @@ -924,7 +925,7 @@ _bfd_x86_elf_size_dynamic_sections (bfd *output_bfd, linker script /DISCARD/, so we'll be discarding the relocs too. */ } - else if (htab->is_vxworks + else if (htab->target_os == is_vxworks && strcmp (p->sec->output_section->name, ".tls_vars") == 0) { @@ -1285,7 +1286,7 @@ _bfd_x86_elf_size_dynamic_sections (bfd *output_bfd, return FALSE; } } - if (htab->is_vxworks + if (htab->target_os == is_vxworks && !elf_vxworks_add_dynamic_entries (output_bfd, info)) return FALSE; } @@ -1377,7 +1378,7 @@ _bfd_x86_elf_finish_dynamic_sections (bfd *output_bfd, switch (dyn.d_tag) { default: - if (htab->is_vxworks + if (htab->target_os == is_vxworks && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn)) break; continue; @@ -1835,7 +1836,7 @@ _bfd_x86_elf_adjust_dynamic_symbol (struct bfd_link_info *info, if (ELIMINATE_COPY_RELOCS && (bed->target_id == X86_64_ELF_DATA || (!eh->gotoff_ref - && !htab->is_vxworks))) + && htab->target_os != is_vxworks))) { for (p = eh->dyn_relocs; p != NULL; p = p->next) { @@ -2440,13 +2441,14 @@ error_alignment: if (htab == NULL) return pbfd; - htab->is_vxworks = init_table->is_vxworks; htab->r_info = init_table->r_info; htab->r_sym = init_table->r_sym; if (bfd_link_relocatable (info)) return pbfd; + htab->plt0_pad_byte = init_table->plt0_pad_byte; + use_ibt_plt = info->ibtplt || info->ibt; if (!use_ibt_plt && pbfd != NULL) { @@ -2498,11 +2500,15 @@ error_alignment: } } + /* Return if there are no normal input files. */ + if (dynobj == NULL) + return pbfd; + /* Even when lazy binding is disabled by "-z now", the PLT0 entry may still be used with LD_AUDIT or LD_PROFILE if PLT entry is used for canonical function address. */ htab->plt.has_plt0 = 1; - normal_target = init_table->normal_target; + normal_target = htab->target_os == is_normal; if (normal_target) { @@ -2565,11 +2571,7 @@ error_alignment: htab->plt.eh_frame_plt = htab->lazy_plt->eh_frame_plt; } - /* Return if there are no normal input files. */ - if (dynobj == NULL) - return pbfd; - - if (htab->is_vxworks + if (htab->target_os == is_vxworks && !elf_vxworks_create_dynamic_sections (dynobj, info, &htab->srelplt2)) { diff --git a/bfd/elfxx-x86.h b/bfd/elfxx-x86.h index a6a8455..8d2a731 100644 --- a/bfd/elfxx-x86.h +++ b/bfd/elfxx-x86.h @@ -403,6 +403,13 @@ struct elf_x86_plt_layout #define elf_x86_hash_entry(ent) \ ((struct elf_x86_link_hash_entry *)(ent)) +enum elf_x86_target_os +{ + is_normal, + is_vxworks, + is_nacl +}; + /* x86 ELF linker hash table. */ struct elf_x86_link_hash_table @@ -458,10 +465,6 @@ struct elf_x86_link_hash_table to read-only sections. */ bfd_boolean readonly_dynrelocs_against_ifunc; - /* TRUE if this is a VxWorks x86 target. This is only used for - i386. */ - bfd_boolean is_vxworks; - /* The (unloaded but important) .rel.plt.unloaded section on VxWorks. This is used for i386 only. */ asection *srelplt2; @@ -476,10 +479,15 @@ struct elf_x86_link_hash_table yet. This is only used for x86-64. */ bfd_vma tlsdesc_plt; + /* Value used to fill the unused bytes of the first PLT entry. This + is only used for i386. */ + bfd_byte plt0_pad_byte; + bfd_vma (*r_info) (bfd_vma, bfd_vma); bfd_vma (*r_sym) (bfd_vma); bfd_boolean (*is_reloc_section) (const char *); enum elf_target_id target_id; + enum elf_x86_target_os target_os; unsigned int sizeof_reloc; unsigned int dt_reloc; unsigned int dt_reloc_sz; @@ -491,6 +499,18 @@ struct elf_x86_link_hash_table const char *tls_get_addr; }; +/* Architecture-specific backend data for x86. */ + +struct elf_x86_backend_data +{ + /* Target system. */ + enum elf_x86_target_os target_os; +}; + +#define get_elf_x86_backend_data(abfd) \ + ((const struct elf_x86_backend_data *) \ + get_elf_backend_data (abfd)->arch_data) + struct elf_x86_init_table { /* The lazy PLT layout. */ @@ -505,11 +525,7 @@ struct elf_x86_init_table /* The non-lazy PLT layout for IBT. */ const struct elf_x86_non_lazy_plt_layout *non_lazy_ibt_plt; - /* TRUE if this is a normal x86 target. */ - bfd_boolean normal_target; - - /* TRUE if this is a VxWorks x86 target. */ - bfd_boolean is_vxworks; + bfd_byte plt0_pad_byte; bfd_vma (*r_info) (bfd_vma, bfd_vma); bfd_vma (*r_sym) (bfd_vma);