[PATCH] Always return the full path of filenames in bfd

Alan Modra amodra@bigpond.net.au
Sun Sep 17 00:39:00 GMT 2006


On Sat, Sep 16, 2006 at 06:59:10PM +1000, Anton Blanchard wrote:
> I narrowed the issue down to dwarf2.c:concat_filename() where it only
> applies the compile directory to a filename if the filename didnt have a
> directory component.
> 
> Does the patch below look reasonable?

It's not quite right.  According to the Dwarf3 standard, table->dirs
might contain absolute paths.  In that case you wouldn't want to prefix
comp_dir.

	* dwarf2.c (concat_filename) Apply DW_AT_comp_dir if dir table
	entry isn't absolute.

Index: bfd/dwarf2.c
===================================================================
RCS file: /cvs/src/src/bfd/dwarf2.c,v
retrieving revision 1.89
diff -u -p -r1.89 dwarf2.c
--- bfd/dwarf2.c	2 May 2006 10:01:56 -0000	1.89
+++ bfd/dwarf2.c	16 Sep 2006 23:36:21 -0000
@@ -874,24 +874,45 @@ concat_filename (struct line_info_table 
 
   filename = table->files[file - 1].name;
 
-  if (! IS_ABSOLUTE_PATH (filename))
+  if (!IS_ABSOLUTE_PATH (filename))
     {
-      char *dirname = (table->files[file - 1].dir
-		       ? table->dirs[table->files[file - 1].dir - 1]
-		       : table->comp_dir);
-
-      /* Not all tools set DW_AT_comp_dir, so dirname may be unknown.
-	 The best we can do is return the filename part.  */
-      if (dirname != NULL)
+      char *dirname = NULL;
+      char *subdirname = NULL;
+      char *name;
+      size_t len;
+
+      if (table->files[file - 1].dir)
+	subdirname = table->dirs[table->files[file - 1].dir - 1];
+
+      if (!subdirname || !IS_ABSOLUTE_PATH (subdirname))
+	dirname = table->comp_dir;
+
+      if (!dirname)
 	{
-	  unsigned int len = strlen (dirname) + strlen (filename) + 2;
-	  char * name;
+	  dirname = subdirname;
+	  subdirname = NULL;
+	}
 
+      if (!dirname)
+	return strdup (filename);
+
+      len = strlen (dirname) + strlen (filename) + 2;
+
+      if (subdirname)
+	{
+	  len += strlen (subdirname) + 1;
+	  name = bfd_malloc (len);
+	  if (name)
+	    sprintf (name, "%s/%s/%s", dirname, subdirname, filename);
+	}
+      else
+	{
 	  name = bfd_malloc (len);
 	  if (name)
 	    sprintf (name, "%s/%s", dirname, filename);
-	  return name;
 	}
+
+      return name;
     }
 
   return strdup (filename);

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre



More information about the Binutils mailing list