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: Patch: Fix elf_find_function () on a corner case


Alan Modra wrote:
So I'm rejecting the patch as it is.  You might be able to do something
reasonable with ld -r output by noticing that section symbols precede
file symbols for ld -r.

Thanks!

This is my second try. I'm not sure if the section symbols always come first for ld -r output. If so, this patch should work. If not, the state machine in elf_find_function () may need rewrite.

Regards,
Jie
	* elf.c (elf_find_function): Don't report a filename at all for
	global symbols when there are two or more FILE symbols for
	ld -r output.

Index: elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.318
diff -u -p -r1.318 elf.c
--- elf.c	3 Nov 2005 02:53:38 -0000	1.318
+++ elf.c	28 Nov 2005 14:31:51 -0000
@@ -6633,6 +6633,7 @@ elf_find_function (bfd *abfd ATTRIBUTE_U
      ld -r doesn't do this.  So, for ld -r output, it is possible to
      make a better choice of file name for local symbols by ignoring
      file symbols appearing after a given local symbol.  */
+  int is_ld_r_output;
   enum { nothing_seen, symbol_seen, file_after_symbol_seen } state;
 
   filename = NULL;
@@ -6641,6 +6642,13 @@ elf_find_function (bfd *abfd ATTRIBUTE_U
   low_func = 0;
   state = nothing_seen;
 
+  /* The section symbols precede file symbols for ld -r.  */
+  if (ELF_ST_TYPE (((elf_symbol_type *) *symbols)->internal_elf_sym.st_info)
+      == STT_SECTION)
+    is_ld_r_output = 1;
+  else
+    is_ld_r_output = 0;
+
   for (p = symbols; *p != NULL; p++)
     {
       elf_symbol_type *q;
@@ -6652,9 +6660,9 @@ elf_find_function (bfd *abfd ATTRIBUTE_U
 	default:
 	  break;
 	case STT_FILE:
-	  file = &q->symbol;
-	  if (state == symbol_seen)
+	  if (state == symbol_seen || (is_ld_r_output && file != NULL))
 	    state = file_after_symbol_seen;
+	  file = &q->symbol;
 	  continue;
 	case STT_SECTION:
 	  continue;

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