From 9ff114ca5d2c2753f1ac110f8586d0040c27a7a3 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Sat, 2 Sep 2017 07:16:33 -0700 Subject: [PATCH] x86: Add elf_x86_compute_jump_table_size Share elf_x86_compute_jump_table_size in elf32-i386.c and elf64-x86-64.c. * elf32-i386.c (elf_i386_compute_jump_table_size): Removed. (elf_i386_allocate_dynrelocs): Replace elf_i386_compute_jump_table_size with elf_x86_compute_jump_table_size. (elf_i386_size_dynamic_sections): Likewise. * elf64-x86-64.c (elf_x86_64_compute_jump_table_size): Removed. (elf_x86_64_allocate_dynrelocs): Replace elf_x86_64_compute_jump_table_size with elf_x86_compute_jump_table_size. (elf_x86_64_size_dynamic_sections): Likewise. * elfxx-x86.c (_bfd_x86_elf_link_hash_table_create): Initialize got_entry_size. * elfxx-x86.h (elf_x86_link_hash_table): Add got_entry_size. (elf_x86_compute_jump_table_size): New. --- bfd/ChangeLog | 17 +++++++++++++++++ bfd/elf32-i386.c | 7 ++----- bfd/elf64-x86-64.c | 9 +++------ bfd/elfxx-x86.c | 3 +++ bfd/elfxx-x86.h | 4 ++++ 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 764d3e7766d..efee0544f60 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,20 @@ +2017-09-02 H.J. Lu + + * elf32-i386.c (elf_i386_compute_jump_table_size): Removed. + (elf_i386_allocate_dynrelocs): Replace + elf_i386_compute_jump_table_size with + elf_x86_compute_jump_table_size. + (elf_i386_size_dynamic_sections): Likewise. + * elf64-x86-64.c (elf_x86_64_compute_jump_table_size): Removed. + (elf_x86_64_allocate_dynrelocs): Replace + elf_x86_64_compute_jump_table_size with + elf_x86_compute_jump_table_size. + (elf_x86_64_size_dynamic_sections): Likewise. + * elfxx-x86.c (_bfd_x86_elf_link_hash_table_create): Initialize + got_entry_size. + * elfxx-x86.h (elf_x86_link_hash_table): Add got_entry_size. + (elf_x86_compute_jump_table_size): New. + 2017-09-02 H.J. Lu * elfxx-x86.c (_bfd_x86_elf_link_hash_table_create): Initialize diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c index 3d8a4ae8975..573a8edcc91 100644 --- a/bfd/elf32-i386.c +++ b/bfd/elf32-i386.c @@ -858,9 +858,6 @@ static const struct elf_i386_backend_data elf_i386_arch_bed = && elf_tdata (bfd) != NULL \ && elf_object_id (bfd) == I386_ELF_DATA) -#define elf_i386_compute_jump_table_size(htab) \ - ((htab)->elf.srelplt->reloc_count * 4) - /* Return TRUE if the TLS access code sequence support transition from R_TYPE. */ @@ -2206,7 +2203,7 @@ elf_i386_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) if (GOT_TLS_GDESC_P (tls_type)) { eh->tlsdesc_got = htab->elf.sgotplt->size - - elf_i386_compute_jump_table_size (htab); + - elf_x86_compute_jump_table_size (htab); htab->elf.sgotplt->size += 8; h->got.offset = (bfd_vma) -2; } @@ -2637,7 +2634,7 @@ elf_i386_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info) if (GOT_TLS_GDESC_P (*local_tls_type)) { *local_tlsdesc_gotent = htab->elf.sgotplt->size - - elf_i386_compute_jump_table_size (htab); + - elf_x86_compute_jump_table_size (htab); htab->elf.sgotplt->size += 8; *local_got = (bfd_vma) -2; } diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c index 300e99ae4f0..dcebd68c5a6 100644 --- a/bfd/elf64-x86-64.c +++ b/bfd/elf64-x86-64.c @@ -973,9 +973,6 @@ static const struct elf_x86_64_backend_data elf_x86_64_arch_bed = && elf_tdata (bfd) != NULL \ && elf_object_id (bfd) == X86_64_ELF_DATA) -#define elf_x86_64_compute_jump_table_size(htab) \ - ((htab)->elf.srelplt->reloc_count * GOT_ENTRY_SIZE) - static bfd_boolean elf64_x86_64_elf_object_p (bfd *abfd) { @@ -2632,7 +2629,7 @@ elf_x86_64_allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf) if (GOT_TLS_GDESC_P (tls_type)) { eh->tlsdesc_got = htab->elf.sgotplt->size - - elf_x86_64_compute_jump_table_size (htab); + - elf_x86_compute_jump_table_size (htab); htab->elf.sgotplt->size += 2 * GOT_ENTRY_SIZE; h->got.offset = (bfd_vma) -2; } @@ -3035,7 +3032,7 @@ elf_x86_64_size_dynamic_sections (bfd *output_bfd, if (GOT_TLS_GDESC_P (*local_tls_type)) { *local_tlsdesc_gotent = htab->elf.sgotplt->size - - elf_x86_64_compute_jump_table_size (htab); + - elf_x86_compute_jump_table_size (htab); htab->elf.sgotplt->size += 2 * GOT_ENTRY_SIZE; *local_got = (bfd_vma) -2; } @@ -3099,7 +3096,7 @@ elf_x86_64_size_dynamic_sections (bfd *output_bfd, if (htab->elf.srelplt) { htab->sgotplt_jump_table_size - = elf_x86_64_compute_jump_table_size (htab); + = elf_x86_compute_jump_table_size (htab); htab->next_irelative_index = htab->elf.srelplt->reloc_count - 1; } else if (htab->elf.irelplt) diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c index fe5d211af2d..6b7c119393e 100644 --- a/bfd/elfxx-x86.c +++ b/bfd/elfxx-x86.c @@ -278,6 +278,7 @@ _bfd_x86_elf_link_hash_table_create (bfd *abfd) ret->r_info = elf64_r_info; ret->r_sym = elf64_r_sym; ret->sizeof_reloc = sizeof (Elf64_External_Rela); + ret->got_entry_size = 8; ret->pointer_r_type = R_X86_64_64; ret->dynamic_interpreter = ELF64_DYNAMIC_INTERPRETER; ret->dynamic_interpreter_size = sizeof ELF64_DYNAMIC_INTERPRETER; @@ -291,6 +292,7 @@ _bfd_x86_elf_link_hash_table_create (bfd *abfd) if (bed->target_id == X86_64_ELF_DATA) { ret->sizeof_reloc = sizeof (Elf32_External_Rela); + ret->got_entry_size = 8; ret->pointer_r_type = R_X86_64_32; ret->dynamic_interpreter = ELFX32_DYNAMIC_INTERPRETER; ret->dynamic_interpreter_size @@ -300,6 +302,7 @@ _bfd_x86_elf_link_hash_table_create (bfd *abfd) else { ret->sizeof_reloc = sizeof (Elf32_External_Rel); + ret->got_entry_size = 4; ret->pointer_r_type = R_386_32; ret->dynamic_interpreter = ELF32_DYNAMIC_INTERPRETER; ret->dynamic_interpreter_size diff --git a/bfd/elfxx-x86.h b/bfd/elfxx-x86.h index 0c80ca45bea..a95b5c60a2f 100644 --- a/bfd/elfxx-x86.h +++ b/bfd/elfxx-x86.h @@ -314,6 +314,7 @@ struct elf_x86_link_hash_table bfd_vma (*r_info) (bfd_vma, bfd_vma); bfd_vma (*r_sym) (bfd_vma); unsigned int sizeof_reloc; + unsigned int got_entry_size; unsigned int pointer_r_type; int dynamic_interpreter_size; const char *dynamic_interpreter; @@ -382,6 +383,9 @@ struct elf_x86_plt #define elf_x86_local_tlsdesc_gotent(abfd) \ (elf_x86_tdata (abfd)->local_tlsdesc_gotent) +#define elf_x86_compute_jump_table_size(htab) \ + ((htab)->elf.srelplt->reloc_count * (htab)->got_entry_size) + extern bfd_boolean _bfd_x86_elf_mkobject (bfd *); -- 2.30.2