[[RFC] DWARF2 debug support for HP-UX SOM target

John David Anglin dave@hiauly1.hia.nrc.ca
Sun Aug 13 15:06:00 GMT 2006

On Wed, Aug 02, 2006 at 03:21:56PM -0400, Daniel Jacobowitz wrote:
> On Wed, Aug 02, 2006 at 03:16:56PM -0400, John David Anglin wrote:
> > > > I have a question, though, which I think I've asked before.  GCC on
> > > > HP/UX uses stabs, so only requires basic SOM support from GDB.  That
> > > 
> > > There have been requests for ELF debug support.  The main issue as
> > > far as I can see is the lack of named sections and where to put stuff.
> Do you mean DWARF-2 here?  If so, I completely agree.  It seems like
> SOM has some named sections - at least we're managing to get objdump to
> tell me there's a GDB_STRINGS section - so I don't know what the
> problem is.

> I'd be much happier working on support for GCC :-)  Especially if that
> means DWARF-2 debug information!

I've attached a couple of preliminary patches to GCC and binutils
to implement DWARF2 debugging on the HP-UX RA-RISC SOM target.  It
builds and I don't see any testsuite regressions so far.  What I need
to know is whether GDB can successfully access the DWARF2 subspaces
and whether this actually works.

What I did was to enable the target define to create named sections.
Then, I disabled use of named sections for functions, data, profiling,
etc.  I confirmed with a full bootstrap and check that named sections
weren't being used.  This part was easy.

Next, I added the code to create the DWARF2 sections (subspaces) and
enabled DWARF2.  This is when I discovered that GAS didn't support
label differences in different segments.  Ok, so I define DIFF_EXPR_OK
in tc-hppa.h in spite of the comment that says it doesn't work.  I
think I may have fixed this problem last fall when I corrected data

Then, I discover that HP ld can't do unaligned symbol differences.
Well, I knew that but I didn't realize that dwarf2out.c needs this
capability.  The HP linker can do unaligned fixups for absolute
addresses.  I see that defining have_multiple_function_sections to
true in dwarf2out.c causes it to use absolute references.  The
code in dwarf2out.c can't detect our unnamed subspace changes in
the $TEXT$ space.  Even with a single function we have multiple text
subspaces, so I decided to just provide a mechanism to initialize
have_multiple_function_sections to true.

So, the fundamental problem is that the HP linker can't handle
unaligned symbol differences.  I haven't detected any further problems
with this in the test build, but I don't understand the DWARF
machinary sufficiently well to know if there are other circumstances
where unaligned symbol differences might occur.

There are minor problems with the section flags printed by objdump.
However, odump tells me they are correct.  I tried to setup the
DWARF2 debug space and subspaces in a manner similar to HP's debug
format.  I at first used the $DEBUG$ space but discovered that HP
also uses this space for their debug information.  Putting the
DWARF2 info in this space confuses pxdb, so I changes the name to


J. David Anglin                                  dave.anglin@nrc-cnrc.gc.ca
National Research Council of Canada              (613) 990-0752 (FAX: 952-6602)
-------------- next part --------------
Index: defaults.h
--- defaults.h	(revision 116106)
+++ defaults.h	(working copy)
@@ -355,6 +355,14 @@
+/* If a compilation always places functions in more than one section,
+   then you may need to define HAVE_MULTIPLE_FUNCTION_SECTIONS to TRUE
+   in your target configuration file in order to support the DWARF2 debug
+   format.  This avoids unaligned symbol differences from being emitted.  */
 /* If we have named section and we support weak symbols, then use the
    .jcr section for recording java classes which need to be registered
    at program start-up time.  */
Index: dwarf2out.c
--- dwarf2out.c	(revision 116106)
+++ dwarf2out.c	(working copy)
@@ -3904,7 +3904,8 @@
 static GTY(()) unsigned line_info_table_in_use;
 /* True if the compilation unit places functions in more than one section.  */
-static GTY(()) bool have_multiple_function_sections = false;
+static GTY(()) bool have_multiple_function_sections
 /* A pointer to the base of a table that contains line information
    for each source code line outside of .text in the compilation unit.  */
Index: predict.c
--- predict.c	(revision 116106)
+++ predict.c	(working copy)
@@ -1820,6 +1820,8 @@
 static void
 choose_function_section (void)
+  size_t len;
   if (DECL_SECTION_NAME (current_function_decl)
       || !targetm.have_named_sections
       /* Theoretically we can split the gnu.linkonce text section too,
@@ -1836,12 +1838,19 @@
   if (cfun->function_frequency == FUNCTION_FREQUENCY_HOT)
-    DECL_SECTION_NAME (current_function_decl) =
-      build_string (strlen (HOT_TEXT_SECTION_NAME), HOT_TEXT_SECTION_NAME);
+    {
+      len = strlen (HOT_TEXT_SECTION_NAME);
+      if (len)
+	DECL_SECTION_NAME (current_function_decl) =
+	  build_string (len, HOT_TEXT_SECTION_NAME);
+    }
   if (cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED)
-    DECL_SECTION_NAME (current_function_decl) =
-      build_string (strlen (UNLIKELY_EXECUTED_TEXT_SECTION_NAME),
+    {
+      if (len)
+	DECL_SECTION_NAME (current_function_decl) =
+    }
 static bool
Index: config/pa/som.h
--- config/pa/som.h	(revision 116106)
+++ config/pa/som.h	(working copy)
@@ -23,20 +23,45 @@
 #undef TARGET_SOM
 #define TARGET_SOM 1
+/* Finally, our preferred format is DWARF2_DEBUG!  */
 /* We do not use BINCL stabs in SOM.
    ??? If it does not hurt, we probably should to avoid useless divergence
    from other embedded stabs implementations.  */
+/* Don't generate dbx function end.  */
-/* gdb needs a null N_SO at the end of each file for scattered loading.  */
+/* Put the eh frame data in the data section.  */  
+/* Provide empty names for hot and unlikely executed text sections.  */
+/* The HP linker can't handle unaligned symbol differences.  When a
+   compilation unit has multiple function sections, the DWARF2 output
+   code avoids emitting unaligned symbol differences.  Effectively,
+   every function is placed in its own unnamed subspace when using
+   SOM.  However, these subspace switches aren't noticed by
+   dwarf2out_begin_function (), so we need to forcibly initialize
+   have_multiple_function_sections to TRUE.  */
+#if 0
+/* If using HP ld do not call pxdb.  Use size as a program that does nothing
+   and returns 0.  /bin/true cannot be used because it is a script without
+   an interpreter.  */
+#define INIT_ENVIRONMENT "LD_PXDB=/usr/ccs/bin/size"
 /* HPUX has a program 'chatr' to list the dependencies of dynamically
    linked executables and shared libraries.  */
 #define LDD_SUFFIX "chatr"
 /* Look for lines like "dynamic   /usr/lib/X11R5/libX11.sl"
    or "static    /usr/lib/X11R5/libX11.sl". 
@@ -176,6 +201,8 @@
 #define TARGET_ASM_FILE_START pa_som_file_start
 #define TARGET_ASM_INIT_SECTIONS pa_som_asm_init_sections
+#define TARGET_ASM_NAMED_SECTION  pa_som_asm_named_section
+#define TARGET_ASM_UNIQUE_SECTION pa_som_unique_section
 /* String to output before writable data.  */
Index: config/pa/pa.c
--- config/pa/pa.c	(revision 116106)
+++ config/pa/pa.c	(working copy)
@@ -108,6 +108,9 @@
 static int pa_adjust_priority (rtx, int);
 static int pa_issue_rate (void);
 static void pa_som_asm_init_sections (void) ATTRIBUTE_UNUSED;
+static void pa_som_asm_named_section (const char *, unsigned int,
+				      tree) ATTRIBUTE_UNUSED;
+static void pa_som_unique_section (tree, int) ATTRIBUTE_UNUSED;
 static section *pa_select_section (tree, int, unsigned HOST_WIDE_INT)
 static void pa_encode_section_info (tree, rtx, int);
@@ -488,11 +491,27 @@
   if (flag_pic == 1 || TARGET_64BIT)
     flag_pic = 2;
+  if (TARGET_SOM)
+    {
+      /* We have named sections but they are only for special purposes.  */
+      if (flag_function_sections)
+	{
+	  warning (0, "-ffunction-sections not supported for this target");
+	  flag_function_sections = 0;
+	}
+      if (flag_data_sections)
+	{
+	  warning (0, "-fdata-sections not supported for this target");
+	  flag_data_sections = 0;
+	}
+    }
   /* We can't guarantee that .dword is available for 32-bit targets.  */
   if (UNITS_PER_WORD == 4)
     targetm.asm_out.aligned_op.di = NULL;
-  /* The unaligned ops are only available when using GAS.  */
+  /* The unaligned ops are only available when using GAS.  Note that
+     the HP linker isn't in general able to handle unaligned fixups.  */
   if (!TARGET_GAS)
       targetm.asm_out.unaligned_op.hi = NULL;
@@ -9372,6 +9391,40 @@
   exception_section = data_section;
+static void
+pa_som_asm_named_section (const char *name ATTRIBUTE_UNUSED,
+			  unsigned int flags ATTRIBUTE_UNUSED,
+                          tree decl ATTRIBUTE_UNUSED)
+  /* Currently, we only use named sections for debug sections.  */
+  if (!(flags & SECTION_DEBUG))
+    gcc_unreachable ();
+  if (flags & SECTION_DECLARED)
+    {
+      fprintf (asm_out_file, "\t.SPACE $DWARF_DEBUG$\n\t.SUBSPA %s\n", name);
+      return;
+    }
+  fprintf (asm_out_file,
+  fprintf (asm_out_file,
+	   name);
+static void
+pa_som_unique_section (tree decl ATTRIBUTE_UNUSED,
+		       int reloc ATTRIBUTE_UNUSED)
+  /* We don't use unique section names for declarations, but
+     we need to override the default implementation.  */
 /* On hpux10, the linker will give an error if we have a reference
    in the read-only data section to a symbol defined in a shared
    library.  Therefore, expressions that might require a reloc can
-------------- next part --------------
Index: config/tc-hppa.h
RCS file: /cvs/src/src/gas/config/tc-hppa.h,v
retrieving revision 1.31
diff -u -r1.31 tc-hppa.h
--- config/tc-hppa.h	24 May 2006 11:05:42 -0000	1.31
+++ config/tc-hppa.h	13 Aug 2006 14:01:16 -0000
@@ -150,6 +150,7 @@
    the add symbol is undefined and the sub symbol is a symbol in
    the same section as the relocation.  We also need some way to
    specialize some code in adjust_reloc_syms.  */
+#define DIFF_EXPR_OK

More information about the Gcc-patches mailing list