public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "iains at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/104117] [9,10,11,12 Regression] Darwin ppc64 uses invalid non-PIC address to access constants (in PIC code).
Date: Sun, 06 Feb 2022 11:54:58 +0000	[thread overview]
Message-ID: <bug-104117-4-gez0T2wulz@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-104117-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104117

--- Comment #17 from Iain Sandoe <iains at gcc dot gnu.org> ---
FTR: this is the patch I came up with:

diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 843ce97b993..3f803bd791f 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -8244,8 +8244,14 @@ darwin_rs6000_legitimate_lo_sum_const_p (rtx x,
machine_mode mode)
   if (GET_CODE (x) == CONST)
     x = XEXP (x, 0);

+  /* If we are building PIC code, then any symbol must be wrapped in an
+     UNSPEC_MACHOPIC_OFFSET so that it will get the picbase subtracted.  */
+  bool machopic_offs_p = false;
   if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_MACHOPIC_OFFSET)
-    x =  XVECEXP (x, 0, 0);
+    {
+      x =  XVECEXP (x, 0, 0);
+      machopic_offs_p = true;
+    }

   rtx sym = NULL_RTX;
   unsigned HOST_WIDE_INT offset = 0;
@@ -8276,6 +8282,9 @@ darwin_rs6000_legitimate_lo_sum_const_p (rtx x,
machine_mode mode)
   if (sym)
     {
       tree decl = SYMBOL_REF_DECL (sym);
+      /* As noted above, PIC code cannot use a bare SYMBOL_REF.  */
+      if (TARGET_MACHO && flag_pic && !machopic_offs_p)
+       return false;
 #if TARGET_MACHO
       if (MACHO_SYMBOL_INDIRECTION_P (sym))
       /* The decl in an indirection symbol is the original one, which might
@@ -8863,7 +8872,7 @@ legitimate_lo_sum_address_p (machine_mode mode, rtx x,
int strict)
     return false;
   x = XEXP (x, 1);

-  if (TARGET_ELF || TARGET_MACHO)
+  if (TARGET_ELF)
     {
       bool large_toc_ok;

@@ -8889,11 +8898,35 @@ legitimate_lo_sum_address_p (machine_mode mode, rtx x,
int strict)

       return CONSTANT_P (x) || large_toc_ok;
     }
+  else if (TARGET_MACHO)
+    {
+      if (GET_MODE_NUNITS (mode) != 1)
+       return false;
+      if (GET_MODE_SIZE (mode) > UNITS_PER_WORD
+         && !(/* see above  */
+              TARGET_HARD_FLOAT && (mode == DFmode || mode == DDmode)))
+       return false;
+#if TARGET_MACHO
+      if (MACHO_DYNAMIC_NO_PIC_P || !flag_pic)
+       return CONSTANT_P (x);
+#endif
+      /* Macho-O PIC code from here.  */
+      if (GET_CODE (x) == CONST)
+       x = XEXP (x, 0);

+      /* SYMBOL_REFs need to be wrapped in an UNSPEC_MACHOPIC_OFFSET.  */
+      if (SYMBOL_REF_P (x))
+       return false;
+
+      /* So this is OK if the wrapped object is const.  */
+      if (GET_CODE (x) == UNSPEC
+         && XINT (x, 1) == UNSPEC_MACHOPIC_OFFSET)
+       return CONSTANT_P (XVECEXP (x, 0, 0));
+      return CONSTANT_P (x);
+    }
   return false;
 }

-
 /* Try machine-dependent ways of modifying an illegitimate address
    to be legitimate.  If we find one, return the new, valid address.
    This is used from only one place: `memory_address' in explow.c.
diff --git a/gcc/lra-constraints.c b/gcc/lra-constraints.c
index 5c2a2d7ce9c..3961dfd2725 100644
--- a/gcc/lra-constraints.c
+++ b/gcc/lra-constraints.c
@@ -3589,21 +3589,8 @@ process_address_1 (int nop, bool check_only_p,
                  *ad.inner = gen_rtx_LO_SUM (Pmode, new_reg, addr);
                  if (!valid_address_p (op, &ad, cn))
                    {
-                     /* Try to put lo_sum into register.  */
-                     insn = emit_insn (gen_rtx_SET
-                                       (new_reg,
-                                        gen_rtx_LO_SUM (Pmode, new_reg,
addr)));
-                     code = recog_memoized (insn);
-                     if (code >= 0)
-                       {
-                         *ad.inner = new_reg;
-                         if (!valid_address_p (op, &ad, cn))
-                           {
-                             *ad.inner = addr;
-                             code = -1;
-                           }
-                       }
-
+                     *ad.inner = addr; /* Punt.  */
+                     code = -1;
                    }
                }
              if (code < 0)

  parent reply	other threads:[~2022-02-06 11:54 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-19 14:35 [Bug target/104117] New: gcc10 fails to build icu for ppc64 on 10.5.8 (direct access to a floating-point constant) vital.had at gmail dot com
2022-01-19 14:58 ` [Bug target/104117] " iains at gcc dot gnu.org
2022-01-19 15:01 ` iains at gcc dot gnu.org
2022-01-19 15:54 ` vital.had at gmail dot com
2022-01-20  7:36 ` rguenth at gcc dot gnu.org
2022-01-20  7:45 ` iains at gcc dot gnu.org
2022-01-20  8:38 ` iains at gcc dot gnu.org
2022-01-20 14:29 ` [Bug target/104117] [9,10,11,12 Regression] Darwin ppc64 uses invalid non-PIC address to access constants (in PIC code) iains at gcc dot gnu.org
2022-01-20 14:31 ` iains at gcc dot gnu.org
2022-01-20 14:33 ` iains at gcc dot gnu.org
2022-01-20 14:37 ` iains at gcc dot gnu.org
2022-01-20 15:23 ` iains at gcc dot gnu.org
2022-01-22  9:34 ` vital.had at gmail dot com
2022-02-04 22:05 ` vmakarov at gcc dot gnu.org
2022-02-05  8:06 ` vital.had at gmail dot com
2022-02-06 10:34 ` iains at gcc dot gnu.org
2022-02-06 10:36 ` iains at gcc dot gnu.org
2022-02-06 11:54 ` iains at gcc dot gnu.org [this message]
2022-02-06 12:22 ` vital.had at gmail dot com
2022-02-06 13:23 ` iains at gcc dot gnu.org
2022-02-06 15:46 ` iains at gcc dot gnu.org
2022-02-09 15:56 ` vmakarov at gcc dot gnu.org
2022-02-11  2:21 ` vital.had at gmail dot com
2022-02-11 23:52 ` cvs-commit at gcc dot gnu.org
2022-02-13 19:37 ` iains at gcc dot gnu.org
2022-03-04 15:07 ` cvs-commit at gcc dot gnu.org
2022-04-14  5:28 ` cvs-commit at gcc dot gnu.org
2022-05-29 19:12 ` [Bug target/104117] [9,10 " cvs-commit at gcc dot gnu.org
2022-05-29 19:24 ` iains at gcc dot gnu.org

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=bug-104117-4-gez0T2wulz@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).