This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] dwarf2out fixes
- From: Jakub Jelinek <jakub at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 29 Sep 2009 12:32:04 +0200
- Subject: [PATCH] dwarf2out fixes
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
This patch cures two problems reported recently.
One is the problem linking shared libraries on mips/x86_64 if they mention
some undefined symbol in .debug_info/.debug_loc - with the current ld we
really can't do that, even if it doesn't fail to link it, on most targets it
discards .rel{,a}.debug_{info,loc} sections during final link, so the
constants appear as 0 anyway. Ideally ld during final link would only keep
.rel{,a}.debug{_info,loc} etc. relocations for stuff that needs relocation,
for all local symbols drop it after resolving them.
The second issue is that CONCAT{,N} and VAR_LOCATION case in
mem_loc_descriptor has a forgotten gcc_unreachable () after reporting
expansion_failed.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2009-09-29 Jakub Jelinek <jakub@redhat.com>
* dwarf2out.c (const_ok_for_output_1, const_ok_for_output): New
functions.
(mem_loc_descriptor, loc_descriptor, add_const_value_attribute): Bail
out if !const_ok_for_output.
PR debug/41474
* dwarf2out.c (mem_loc_descriptor) <case CONCAT, case CONCATN,
case VAR_LOCATION>: Remove gcc_unreachable ().
* gcc.dg/debug/dwarf2/const-1.c: Add dg-require-visibility, make x
hidden.
* g++.dg/debug/dwarf2/const-1.C: Likewise.
--- gcc/dwarf2out.c.jj 2009-09-25 14:34:11.000000000 +0200
+++ gcc/dwarf2out.c 2009-09-29 09:41:15.000000000 +0200
@@ -11091,6 +11091,70 @@ expansion_failed (tree expr, rtx rtl, ch
}
}
+/* Helper function for const_ok_for_output, called either directly
+ or via for_each_rtx. */
+
+static int
+const_ok_for_output_1 (rtx *rtlp, void *data ATTRIBUTE_UNUSED)
+{
+ rtx rtl = *rtlp;
+
+ if (GET_CODE (rtl) != SYMBOL_REF)
+ return 0;
+
+ if (CONSTANT_POOL_ADDRESS_P (rtl))
+ {
+ bool marked;
+ get_pool_constant_mark (rtl, &marked);
+ /* If all references to this pool constant were optimized away,
+ it was not output and thus we can't represent it. */
+ if (!marked)
+ {
+ expansion_failed (NULL_TREE, rtl,
+ "Constant was removed from constant pool.\n");
+ return 1;
+ }
+ }
+
+ if (SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
+ return 1;
+
+ /* Avoid references to external symbols in debug info, on several targets
+ the linker might even refuse to link when linking a shared library,
+ and in many other cases the relocations for .debug_info/.debug_loc are
+ dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
+ to be defined within the same shared library or executable are fine. */
+ if (SYMBOL_REF_EXTERNAL_P (rtl))
+ {
+ tree decl = SYMBOL_REF_DECL (rtl);
+
+ if (decl == NULL || !targetm.binds_local_p (decl))
+ {
+ expansion_failed (NULL_TREE, rtl,
+ "Symbol not defined in current TU.\n");
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+/* Return true if constant RTL can be emitted in DW_OP_addr or
+ DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
+ non-marked constant pool SYMBOL_REFs can't be referenced in it. */
+
+static bool
+const_ok_for_output (rtx rtl)
+{
+ if (GET_CODE (rtl) == SYMBOL_REF)
+ return const_ok_for_output_1 (&rtl, NULL) == 0;
+
+ if (GET_CODE (rtl) == CONST)
+ return for_each_rtx (&XEXP (rtl, 0), const_ok_for_output_1, NULL) == 0;
+
+ return true;
+}
+
/* The following routine converts the RTL for a variable or parameter
(resident in memory) into an equivalent Dwarf representation of a
mechanism for getting the address of that same variable onto the top of a
@@ -11265,6 +11329,9 @@ mem_loc_descriptor (rtx rtl, enum machin
break;
}
+ if (!const_ok_for_output (rtl))
+ break;
+
mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
@@ -11276,7 +11343,6 @@ mem_loc_descriptor (rtx rtl, enum machin
case VAR_LOCATION:
expansion_failed (NULL_TREE, rtl,
"CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
- gcc_unreachable ();
return 0;
case PRE_MODIFY:
@@ -11971,8 +12037,7 @@ loc_descriptor (rtx rtl, enum machine_mo
}
/* FALLTHROUGH */
case SYMBOL_REF:
- if (GET_CODE (rtl) == SYMBOL_REF
- && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
+ if (!const_ok_for_output (rtl))
break;
case LABEL_REF:
if (mode != VOIDmode && GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE
@@ -12553,7 +12618,7 @@ loc_list_from_tree (tree loc, int want_a
expansion_failed (loc, NULL_RTX, "CONST_STRING");
return 0;
}
- else if (CONSTANT_P (rtl))
+ else if (CONSTANT_P (rtl) && const_ok_for_output (rtl))
{
ret = new_loc_descr (DW_OP_addr, 0, 0);
ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
@@ -12903,8 +12968,11 @@ loc_list_from_tree (tree loc, int want_a
"DWARF address size mismatch");
return 0;
}
- add_loc_descr_to_each (list_ret,
- new_loc_descr (DW_OP_stack_value, 0, 0));
+ if (ret)
+ add_loc_descr (&ret, new_loc_descr (DW_OP_stack_value, 0, 0));
+ else
+ add_loc_descr_to_each (list_ret,
+ new_loc_descr (DW_OP_stack_value, 0, 0));
have_address = 1;
}
/* Show if we can't fill the request for an address. */
@@ -13448,8 +13516,7 @@ add_const_value_attribute (dw_die_ref di
return add_const_value_attribute (die, XEXP (rtl, 0));
/* FALLTHROUGH */
case SYMBOL_REF:
- if (GET_CODE (rtl) == SYMBOL_REF
- && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
+ if (!const_ok_for_output (rtl))
return false;
case LABEL_REF:
add_AT_addr (die, DW_AT_const_value, rtl);
--- gcc/testsuite/gcc.dg/debug/dwarf2/const-1.c.jj 2008-09-30 16:54:45.000000000 +0200
+++ gcc/testsuite/gcc.dg/debug/dwarf2/const-1.c 2009-09-29 09:42:44.000000000 +0200
@@ -1,6 +1,7 @@
/* { dg-do compile } */
/* { dg-options "-O -gdwarf-2 -dA" } */
+/* { dg-require-visibility "" } */
/* { dg-final { scan-assembler "DW_AT_const_value" } } */
-extern void x();
+extern void x() __attribute__((visibility("hidden")));
static void (*f)() = x;
--- gcc/testsuite/g++.dg/debug/dwarf2/const1.C.jj 2008-09-30 16:55:08.000000000 +0200
+++ gcc/testsuite/g++.dg/debug/dwarf2/const1.C 2009-09-29 09:43:23.000000000 +0200
@@ -1,6 +1,7 @@
/* { dg-do compile } */
/* { dg-options "-O -gdwarf-2 -dA" } */
+/* { dg-require-visibility "" } */
/* { dg-final { scan-assembler "DW_AT_const_value" } } */
-extern void x ();
+extern void x () __attribute__((visibility ("hidden")));
void (* const f) () = x;
Jakub