re PR target/51957 (ppc64 .debug_loc toc reference)
authorJakub Jelinek <jakub@redhat.com>
Tue, 24 Jan 2012 07:24:34 +0000 (08:24 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 24 Jan 2012 07:24:34 +0000 (08:24 +0100)
PR target/51957
* target.def (const_not_ok_for_debug_p): New hook.
* doc/tm.texi.in (TARGET_CONST_NOT_OK_FOR_DEBUG_P): New hook
documentation.
* doc/tm.texi: Regenerated.
* dwarf2out.c (const_ok_for_output_1): If
targetm.const_not_ok_for_debug_p returns true, fail.
* config/rs6000/rs6000.c (rs6000_const_not_ok_for_debug_p): New
function.
(TARGET_CONST_NOT_OK_FOR_DEBUG_P): Redefine.

* gcc.dg/pr51957-1.c: New test.
* gcc.dg/pr51957-1.h: New file.
* gcc.dg/pr51957-2.c: New test.

From-SVN: r183468

gcc/ChangeLog
gcc/config/rs6000/rs6000.c
gcc/doc/tm.texi
gcc/doc/tm.texi.in
gcc/dwarf2out.c
gcc/target.def
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr51957-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr51957-1.h [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr51957-2.c [new file with mode: 0644]

index 82b574a950d8c2a2f140754fccf74b7f44e66a7d..6455954d3030b68c23fdad559ae7945295aa59f7 100644 (file)
@@ -1,3 +1,16 @@
+2012-01-24  Jakub Jelinek  <jakub@redhat.com>
+
+       PR target/51957
+       * target.def (const_not_ok_for_debug_p): New hook.
+       * doc/tm.texi.in (TARGET_CONST_NOT_OK_FOR_DEBUG_P): New hook
+       documentation.
+       * doc/tm.texi: Regenerated.
+       * dwarf2out.c (const_ok_for_output_1): If
+       targetm.const_not_ok_for_debug_p returns true, fail.
+       * config/rs6000/rs6000.c (rs6000_const_not_ok_for_debug_p): New
+       function.
+       (TARGET_CONST_NOT_OK_FOR_DEBUG_P): Redefine.
+
 2012-01-23  Kai Tietz  <ktietz@redhat.com>
 
        PR target/51900
index a24ea86881eef512d510e41a1e6ae766b96c1ff8..539cc8b3beeefd66909aa338b97fba9ebb0a4482 100644 (file)
@@ -1106,6 +1106,7 @@ static rtx rs6000_debug_legitimize_address (rtx, rtx, enum machine_mode);
 static rtx rs6000_legitimize_tls_address (rtx, enum tls_model);
 static void rs6000_output_dwarf_dtprel (FILE *, int, rtx) ATTRIBUTE_UNUSED;
 static rtx rs6000_delegitimize_address (rtx);
+static bool rs6000_const_not_ok_for_debug_p (rtx);
 static rtx rs6000_tls_get_addr (void);
 static rtx rs6000_got_sym (void);
 static int rs6000_tls_symbol_ref_1 (rtx *, void *);
@@ -1405,6 +1406,9 @@ static const struct attribute_spec rs6000_attribute_table[] =
 #undef TARGET_DELEGITIMIZE_ADDRESS
 #define TARGET_DELEGITIMIZE_ADDRESS rs6000_delegitimize_address
 
+#undef TARGET_CONST_NOT_OK_FOR_DEBUG_P
+#define TARGET_CONST_NOT_OK_FOR_DEBUG_P rs6000_const_not_ok_for_debug_p
+
 #undef TARGET_ASM_FUNCTION_PROLOGUE
 #define TARGET_ASM_FUNCTION_PROLOGUE rs6000_output_function_prologue
 #undef TARGET_ASM_FUNCTION_EPILOGUE
@@ -5815,6 +5819,25 @@ rs6000_delegitimize_address (rtx orig_x)
   return orig_x;
 }
 
+/* Return true if X shouldn't be emitted into the debug info.
+   The linker doesn't like .toc section references from
+   .debug_* sections, so reject .toc section symbols.  */
+
+static bool
+rs6000_const_not_ok_for_debug_p (rtx x)
+{
+  if (GET_CODE (x) == SYMBOL_REF
+      && CONSTANT_POOL_ADDRESS_P (x))
+    {
+      rtx c = get_pool_constant (x);
+      enum machine_mode cmode = get_pool_mode (x);
+      if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (c, cmode))
+       return true;
+    }
+
+  return false;
+}
+
 /* Construct the SYMBOL_REF for the tls_get_addr function.  */
 
 static GTY(()) rtx rs6000_tls_symbol;
index 9a51968b91c7c3174b870e2f3e4ba813bcbef145..ceb0d1ea4dec5b469af947cf1b7d4c323c67e40c 100644 (file)
@@ -5631,6 +5631,11 @@ the semantics of these opaque @code{UNSPEC}s by converting them back
 into their original form.
 @end deftypefn
 
+@deftypefn {Target Hook} bool TARGET_CONST_NOT_OK_FOR_DEBUG_P (rtx @var{x})
+This hook should return true if @var{x} should not be emitted into
+debug sections.
+@end deftypefn
+
 @deftypefn {Target Hook} bool TARGET_CANNOT_FORCE_CONST_MEM (enum machine_mode @var{mode}, rtx @var{x})
 This hook should return true if @var{x} is of a form that cannot (or
 should not) be spilled to the constant pool.  @var{mode} is the mode
index 42d69565e80fc9598c35f447dac9981969c24ea3..55c8432c3bf1ea1d9ec80f4dd3e3e666f89e2ccc 100644 (file)
@@ -5567,6 +5567,11 @@ the semantics of these opaque @code{UNSPEC}s by converting them back
 into their original form.
 @end deftypefn
 
+@hook TARGET_CONST_NOT_OK_FOR_DEBUG_P
+This hook should return true if @var{x} should not be emitted into
+debug sections.
+@end deftypefn
+
 @hook TARGET_CANNOT_FORCE_CONST_MEM
 This hook should return true if @var{x} is of a form that cannot (or
 should not) be spilled to the constant pool.  @var{mode} is the mode
index ed279ba65fe9b2083ee21eebdaf3555bc016f6f9..fee5c60e403020cbea20e240ae919a002c9887ab 100644 (file)
@@ -10683,6 +10683,13 @@ const_ok_for_output_1 (rtx *rtlp, void *data ATTRIBUTE_UNUSED)
       return 1;
     }
 
+  if (targetm.const_not_ok_for_debug_p (rtl))
+    {
+      expansion_failed (NULL_TREE, rtl,
+                       "Expression rejected for debug by the backend.\n");
+      return 1;
+    }
+
   if (GET_CODE (rtl) != SYMBOL_REF)
     return 0;
 
index cdc8cb84ad10693502e1262768cfd878ad51cb30..f86f782b0209bcd2f3b6bb2133d6d3ec2fdfdd5a 100644 (file)
@@ -1382,6 +1382,14 @@ DEFHOOK
  rtx, (rtx x),
  delegitimize_mem_from_attrs)
 
+/* Given an RTX, return true if it is not ok to emit it into debug info
+   section.  */
+DEFHOOK
+(const_not_ok_for_debug_p,
+ "",
+ bool, (rtx x),
+ hook_bool_rtx_false)
+
 /* Given an address RTX, say whether it is valid.  */
 DEFHOOK
 (legitimate_address_p,
index 43794d3e5eba10209ce9727d63a289885b6f33d8..9825bc517fa5afd10eef9de06750cb612a713635 100644 (file)
@@ -1,3 +1,10 @@
+2012-01-24  Jakub Jelinek  <jakub@redhat.com>
+
+       PR target/51957
+       * gcc.dg/pr51957-1.c: New test.
+       * gcc.dg/pr51957-1.h: New file.
+       * gcc.dg/pr51957-2.c: New test.
+
 2012-01-23  Jason Merrill  <jason@redhat.com>
 
        PR c++/51930
diff --git a/gcc/testsuite/gcc.dg/pr51957-1.c b/gcc/testsuite/gcc.dg/pr51957-1.c
new file mode 100644 (file)
index 0000000..d899771
--- /dev/null
@@ -0,0 +1,29 @@
+/* PR target/51957 */
+/* { dg-do link } */
+/* { dg-options "-O2 -g -fprofile-use" } */
+/* { dg-additional-sources "pr51957-2.c" } */
+
+int v[128];
+#include "pr51957-1.h"
+
+void
+foo (U *x)
+{
+  T *a = x->u;
+  while (1)
+    {
+      union R *b;
+      b = fn1 ();
+      if (b != w[0] && !(v[b->p->c] == 1))
+       {
+         fn2 (a->t, "foobar", b->p);
+         b = w[0];
+       }
+      if (b != w[0])
+       fn3 ();
+      if (w[0] && b != w[0])
+       fn4 (b->p);
+      if (b != w[0] && (v[b->p->c] == 1) && fn4 (b->p))
+       break;
+    }
+}
diff --git a/gcc/testsuite/gcc.dg/pr51957-1.h b/gcc/testsuite/gcc.dg/pr51957-1.h
new file mode 100644 (file)
index 0000000..cfafb2c
--- /dev/null
@@ -0,0 +1,9 @@
+union R { int c; union R *p; };
+extern union R *w[];
+typedef struct { int t; } T;
+typedef struct { void *u; } U;
+union R *fn1 (void);
+void fn2 (int, const char *, union R *);
+void fn3 (void);
+int fn4 (union R *);
+void foo (U *x);
diff --git a/gcc/testsuite/gcc.dg/pr51957-2.c b/gcc/testsuite/gcc.dg/pr51957-2.c
new file mode 100644 (file)
index 0000000..038921e
--- /dev/null
@@ -0,0 +1,35 @@
+/* PR target/51957 */
+/* { dg-do compile } */
+/* { dg-options "-O0" } */
+
+#include "pr51957-1.h"
+
+union R *w[10];
+
+union R *
+fn1 (void)
+{
+  return (union R *) 0;
+}
+
+void
+fn2 (int x, const char *y, union R *z)
+{
+}
+
+void
+fn3 (void)
+{
+}
+
+int
+fn4 (union R *x)
+{
+  return 0;
+}
+
+int
+main ()
+{
+  return 0;
+}