This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH] x86: Remove the unused _GLOBAL_OFFSET_TABLE_
On Thu, Feb 8, 2018 at 4:32 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> 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.
We will need is_solaris for TLS. Rainer, can you test this patch for master
branch on Solaris/x86?
Thanks,
--
H.J.
From b80e96441a3d65dfea7629d4593253e62636cd27 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Thu, 8 Feb 2018 18:56:16 -0800
Subject: [PATCH] x86: Add is_solaris to elf_x86_target_os
Add is_solaris to elf_x86_target_os since Solaris is quite different.
* elf32-i386.c (elf_i386_get_synthetic_symtab): Also handle
is_solaris.
(i386_elf32_sol2_vec): Don't declare.
(elf_i386_link_setup_gnu_properties): Also handle is_solaris.
Don't set need_global_offset_table.
(elf_i386_solaris_arch_bed): New.
(elf_backend_arch_data): Set to elf_i386_solaris_arch_bed for
Solaris.
* elf64-x86-64.c (elf_x86_64_get_synthetic_symtab): Check
target_os != is_nacl instead of target_os == is_normal.
(x86_64_elf64_sol2_vec): Don't declare.
(elf_x86_64_link_setup_gnu_properties): Check target_os !=
is_nacl instead of target_os == is_normal. Don't set
need_global_offset_table.
(elf_x86_64_solaris_arch_bed): New.
(elf_backend_arch_data): Set to elf_x86_64_solaris_arch_bed for
Solaris.
* elfxx-x86.c (_bfd_x86_elf_size_dynamic_sections): Keep
_GLOBAL_OFFSET_TABLE_ for Solaris.
(_bfd_x86_elf_link_setup_gnu_properties): Don't copy
need_global_offset_table.
* elfxx-x86.h (elf_x86_target_os): Add is_solaris.
(elf_x86_link_hash_table): Remove need_global_offset_table.
(elf_x86_init_table): Likewise
---
bfd/elf32-i386.c | 18 +++++++++++++-----
bfd/elf64-x86-64.c | 18 ++++++++++--------
bfd/elfxx-x86.c | 6 +++---
bfd/elfxx-x86.h | 7 +------
4 files changed, 27 insertions(+), 22 deletions(-)
diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index 4a6df1949a..e74da3af62 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -4190,6 +4190,7 @@ elf_i386_get_synthetic_symtab (bfd *abfd,
switch (get_elf_x86_backend_data (abfd)->target_os)
{
case is_normal:
+ case is_solaris:
non_lazy_plt = &elf_i386_non_lazy_plt;
lazy_ibt_plt = &elf_i386_lazy_ibt_plt;
non_lazy_ibt_plt = &elf_i386_non_lazy_ibt_plt;
@@ -4338,8 +4339,6 @@ 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. */
@@ -4351,6 +4350,7 @@ elf_i386_link_setup_gnu_properties (struct bfd_link_info *info)
switch (get_elf_x86_backend_data (info->output_bfd)->target_os)
{
case is_normal:
+ case is_solaris:
init_table.plt0_pad_byte = 0x0;
init_table.lazy_plt = &elf_i386_lazy_plt;
init_table.non_lazy_plt = &elf_i386_non_lazy_plt;
@@ -4376,9 +4376,6 @@ 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;
- init_table.need_global_offset_table
- = info->output_bfd->xvec == &i386_elf32_sol2_vec;
-
return _bfd_x86_elf_link_setup_gnu_properties (info, &init_table);
}
@@ -4471,6 +4468,14 @@ elf_i386_fbsd_post_process_headers (bfd *abfd, struct bfd_link_info *info)
#undef TARGET_LITTLE_NAME
#define TARGET_LITTLE_NAME "elf32-i386-sol2"
+static const struct elf_x86_backend_data elf_i386_solaris_arch_bed =
+ {
+ is_solaris /* os */
+ };
+
+#undef elf_backend_arch_data
+#define elf_backend_arch_data &elf_i386_solaris_arch_bed
+
#undef elf_backend_post_process_headers
/* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
@@ -4597,6 +4602,9 @@ elf32_iamcu_elf_object_p (bfd *abfd)
#undef ELF_MACHINE_CODE
#define ELF_MACHINE_CODE EM_IAMCU
+#undef elf_backend_arch_data
+#define elf_backend_arch_data &elf_i386_arch_bed
+
#undef ELF_OSABI
#undef elf32_bed
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 149543f7bf..ad66840eac 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -4519,7 +4519,7 @@ elf_x86_64_get_synthetic_symtab (bfd *abfd,
if (relsize <= 0)
return -1;
- if (get_elf_x86_backend_data (abfd)->target_os == is_normal)
+ if (get_elf_x86_backend_data (abfd)->target_os != is_nacl)
{
lazy_plt = &elf_x86_64_lazy_plt;
non_lazy_plt = &elf_x86_64_non_lazy_plt;
@@ -4851,8 +4851,6 @@ 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. */
@@ -4872,8 +4870,7 @@ elf_x86_64_link_setup_gnu_properties (struct bfd_link_info *info)
/* 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 (get_elf_x86_backend_data (info->output_bfd)->target_os != is_nacl)
{
if (info->bndplt)
{
@@ -4916,9 +4913,6 @@ elf_x86_64_link_setup_gnu_properties (struct bfd_link_info *info)
init_table.r_sym = elf32_r_sym;
}
- init_table.need_global_offset_table
- = info->output_bfd->xvec == &x86_64_elf64_sol2_vec;
-
return _bfd_x86_elf_link_setup_gnu_properties (info, &init_table);
}
@@ -5044,6 +5038,14 @@ elf_x86_64_special_sections[]=
#undef TARGET_LITTLE_NAME
#define TARGET_LITTLE_NAME "elf64-x86-64-sol2"
+static const struct elf_x86_backend_data elf_x86_64_solaris_arch_bed =
+ {
+ is_solaris /* os */
+ };
+
+#undef elf_backend_arch_data
+#define elf_backend_arch_data &elf_x86_64_solaris_arch_bed
+
/* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
objects won't be recognized. */
#undef ELF_OSABI
diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
index b0eb1c8d0f..fc08d1b977 100644
--- a/bfd/elfxx-x86.c
+++ b/bfd/elfxx-x86.c
@@ -1098,8 +1098,9 @@ _bfd_x86_elf_size_dynamic_sections (bfd *output_bfd,
|| htab->elf.igotplt->size == 0))
{
htab->elf.sgotplt->size = 0;
- if (htab->elf.hgot != NULL
- && !htab->need_global_offset_table)
+ /* Solaris requires to keep _GLOBAL_OFFSET_TABLE_ even if it
+ isn't used. */
+ if (htab->elf.hgot != NULL && htab->target_os != is_solaris)
{
/* Remove the unused _GLOBAL_OFFSET_TABLE_ from symbol
table. */
@@ -2464,7 +2465,6 @@ 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)
diff --git a/bfd/elfxx-x86.h b/bfd/elfxx-x86.h
index 4606bf19b6..a7bd49e05b 100644
--- a/bfd/elfxx-x86.h
+++ b/bfd/elfxx-x86.h
@@ -401,6 +401,7 @@ struct elf_x86_plt_layout
enum elf_x86_target_os
{
is_normal,
+ is_solaris,
is_vxworks,
is_nacl
};
@@ -481,9 +482,6 @@ 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 *);
@@ -528,9 +526,6 @@ 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);
};
--
2.14.3