public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Eric Botcazou <ebotcazou@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r10-10158] Fix PR c++/64697 at -O1 or above
Date: Fri,  1 Oct 2021 09:02:20 +0000 (GMT)	[thread overview]
Message-ID: <20211001090220.C4E0B3858422@sourceware.org> (raw)

https://gcc.gnu.org/g:48e24ff39b16c072cd58bdad1a5668794453af5f

commit r10-10158-g48e24ff39b16c072cd58bdad1a5668794453af5f
Author: Eric Botcazou <ebotcazou@adacore.com>
Date:   Fri Oct 1 10:49:34 2021 +0200

    Fix PR c++/64697 at -O1 or above
    
    The BFD fix eliminates the link failure and working code is generated at
    -O0, but _not_ when optimization is enabled because the optimizer changes:
    
            movq    .refptr._ZTH1s(%rip), %rax
            testq   %rax, %rax
            je      .L2
            call    _ZTH1s
    
    into:
    
            leaq    _ZTH1s(%rip), %rax
            testq   %rax, %rax
            je      .L2
            call    _ZTH1s
    
    and the leaq now also gets the relocation overflow.  So the fix is to
    teach legitimate_pic_address_disp_p to reject the transformation when
    the symbol is an external weak function, which yields:
    
            cmpq    $0, .refptr._ZTH1s(%rip)
            je      .L2
            call    _ZTH1s
    
    and the cmpq keeps a relocation that does not overflow.
    
    gcc/
            PR c++/64697
            * config/i386/i386.c (legitimate_pic_address_disp_p): For PE-COFF do
            not return true for external weak function symbols in medium model.

Diff:
---
 gcc/config/i386/i386.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 103fa10a9c5..bcee6bafa96 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -10335,24 +10335,19 @@ legitimate_pic_address_disp_p (rtx disp)
 	      if (is_imported_p (op0))
 		return true;
 
-	      if (SYMBOL_REF_FAR_ADDR_P (op0)
-		  || !SYMBOL_REF_LOCAL_P (op0))
+	      if (SYMBOL_REF_FAR_ADDR_P (op0) || !SYMBOL_REF_LOCAL_P (op0))
 		break;
 
-	      /* Function-symbols need to be resolved only for
-	         large-model.
-	         For the small-model we don't need to resolve anything
-	         here.  */
+	      /* Non-external-weak function symbols need to be resolved only
+		 for the large model.  Non-external symbols don't need to be
+		 resolved for large and medium models.  For the small model,
+		 we don't need to resolve anything here.  */
 	      if ((ix86_cmodel != CM_LARGE_PIC
-	           && SYMBOL_REF_FUNCTION_P (op0))
+		   && SYMBOL_REF_FUNCTION_P (op0)
+		   && !(SYMBOL_REF_EXTERNAL_P (op0) && SYMBOL_REF_WEAK (op0)))
+		  || !SYMBOL_REF_EXTERNAL_P (op0)
 		  || ix86_cmodel == CM_SMALL_PIC)
 		return true;
-	      /* Non-external symbols don't need to be resolved for
-	         large, and medium-model.  */
-	      if ((ix86_cmodel == CM_LARGE_PIC
-		   || ix86_cmodel == CM_MEDIUM_PIC)
-		  && !SYMBOL_REF_EXTERNAL_P (op0))
-		return true;
 	    }
 	  else if (!SYMBOL_REF_FAR_ADDR_P (op0)
 		   && (SYMBOL_REF_LOCAL_P (op0)


                 reply	other threads:[~2021-10-01  9:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20211001090220.C4E0B3858422@sourceware.org \
    --to=ebotcazou@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.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).