This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] x86: Remove the unused _GLOBAL_OFFSET_TABLE_


On Thu, Feb 8, 2018 at 1:56 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Mon, Feb 5, 2018 at 8:37 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Sun, Feb 4, 2018 at 8:26 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>> Since _GLOBAL_OFFSET_TABLE_ may be referenced implicitly on x86,
>>> checking ref_regular_nonweak leaves the unused _GLOBAL_OFFSET_TABLE_
>>> in output.  This patch checks explicit GOT references instead.
>>>
>>> bfd/
>>>
>>>         PR ld/22782
>>>         * elf32-i386.c (elf_i386_check_relocs): Set got_referenced if
>>>         GOT is referenced.
>>>         * elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
>>>         * elfxx-x86.c (_bfd_x86_elf_size_dynamic_sections): Likewise.
>>>         Check got_referenced instead of ref_regular_nonweak.  Remove
>>>         the unused _GLOBAL_OFFSET_TABLE_ from symbol table.
>>>         * elfxx-x86.h (elf_x86_link_hash_table): Add got_referenced.
>>>
>>> ld/
>>>
>>>         PR ld/22782
>>>         * testsuite/ld-i386/discarded1.s: Replace mov with div.
>>>         * testsuite/ld-x86-64/discarded1.s: Likewise.
>>>         * testsuite/ld-i386/i386.exp: Run pr22782.
>>>         * testsuite/ld-i386/load1-nacl.d: Updated for removing
>>>         _GLOBAL_OFFSET_TABLE_ from output.
>>>         * testsuite/ld-i386/load1.d: Likewise.
>>>         * testsuite/ld-x86-64/load1a-nacl.d: Likewise.
>>>         * testsuite/ld-x86-64/load1a.d: Likewise.
>>>         * testsuite/ld-x86-64/load1b-nacl.d: Likewise.
>>>         * testsuite/ld-x86-64/load1b.d: Likewise.
>>>         * testsuite/ld-i386/pr22782.d: New file.
>>>         * testsuite/ld-i386/pr22782.s: Likewise.
>>>         * testsuite/ld-x86-64/pr22782.s: Likewise.
>>>         * testsuite/ld-x86-64/pr22782a.d: Likewise.
>>>         * testsuite/ld-x86-64/pr22782b.d: Likewise.
>>>         * testsuite/ld-x86-64/x86-64.exp: Run pr22782a and pr22782b.
>>
>> This is the patch I am checking in.
>>
>
> Solaris requires to keep _GLOBAL_OFFSET_TABLE_ even if it isn't used.
> I checked in this patch to detect Solaris target and keeps it for Solaris.
>
> --
> H.J.

I checked in this patch to set need_global_offset_table with
info->output_bfd->xvec.

-- 
H.J.
--
>From 17ef1256f3a93fbcb399f075a9ebb88ae7ef72a3 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Thu, 8 Feb 2018 16:29:19 -0800
Subject: [PATCH] x86: Set need_global_offset_table with info->output_bfd->xvec

* elf32-i386.c (elf32_i386_copy_solaris_special_section_fields):
Remove prototype.
(i386_elf32_sol2_vec): Declared.
(elf_i386_link_setup_gnu_properties): Set
need_global_offset_table with info->output_bfd->xvec.
* elf64-x86-64.c (elf64_x86_64_copy_solaris_special_section_fields):
Remove prototype.
(x86_64_elf64_sol2_vec): Declared.
(elf_x86_64_link_setup_gnu_properties): Set
need_global_offset_table with info->output_bfd->xvec.
---
 bfd/ChangeLog      | 13 +++++++++++++
 bfd/elf32-i386.c   | 10 +++-------
 bfd/elf64-x86-64.c | 10 +++-------
 3 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 0b27eb0411..c25542d874 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,16 @@
+2018-02-08  H.J. Lu  <hongjiu.lu@intel.com>
+
+ * elf32-i386.c (elf32_i386_copy_solaris_special_section_fields):
+ Remove prototype.
+ (i386_elf32_sol2_vec): Declared.
+ (elf_i386_link_setup_gnu_properties): Set
+ need_global_offset_table with info->output_bfd->xvec.
+ * elf64-x86-64.c (elf64_x86_64_copy_solaris_special_section_fields):
+ Remove prototype.
+ (x86_64_elf64_sol2_vec): Declared.
+ (elf_x86_64_link_setup_gnu_properties): Set
+ need_global_offset_table with info->output_bfd->xvec.
+
 2018-02-08  H.J. Lu  <hongjiu.lu@intel.com>

  * elf32-i386.c (elf32_i386_copy_solaris_special_section_fields):
diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index 4988359b2a..4a6df1949a 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -29,9 +29,6 @@

 #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,
@@ -4341,6 +4338,8 @@ elf_i386_get_synthetic_symtab (bfd *abfd,
      ret);
 }

+extern const bfd_target i386_elf32_sol2_vec;
+
 /* Set up i386 GNU properties.  Return the first relocatable ELF input
    with GNU properties if found.  Otherwise, return NULL.  */

@@ -4348,7 +4347,6 @@ 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)
     {
@@ -4378,10 +4376,8 @@ 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);
+    = info->output_bfd->xvec == &i386_elf32_sol2_vec;

   return _bfd_x86_elf_link_setup_gnu_properties (info, &init_table);
 }
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 7fa04081c8..149543f7bf 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -27,9 +27,6 @@
 #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
@@ -4854,6 +4851,8 @@ elf_x86_64_relocs_compatible (const bfd_target *input,
    && _bfd_elf_relocs_compatible (input, output));
 }

+extern const bfd_target x86_64_elf64_sol2_vec;
+
 /* Set up x86-64 GNU properties.  Return the first relocatable ELF input
    with GNU properties if found.  Otherwise, return NULL.  */

@@ -4861,7 +4860,6 @@ 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
@@ -4918,10 +4916,8 @@ 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);
+    = info->output_bfd->xvec == &x86_64_elf64_sol2_vec;

   return _bfd_x86_elf_link_setup_gnu_properties (info, &init_table);
 }
-- 
2.14.3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]