This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [committed, PATCH] Check SEC_ALLOC before allocating dynamic relocation
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Alan Modra <amodra at gmail dot com>
- Cc: Binutils <binutils at sourceware dot org>
- Date: Thu, 16 Jun 2016 05:55:21 -0700
- Subject: Re: [committed, PATCH] Check SEC_ALLOC before allocating dynamic relocation
- Authentication-results: sourceware.org; auth=none
- References: <20160616014422 dot GA17309 at intel dot com> <20160616022359 dot GF25487 at bubble dot grove dot modra dot org>
On Wed, Jun 15, 2016 at 7:23 PM, Alan Modra <amodra@gmail.com> wrote:
> On Wed, Jun 15, 2016 at 06:44:22PM -0700, H.J. Lu wrote:
>> * elf32-i386.c (elf_i386_check_relocs): Check SEC_ALLOC before
>> allocating dynamic relocation.
>> * elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
>
> Why stop at .rela.dyn relocs? Should references in non-alloc sections
> create plt or got entries? Or anything else that check_relocs does?
> See the start of elf64-ppc.c check_relocs.
>
> if (bfd_link_relocatable (info))
> return TRUE;
>
> /* Don't do anything special with non-loaded, non-alloced sections.
> In particular, any relocs in such sections should not affect GOT
> and PLT reference counting (ie. we don't allow them to create GOT
> or PLT entries), there's no possibility or desire to optimize TLS
> relocs, and there's not much point in propagating relocs to shared
> libs that the dynamic linker won't relocate. */
> if ((sec->flags & SEC_ALLOC) == 0)
> return TRUE;
>
You are right. This is what I checked in.
Thanks.
--
H.J.
---
>From 081b1afe5a8cfa02bf3b3cdefb80c266705c17d1 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Thu, 16 Jun 2016 05:52:34 -0700
Subject: [PATCH] Skip relocations in non-loaded, non-alloced sections
Don't do anything special with non-loaded, non-alloced sections.
In particular, any relocs in such sections should not affect GOT
and PLT reference counting (ie. we don't allow them to create GOT
or PLT entries), there's no possibility or desire to optimize TLS
relocs, and there's not much point in propagating relocs to shared
libs that the dynamic linker won't relocate.
* elf32-i386.c (elf_i386_check_relocs): Skip relocations in
non-loaded, non-alloced sections.
* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
---
bfd/ChangeLog | 6 ++++++
bfd/elf32-i386.c | 34 +++++++++++++++++++++-------------
bfd/elf64-x86-64.c | 37 ++++++++++++++++++++++---------------
3 files changed, 49 insertions(+), 28 deletions(-)
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 344e08b..ad9e027 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,9 @@
+2016-06-16 H.J. Lu <hongjiu.lu@intel.com>
+
+ * elf32-i386.c (elf_i386_check_relocs): Skip relocations in
+ non-loaded, non-alloced sections.
+ * elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
+
2016-06-15 H.J. Lu <hongjiu.lu@intel.com>
* elf32-i386.c (elf_i386_check_relocs): Check SEC_ALLOC before
diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index 793fb39..a519778 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -1846,6 +1846,15 @@ elf_i386_check_relocs (bfd *abfd,
if (bfd_link_relocatable (info))
return TRUE;
+ /* Don't do anything special with non-loaded, non-alloced sections.
+ In particular, any relocs in such sections should not affect GOT
+ and PLT reference counting (ie. we don't allow them to create GOT
+ or PLT entries), there's no possibility or desire to optimize TLS
+ relocs, and there's not much point in propagating relocs to shared
+ libs that the dynamic linker won't relocate. */
+ if ((sec->flags & SEC_ALLOC) == 0)
+ return TRUE;
+
BFD_ASSERT (is_i386_elf (abfd));
htab = elf_i386_hash_table (info);
@@ -2202,19 +2211,18 @@ do_size:
may need to keep relocations for symbols satisfied by a
dynamic library if we manage to avoid copy relocs for the
symbol. */
- if ((sec->flags & SEC_ALLOC) != 0
- && ((bfd_link_pic (info)
- && (r_type != R_386_PC32
- || (h != NULL
- && (! (bfd_link_pie (info)
- || SYMBOLIC_BIND (info, h))
- || h->root.type == bfd_link_hash_defweak
- || !h->def_regular))))
- || (ELIMINATE_COPY_RELOCS
- && !bfd_link_pic (info)
- && h != NULL
- && (h->root.type == bfd_link_hash_defweak
- || !h->def_regular))))
+ if ((bfd_link_pic (info)
+ && (r_type != R_386_PC32
+ || (h != NULL
+ && (! (bfd_link_pie (info)
+ || SYMBOLIC_BIND (info, h))
+ || h->root.type == bfd_link_hash_defweak
+ || !h->def_regular))))
+ || (ELIMINATE_COPY_RELOCS
+ && !bfd_link_pic (info)
+ && h != NULL
+ && (h->root.type == bfd_link_hash_defweak
+ || !h->def_regular)))
{
struct elf_dyn_relocs *p;
struct elf_dyn_relocs **head;
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 8c8bcce..9044aab 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -2143,6 +2143,15 @@ elf_x86_64_check_relocs (bfd *abfd, struct
bfd_link_info *info,
if (bfd_link_relocatable (info))
return TRUE;
+ /* Don't do anything special with non-loaded, non-alloced sections.
+ In particular, any relocs in such sections should not affect GOT
+ and PLT reference counting (ie. we don't allow them to create GOT
+ or PLT entries), there's no possibility or desire to optimize TLS
+ relocs, and there's not much point in propagating relocs to shared
+ libs that the dynamic linker won't relocate. */
+ if ((sec->flags & SEC_ALLOC) == 0)
+ return TRUE;
+
BFD_ASSERT (is_x86_64_elf (abfd));
htab = elf_x86_64_hash_table (info);
@@ -2518,8 +2527,7 @@ elf_x86_64_check_relocs (bfd *abfd, struct
bfd_link_info *info,
&& h != NULL
&& !h->def_regular
&& h->def_dynamic
- && (sec->flags & SEC_READONLY) == 0))
- && (sec->flags & SEC_ALLOC) != 0)
+ && (sec->flags & SEC_READONLY) == 0)))
return elf_x86_64_need_pic (abfd, sec, h, symtab_hdr, isym,
&x86_64_elf_howto_table[r_type]);
/* Fall through. */
@@ -2601,19 +2609,18 @@ do_size:
may need to keep relocations for symbols satisfied by a
dynamic library if we manage to avoid copy relocs for the
symbol. */
- if ((sec->flags & SEC_ALLOC) != 0
- && ((bfd_link_pic (info)
- && (! IS_X86_64_PCREL_TYPE (r_type)
- || (h != NULL
- && (! (bfd_link_pie (info)
- || SYMBOLIC_BIND (info, h))
- || h->root.type == bfd_link_hash_defweak
- || !h->def_regular))))
- || (ELIMINATE_COPY_RELOCS
- && !bfd_link_pic (info)
- && h != NULL
- && (h->root.type == bfd_link_hash_defweak
- || !h->def_regular))))
+ if ((bfd_link_pic (info)
+ && (! IS_X86_64_PCREL_TYPE (r_type)
+ || (h != NULL
+ && (! (bfd_link_pie (info)
+ || SYMBOLIC_BIND (info, h))
+ || h->root.type == bfd_link_hash_defweak
+ || !h->def_regular))))
+ || (ELIMINATE_COPY_RELOCS
+ && !bfd_link_pic (info)
+ && h != NULL
+ && (h->root.type == bfd_link_hash_defweak
+ || !h->def_regular)))
{
struct elf_dyn_relocs *p;
struct elf_dyn_relocs **head;
--
2.5.5