This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Build dbx stabs differently for powerpc-apple-darwin*


The following patch changes the dbx stabs output form for symbols in common
(N_LCSYM) for powerpc-apple-darwin* builds.  This system's loader and linker
does not relocate addresses in nlist stabs entries.  Stabs of the N_LCSYM type
do not get the common section' base address added to them, so a debugger can't
display the symbols' contents properly.  The problem impairs debuggability of
C, possibly C++ and, most severely, Fortran code which may heavily rely on
common blocks (which prompts this patch).

To work around this deficiency, this patch causes gcc to emit N_LCSYM stabs
surrounded by N_BCOMM/N_ECOMM.  It puts the name of the common section into
the N_BCOMM stabs n_name/n_strx, so the debugger can find the base address for
the common section symbolically.  The gdb distributed with Darwin 6.6 handles
this form of common symbol information properly and allows full debuggability
when common symbols are used.

NB - The Darwin 6.6 behavior regarding non-relocation of stabs nlist entries was
reported to Apple as ProblemID 3278880 04-Jun-2003 12:58PM and was determined
to "behave correctly" so is unlikely to be fixed in Darwin's linker/loader.

The change in stabs is only for powerpc-apple-darwin* builds.  It has a side
effect of making the stabs info larger since there is no attempt to optimize
emission of symbols within a single N_BCOMM/N_ECOMM bracket.

--- gcc/ChangeLog.orig	Wed Aug  6 17:20:08 2003
+++ gcc/ChangeLog	Tue Sep 16 18:03:56 2003
@@ -1,3 +1,13 @@
+2003-09-15  George Helffrich <george@geo.titech.ac.jp>
+
+	* config/darwin.h:  Don't generate N_LCSYM dbx nlist entries for
+	symbols in Fortran common.
+	* dbxout.c:  Don't generate N_LCSYM dbx nlist entries with symbol
+	addresses in them symbols in Fortran common, use N_BCOMM, N_ECOMM
+	and offset in common.  Native Darwin loader won't relocate
+	addresses in nlist entries, do makes fortran common symbols unaccessable
+	for debugging.
+
 2003-08-06  Phil Edwards  <pme@gcc.gnu.org>
 
 	* doc/install.texi (*-*-solaris2*):  Refine configure instructions.
--- gcc/config/darwin.h.orig	Sun Jul 27 02:48:07 2003
+++ gcc/config/darwin.h	Sun Sep 14 16:33:05 2003
@@ -295,6 +295,12 @@
 
 #define DBX_USE_BINCL
 
+/* Darwin linker does not relocate addresses in NLIST entries, so we
+   try to work around this by using alternative dbx encodings for
+   variables in common (N_LCSYM) */
+
+#define DBX_NO_NLIST_RELOCATION
+
 /* There is no limit to the length of stabs strings.  */
 
 #define DBX_CONTIN_LENGTH 0
--- gcc/dbxout.c.orig	Tue Aug  5 22:15:56 2003
+++ gcc/dbxout.c	Sun Sep 14 16:32:17 2003
@@ -347,6 +347,7 @@
 static void dbxout_class_name_qualifiers (tree);
 static int dbxout_symbol_location (tree, tree, const char *, rtx);
 static void dbxout_symbol_name (tree, const char *, int);
+static void dbxout_common_name (tree, STAB_CODE_TYPE);
 static void dbxout_prepare_symbol (tree);
 static void dbxout_finish_symbol (tree);
 static void dbxout_block (tree, int, tree);
@@ -2642,6 +2643,11 @@
   /* Ok, start a symtab entry and output the variable name.  */
   FORCE_TEXT;
 
+#ifdef DBX_NO_NLIST_RELOCATION
+  if (DECL_COMMON(decl) && current_sym_code == N_LCSYM)
+    dbxout_common_name(decl, N_BCOMM);
+#endif
+
 #ifdef DBX_STATIC_BLOCK_START
   DBX_STATIC_BLOCK_START (asmfile, current_sym_code);
 #endif
@@ -2653,6 +2659,11 @@
 #ifdef DBX_STATIC_BLOCK_END
   DBX_STATIC_BLOCK_END (asmfile, current_sym_code);
 #endif
+
+#ifdef DBX_NO_NLIST_RELOCATION
+  if (DECL_COMMON(decl) && current_sym_code == N_LCSYM)
+    dbxout_common_name(decl, N_ECOMM);
+#endif
   return 1;
 }
 
@@ -2683,6 +2694,68 @@
   if (letter)
     putc (letter, asmfile);
 }
+
+#ifdef DBX_NO_NLIST_RELOCATION
+/* Output the common block name for DECL in a stabs. */
+
+static void
+dbxout_common_name (tree decl, STAB_CODE_TYPE op)
+{
+  const char *name;
+
+  STAB_CODE_TYPE csave = current_sym_code;
+  static rtx asave;
+  static int vsave;
+  int value;
+
+  if (op == N_BCOMM)
+    {
+      asave = current_sym_addr;
+      vsave = current_sym_value;
+    }
+
+  switch (GET_CODE(asave)) 
+    {
+    case PLUS:
+      if (GET_CODE (XEXP (asave, 0)) == CONST_INT)
+        {
+	  name = (* targetm.strip_name_encoding)(XSTR (XEXP (asave, 1), 0));
+	  value = INTVAL (XEXP (asave, 0));
+	}
+      else
+        {
+	  name = (* targetm.strip_name_encoding)(XSTR (XEXP (asave, 0), 0));
+	  value = INTVAL (XEXP (asave, 1));
+        }
+      break;
+
+    case SYMBOL_REF:
+      name = (* targetm.strip_name_encoding)(XSTR (asave, 0));
+      value = 0;
+      break;
+	
+    default:
+      if (op == N_ECOMM)
+	warning("debug info for common symbol may be incorrect");
+      return;
+    }
+
+  fprintf (asmfile, "%s\"%s", ASM_STABS_OP, name);
+  current_sym_addr = 0;
+  current_sym_value = 0;
+  current_sym_code = op;
+  dbxout_finish_symbol (decl);
+
+  if (op == N_ECOMM)
+    {
+      current_sym_addr = asave;
+      current_sym_value = vsave;
+    }
+  else
+    current_sym_value = value;
+  current_sym_code = csave;
+}
+#endif
 
 static void
 dbxout_prepare_symbol (tree decl ATTRIBUTE_UNUSED)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]