]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
x86: Keep the unused _GLOBAL_OFFSET_TABLE_ for Solaris
authorH.J. Lu <hjl.tools@gmail.com>
Thu, 8 Feb 2018 21:52:22 +0000 (13:52 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 8 Feb 2018 21:52:22 +0000 (13:52 -0800)
Solaris requires to keep _GLOBAL_OFFSET_TABLE_ even if it isn't used.
This patch detects Solaris target and keeps _GLOBAL_OFFSET_TABLE_ for
Solaris.

* elf32-i386.c (elf32_i386_copy_solaris_special_section_fields):
New prototype.
(elf_i386_link_setup_gnu_properties): Set need_global_offset_table
for Solaris.
* elf64-x86-64.c (elf64_x86_64_copy_solaris_special_section_fields):
New prototype.
(elf_x86_64_link_setup_gnu_properties): Set
need_global_offset_table for Solaris.
* elfxx-x86.c (_bfd_x86_elf_size_dynamic_sections): Keep the
unused _GLOBAL_OFFSET_TABLE_ for Solaris.
(_bfd_x86_elf_link_setup_gnu_properties): Copy
need_global_offset_table.
* elfxx-x86.h (elf_x86_link_hash_table): Add
need_global_offset_table.
(elf_x86_init_table): Likewise.

bfd/ChangeLog
bfd/elf32-i386.c
bfd/elf64-x86-64.c
bfd/elfxx-x86.c
bfd/elfxx-x86.h

index 0cd219ba64ca2a90d3e24f6cc335afe211d6c6a7..0b27eb041110b155e1aeb5af85b0fab62a73c9e3 100644 (file)
@@ -1,3 +1,21 @@
+2018-02-08  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * elf32-i386.c (elf32_i386_copy_solaris_special_section_fields):
+       New prototype.
+       (elf_i386_link_setup_gnu_properties): Set need_global_offset_table
+       for Solaris.
+       * elf64-x86-64.c (elf64_x86_64_copy_solaris_special_section_fields):
+       New prototype.
+       (elf_x86_64_link_setup_gnu_properties): Set
+       need_global_offset_table for Solaris.
+       * elfxx-x86.c (_bfd_x86_elf_size_dynamic_sections): Keep the
+       unused _GLOBAL_OFFSET_TABLE_ for Solaris.
+       (_bfd_x86_elf_link_setup_gnu_properties): Copy
+       need_global_offset_table.
+       * elfxx-x86.h (elf_x86_link_hash_table): Add
+       need_global_offset_table.
+       (elf_x86_init_table): Likewise.
+
 2018-02-08  Jim Wilson  <jimw@sifive.com>
 
        * elfnn-riscv.c (riscv_elf_relocate_section): Add comment for previous
index 1bdf3d41ecd82b8ab08da56fc1fba643f315097f..4988359b2a3928d5c1fd83422c800fa820ab48d9 100644 (file)
@@ -29,6 +29,9 @@
 
 #include "elf/i386.h"
 
+static bfd_boolean elf32_i386_copy_solaris_special_section_fields
+  (const bfd *, bfd *, const Elf_Internal_Shdr *, Elf_Internal_Shdr *);
+
 static reloc_howto_type elf_howto_table[]=
 {
   HOWTO(R_386_NONE, 0, 3, 0, FALSE, 0, complain_overflow_dont,
@@ -4345,6 +4348,7 @@ static bfd *
 elf_i386_link_setup_gnu_properties (struct bfd_link_info *info)
 {
   struct elf_x86_init_table init_table;
+  const struct elf_backend_data *bed;
 
   switch (get_elf_x86_backend_data (info->output_bfd)->target_os)
     {
@@ -4374,6 +4378,11 @@ elf_i386_link_setup_gnu_properties (struct bfd_link_info *info)
   init_table.r_info = elf32_r_info;
   init_table.r_sym = elf32_r_sym;
 
+  bed = get_elf_backend_data (info->output_bfd);
+  init_table.need_global_offset_table
+    = (bed->elf_backend_copy_special_section_fields
+       == elf32_i386_copy_solaris_special_section_fields);
+
   return _bfd_x86_elf_link_setup_gnu_properties (info, &init_table);
 }
 
index aad9b852961b10da0ef5bab48e3a4c43bbc51ac7..7fa04081c8c371349b146bc852073b8074065808 100644 (file)
@@ -27,6 +27,9 @@
 #include "opcode/i386.h"
 #include "elf/x86-64.h"
 
+static bfd_boolean elf64_x86_64_copy_solaris_special_section_fields
+  (const bfd *, bfd *, const Elf_Internal_Shdr *, Elf_Internal_Shdr *);
+
 #ifdef CORE_HEADER
 #include <stdarg.h>
 #include CORE_HEADER
@@ -4858,6 +4861,7 @@ static bfd *
 elf_x86_64_link_setup_gnu_properties (struct bfd_link_info *info)
 {
   struct elf_x86_init_table init_table;
+  const struct elf_backend_data *bed;
 
   if ((int) R_X86_64_standard >= (int) R_X86_64_converted_reloc_bit
       || (int) R_X86_64_max <= (int) R_X86_64_converted_reloc_bit
@@ -4914,6 +4918,11 @@ elf_x86_64_link_setup_gnu_properties (struct bfd_link_info *info)
       init_table.r_sym = elf32_r_sym;
     }
 
+  bed = get_elf_backend_data (info->output_bfd);
+  init_table.need_global_offset_table
+    = (bed->elf_backend_copy_special_section_fields
+       == elf64_x86_64_copy_solaris_special_section_fields);
+
   return _bfd_x86_elf_link_setup_gnu_properties (info, &init_table);
 }
 
index dbda5425264a4b5be3f95af1e4bcbd23119dcda1..b0eb1c8d0f67f03ea954107bbdbc66a39e0b1f96 100644 (file)
@@ -1098,7 +1098,8 @@ _bfd_x86_elf_size_dynamic_sections (bfd *output_bfd,
              || htab->elf.igotplt->size == 0))
        {
          htab->elf.sgotplt->size = 0;
-         if (htab->elf.hgot != NULL)
+         if (htab->elf.hgot != NULL
+             && !htab->need_global_offset_table)
            {
              /* Remove the unused _GLOBAL_OFFSET_TABLE_ from symbol
                 table. */
@@ -2463,6 +2464,7 @@ error_alignment:
     return pbfd;
 
   htab->plt0_pad_byte = init_table->plt0_pad_byte;
+  htab->need_global_offset_table = init_table->need_global_offset_table;
 
   use_ibt_plt = info->ibtplt || info->ibt;
   if (!use_ibt_plt && pbfd != NULL)
index b515ee61b01a91f5f911cbc3fbb9753ead0d4979..4606bf19b682214a4abc38d5467e445a9b32a4d6 100644 (file)
@@ -481,6 +481,9 @@ struct elf_x86_link_hash_table
   /* TRUE if GOT is referenced.  */
   unsigned int got_referenced : 1;
 
+  /* TRUE if _GLOBAL_OFFSET_TABLE_ is needed.  */
+  unsigned int need_global_offset_table : 1;
+
   bfd_vma (*r_info) (bfd_vma, bfd_vma);
   bfd_vma (*r_sym) (bfd_vma);
   bfd_boolean (*is_reloc_section) (const char *);
@@ -525,6 +528,9 @@ struct elf_x86_init_table
 
   bfd_byte plt0_pad_byte;
 
+  /* TRUE if _GLOBAL_OFFSET_TABLE_ is needed.  */
+  unsigned int need_global_offset_table : 1;
+
   bfd_vma (*r_info) (bfd_vma, bfd_vma);
   bfd_vma (*r_sym) (bfd_vma);
 };