From 329f67aeceef041840cf7d3c3c5a715ccdae6e81 Mon Sep 17 00:00:00 2001
From: mrs <mrs@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Sat, 21 Aug 2004 06:49:16 +0000
Subject: [PATCH] 	* config/darwin.c (machopic_indirect_data_reference):
 Mark 	stubs as defined. 	* config/386/386.c (darwin_local_data_pic):
 Add. 	(legitimate_constant_p): Reorder so that PLUS handling runs 	before
 darwin_local_data_pic to match the ordering in 
 legitimate_pic_address_disp_p and so that MINUS runs after 
 darwin_local_data_pic as otherwise the darwin_local_data_pic 	logic can be
 skipped, which would be very bad. 	(legitimate_pic_address_disp_p): Move
 from from here to 	darwin_local_data_pic so it can be reused.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@86355 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog          | 13 +++++++++++
 gcc/config/darwin.c    |  3 ++-
 gcc/config/i386/i386.c | 49 ++++++++++++++++++++++++++++++------------
 3 files changed, 50 insertions(+), 15 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 3af5733f7974..90413bd4b67c 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,16 @@
+2004-08-20  Mike Stump  <mrs@apple.com>
+
+	* config/darwin.c (machopic_indirect_data_reference): Mark
+	stubs as defined.
+	* config/386/386.c (darwin_local_data_pic): Add.
+	(legitimate_constant_p): Reorder so that PLUS handling runs
+	before darwin_local_data_pic to match the ordering in
+	legitimate_pic_address_disp_p and so that MINUS runs after
+	darwin_local_data_pic as otherwise the darwin_local_data_pic
+	logic can be skipped, which would be very bad.
+	(legitimate_pic_address_disp_p): Move from from here to
+	darwin_local_data_pic so it can be reused.
+
 2004-08-21  Alan Modra  <amodra@bigpond.net.au>
 
 	* config/rs6000/linux64.h (DOT_SYMBOLS): Define.
diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c
index d34dcfe411d0..44c8539f9b70 100644
--- a/gcc/config/darwin.c
+++ b/gcc/config/darwin.c
@@ -455,13 +455,14 @@ machopic_indirect_data_reference (rtx orig, rtx reg)
 	  return orig;
 	}
 
-      ptr_ref = (gen_rtx_SYMBOL_REF 
+      ptr_ref = (gen_rtx_SYMBOL_REF
 		 (Pmode, 
 		  machopic_indirection_name (orig, /*stub_p=*/false)));
 
       SYMBOL_REF_DECL (ptr_ref) = SYMBOL_REF_DECL (orig);
 
       ptr_ref = gen_const_mem (Pmode, ptr_ref);
+      machopic_define_symbol (ptr_ref);
 
       return ptr_ref;
     }
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 9ae3972c4627..0213239303ef 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -4791,6 +4791,28 @@ ix86_find_base_term (rtx x)
 
   return term;
 }
+
+/* Allow {LABEL | SYMBOL}_REF - SYMBOL_REF-FOR-PICBASE for Mach-O as
+   this is used for to form addresses to local data when -fPIC is in
+   use.  */
+
+static bool
+darwin_local_data_pic (rtx disp)
+{
+  if (GET_CODE (disp) == MINUS)
+    {
+      if (GET_CODE (XEXP (disp, 0)) == LABEL_REF
+          || GET_CODE (XEXP (disp, 0)) == SYMBOL_REF)
+        if (GET_CODE (XEXP (disp, 1)) == SYMBOL_REF)
+          {
+            const char *sym_name = XSTR (XEXP (disp, 1), 0);
+            if (! strcmp (sym_name, "<pic base>"))
+              return true;
+          }
+    }
+
+  return false;
+}
 
 /* Determine if a given RTX is a valid constant.  We already know this
    satisfies CONSTANT_P.  */
@@ -4817,8 +4839,17 @@ legitimate_constant_p (rtx x)
 	  && tls_symbolic_operand (XEXP (inner, 0), Pmode))
 	return false;
 
-      if (GET_CODE (inner) == PLUS
-	  || GET_CODE (inner) == MINUS)
+      if (GET_CODE (inner) == PLUS)
+	{
+	  if (GET_CODE (XEXP (inner, 1)) != CONST_INT)
+	    return false;
+	  inner = XEXP (inner, 0);
+	}
+
+      if (TARGET_MACHO && darwin_local_data_pic (inner))
+	return true;
+
+      if (GET_CODE (inner) == MINUS)
 	{
 	  if (GET_CODE (XEXP (inner, 1)) != CONST_INT)
 	    return false;
@@ -4966,18 +4997,8 @@ legitimate_pic_address_disp_p (rtx disp)
       saw_plus = true;
     }
 
-  /* Allow {LABEL | SYMBOL}_REF - SYMBOL_REF-FOR-PICBASE for Mach-O.  */
-  if (TARGET_MACHO && GET_CODE (disp) == MINUS)
-    {
-      if (GET_CODE (XEXP (disp, 0)) == LABEL_REF
-          || GET_CODE (XEXP (disp, 0)) == SYMBOL_REF)
-        if (GET_CODE (XEXP (disp, 1)) == SYMBOL_REF)
-          {
-            const char *sym_name = XSTR (XEXP (disp, 1), 0);
-            if (! strcmp (sym_name, "<pic base>"))
-              return 1;
-          }
-    }
+  if (TARGET_MACHO && darwin_local_data_pic (disp))
+    return 1;
 
   if (GET_CODE (disp) != UNSPEC)
     return 0;
-- 
GitLab