This is the mail archive of the binutils@sourceware.org mailing list for the binutils 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]

Re: Segfault in objdump?


Curiousity got the better of me.  The problem is triggered by
a) Different memory layout when running objdump -S under make
b) Trailing rubbish at the end of your .stab section
 c01f75c8 00000000 44001801 e6a013c0 00000000  ....D...........
 c01f75d8 44001901 e8a013c0 00000000 44001a01  D...........D...
 c01f75e8 e9a013c0 0000                        ......          
                   ^^^^
c) These zeros are seen as a marker for the next compilation unit
   (see include/aout/stab.def N_UNDF), bumping the .stabstr offset
   (bdf/syms.c:1158).
d) syms.c:1178 and syms.c:1247 store this offset string pointer with
   a pointer to a previous stab.

We ought to be keeping a copy of the string pointer for use with any
previous stab.

	* syms.c (_bfd_stab_section_find_nearest_line): Add last_str
	var.  Use it with last_stab.

Index: bfd/syms.c
===================================================================
RCS file: /cvs/src/src/bfd/syms.c,v
retrieving revision 1.58
diff -u -p -r1.58 syms.c
--- bfd/syms.c	10 Jan 2013 20:03:55 -0000	1.58
+++ bfd/syms.c	3 Jun 2013 04:01:18 -0000
@@ -934,7 +934,7 @@ _bfd_stab_section_find_nearest_line (bfd
   struct stab_find_info *info;
   bfd_size_type stabsize, strsize;
   bfd_byte *stab, *str;
-  bfd_byte *last_stab = NULL;
+  bfd_byte *last_stab, *last_str;
   bfd_size_type stroff;
   struct indexentry *indexentry;
   char *file_name;
@@ -1147,8 +1147,9 @@ _bfd_stab_section_find_nearest_line (bfd
       file_name = NULL;
       directory_name = NULL;
       saw_fun = 1;
+      stroff = 0;
 
-      for (i = 0, stroff = 0, stab = info->stabs, str = info->strs;
+      for (i = 0, last_stab = stab = info->stabs, last_str = str = info->strs;
 	   i < info->indextablesize && stab < info->stabs + stabsize;
 	   stab += STABSIZE)
 	{
@@ -1174,7 +1175,7 @@ _bfd_stab_section_find_nearest_line (bfd
 		{
 		  info->indextable[i].val = bfd_get_32 (abfd, last_stab + VALOFF);
 		  info->indextable[i].stab = last_stab;
-		  info->indextable[i].str = str;
+		  info->indextable[i].str = last_str;
 		  info->indextable[i].directory_name = directory_name;
 		  info->indextable[i].file_name = file_name;
 		  info->indextable[i].function_name = NULL;
@@ -1192,6 +1193,7 @@ _bfd_stab_section_find_nearest_line (bfd
 	      else
 		{
 		  last_stab = stab;
+		  last_str = str;
 		  if (stab + STABSIZE >= info->stabs + stabsize
 		      || *(stab + STABSIZE + TYPEOFF) != (bfd_byte) N_SO)
 		    {
@@ -1242,7 +1244,7 @@ _bfd_stab_section_find_nearest_line (bfd
 	{
 	  info->indextable[i].val = bfd_get_32 (abfd, last_stab + VALOFF);
 	  info->indextable[i].stab = last_stab;
-	  info->indextable[i].str = str;
+	  info->indextable[i].str = last_str;
 	  info->indextable[i].directory_name = directory_name;
 	  info->indextable[i].file_name = file_name;
 	  info->indextable[i].function_name = NULL;

-- 
Alan Modra
Australia Development Lab, IBM


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