public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Alan Modra <amodra@gmail.com>
Cc: Binutils <binutils@sourceware.org>
Subject: Re: [PATCH] PR ld/21402: Skip PIE indirect5 and indirect6 tests on i386
Date: Mon, 24 Apr 2017 20:51:00 -0000	[thread overview]
Message-ID: <CAMe9rOqrTWa5Rt3Co5Gh5JREPdf515D7ZKKz5Lad+5Av3ipSGQ@mail.gmail.com> (raw)
In-Reply-To: <20170424040944.GN24006@bubble.grove.modra.org>

[-- Attachment #1: Type: text/plain, Size: 3390 bytes --]

On Sun, Apr 23, 2017 at 9:09 PM, Alan Modra <amodra@gmail.com> wrote:
> On Fri, Apr 21, 2017 at 11:37:34AM -0700, H.J. Lu wrote:
>> @@ -2863,10 +2867,14 @@ elf_i386_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
>>        int tls_type = elf_i386_hash_entry(h)->tls_type;
>>
>>        /* Make sure this symbol is output as a dynamic symbol.
>> -      Undefined weak syms won't yet be marked as dynamic.  */
>> +      Undefined weak syms won't yet be marked as dynamic.
>> +      PR ld/21402: If this symbol isn't undefined weak symbol,
>> +      don't make it dynamic in PIE.   */
>>        if (h->dynindx == -1
>>         && !h->forced_local
>> -       && !resolved_to_zero)
>> +       && !resolved_to_zero
>> +       && (h->root.type == bfd_link_hash_undefweak
>> +           || !bfd_link_pie (info)))
>>       {
>>         if (! bfd_elf_link_record_dynamic_symbol (info, h))
>>           return FALSE;
>
> This doesn't look correct to me.  Sure, it fixes the particular
> testcase, but why do you make non-pie non-undefweak symbols dynamic
> here?  I believe that only undefweak symbols should be made dynamic
> here, and in all the other places in allocate_dynrelocs.
>
> x86_64 too, but fixing allocate_dynrelocs for x86_64 causes no-plt-1e
> to fail due to lack of a relative GOT dynamic reloc on
>         cmpq    func@GOTPCREL(%rip), %rax
> in no-plt-check1.S.  Seems like x86_64 would need something like your
> change to elf32-i386.c to emit relative GOT dynamic relocs in
> relocate_section.  (For powerpc I decided to only handle plt and copy
> relocs in finish_dynamic_symbol.  GOT dynamic relocs are all handled
> in relocate_section as otherwise there is a lot of duplication and IMO
> less comprehensible code.)
>
>> @@ -3818,6 +3826,7 @@ elf_i386_relocate_section (bfd *output_bfd,
>>        bfd_vma st_size;
>>        asection *resolved_plt;
>>        bfd_boolean resolved_to_zero;
>> +      bfd_boolean relative_reloc;
>>
>>        r_type = ELF32_R_TYPE (rel->r_info);
>>        if (r_type == R_386_GNU_VTINHERIT
>> @@ -4268,6 +4277,7 @@ r_386_got32:
>>         if (htab->elf.sgot == NULL)
>>           abort ();
>>
>> +       relative_reloc = FALSE;
>>         if (h != NULL)
>>           {
>>             bfd_boolean dyn;
>> @@ -4301,6 +4311,17 @@ r_386_got32:
>>                     bfd_put_32 (output_bfd, relocation,
>>                                 htab->elf.sgot->contents + off);
>>                     h->got.offset |= 1;
>> +
>> +                   if (h->dynindx == -1
>> +                       && !h->forced_local
>> +                       && h->root.type != bfd_link_hash_undefweak
>> +                       && bfd_link_pie (info))
>> +                     {
>> +                       /* PR ld/21402: If this symbol isn't dynamic
>> +                          in PIE, generate R_386_RELATIVE here.  */
>> +                       eh->no_finish_dynamic_symbol = 1;
>> +                       relative_reloc = TRUE;
>> +                     }
>>                   }
>>               }
>>             else
>
> This also looks odd.  Surely you need a relative reloc when pic, not
> pie?  It seems to me you need one any time you won't be calling
> finish_dynamic_symbol (which is where x86 sets most dynamic GOT
> relocs) and have a symbol that doesn't resolve to zero.
>

I checked in this patch for i386.  I will look into x86-64.

-- 
H.J.

[-- Attachment #2: 0001-i386-Force-symbol-dynamic-if-it-isn-t-undefined-weak.patch --]
[-- Type: text/x-patch, Size: 3435 bytes --]

From 0dc9a308a1ec9675bf6b33bae9e8b1faa0bad9ed Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Mon, 24 Apr 2017 13:42:33 -0700
Subject: [PATCH] i386: Force symbol dynamic if it isn't undefined weak

Force symbol dynamic if it isn't undefined weak.  Generate R_386_RELATIVE
relocation for R_386_GOT32 relocation against non-dynamic symbol in PIC.

	PR ld/21402
	* elf32-i386.c (elf_i386_allocate_dynrelocs): If a symbol isn't
	undefined weak symbol, don't make it dynamic.
	(elf_i386_relocate_section): If a symbol isn't dynamic in PIC,
	set no_finish_dynamic_symbol and generate R_386_RELATIVE
	relocation for R_386_GOT32.
---
 bfd/ChangeLog    |  9 +++++++++
 bfd/elf32-i386.c | 17 ++++++++---------
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 6b969d6..54e2f0d 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,5 +1,14 @@
 2017-04-24  H.J. Lu  <hongjiu.lu@intel.com>
 
+	PR ld/21402
+	* elf32-i386.c (elf_i386_allocate_dynrelocs): If a symbol isn't
+	undefined weak symbol, don't make it dynamic.
+	(elf_i386_relocate_section): If a symbol isn't dynamic in PIC,
+	set no_finish_dynamic_symbol and generate R_386_RELATIVE
+	relocation for R_386_GOT32.
+
+2017-04-24  H.J. Lu  <hongjiu.lu@intel.com>
+
 	PR ld/21425
 	* elf32-i386.c (ELF_MAXPAGESIZE): Set to 0x1000 for VxWorks.
 
diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index 83f3b11..9a568ce 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -2748,7 +2748,8 @@ elf_i386_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
 	 Undefined weak syms won't yet be marked as dynamic.  */
       if (h->dynindx == -1
 	  && !h->forced_local
-	  && !resolved_to_zero)
+	  && !resolved_to_zero
+	  && h->root.type == bfd_link_hash_undefweak)
 	{
 	  if (! bfd_elf_link_record_dynamic_symbol (info, h))
 	    return FALSE;
@@ -2867,14 +2868,11 @@ elf_i386_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
       int tls_type = elf_i386_hash_entry(h)->tls_type;
 
       /* Make sure this symbol is output as a dynamic symbol.
-	 Undefined weak syms won't yet be marked as dynamic.
-	 PR ld/21402: If this symbol isn't undefined weak symbol,
-	 don't make it dynamic in PIE.   */
+	 Undefined weak syms won't yet be marked as dynamic.  */
       if (h->dynindx == -1
 	  && !h->forced_local
 	  && !resolved_to_zero
-	  && (h->root.type == bfd_link_hash_undefweak
-	      || !bfd_link_pie (info)))
+	  && h->root.type == bfd_link_hash_undefweak)
 	{
 	  if (! bfd_elf_link_record_dynamic_symbol (info, h))
 	    return FALSE;
@@ -3035,7 +3033,8 @@ elf_i386_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
 	     Undefined weak syms won't yet be marked as dynamic.  */
 	  if (h->dynindx == -1
 	      && !h->forced_local
-	      && !resolved_to_zero)
+	      && !resolved_to_zero
+	      && h->root.type == bfd_link_hash_undefweak)
 	    {
 	      if (! bfd_elf_link_record_dynamic_symbol (info, h))
 		return FALSE;
@@ -4315,10 +4314,10 @@ r_386_got32:
 		      if (h->dynindx == -1
 			  && !h->forced_local
 			  && h->root.type != bfd_link_hash_undefweak
-			  && bfd_link_pie (info))
+			  && bfd_link_pic (info))
 			{
 			  /* PR ld/21402: If this symbol isn't dynamic
-			     in PIE, generate R_386_RELATIVE here.  */
+			     in PIC, generate R_386_RELATIVE here.  */
 			  eh->no_finish_dynamic_symbol = 1;
 			  relative_reloc = TRUE;
 			}
-- 
2.9.3


  reply	other threads:[~2017-04-24 20:51 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-20 19:41 H.J. Lu
2017-04-21  1:09 ` Alan Modra
2017-04-21 18:37   ` H.J. Lu
2017-04-24  4:10     ` Alan Modra
2017-04-24 20:51       ` H.J. Lu [this message]
2017-04-24 21:43       ` H.J. Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMe9rOqrTWa5Rt3Co5Gh5JREPdf515D7ZKKz5Lad+5Av3ipSGQ@mail.gmail.com \
    --to=hjl.tools@gmail.com \
    --cc=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).