Bug 5170 - Improper casting when creating local symbols.
Summary: Improper casting when creating local symbols.
Status: RESOLVED INVALID
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: unspecified
: P3 minor
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-10-12 22:01 UTC by Evandro
Modified: 2007-10-13 21:54 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Proposed fix. (517 bytes, patch)
2007-10-12 22:03 UTC, Evandro
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Evandro 2007-10-12 22:01:25 UTC
It seems to me that a local_symbol should not be merely cast as symbol in
gas/symbols.c, as it's done in a couple of places.  Or perhaps I'm missing
something...
Comment 1 Evandro 2007-10-12 22:03:11 UTC
Created attachment 2041 [details]
Proposed fix.

I believe that the function local_symbol_convert should do the proper
conversion.
Comment 2 Evandro 2007-10-12 22:05:57 UTC
Comment on attachment 2041 [details]
Proposed fix.

Index: gas/symbols.c
===================================================================
retrieving revision 1.3
diff -p -u -w -r1.3 symbols.c
--- gas/symbols.c	26 Oct 2006 19:49:25 -0000	1.3
+++ gas/symbols.c	12 Oct 2007 21:57:51 -0000
@@ -477,9 +477,10 @@ colon (sym_name)		/* Just seen "x:" - ra
 #ifdef BFD_ASSEMBLER
   else if (! flag_keep_locals && bfd_is_local_label_name (stdoutput,
sym_name))
     {
-      symbolP = (symbolS *) local_symbol_make (sym_name, now_seg,
+      symbolP = local_symbol_convert (
+			     local_symbol_make (sym_name, now_seg,
						(valueT) frag_now_fix (),
-						frag_now);
+						frag_now));
     }
 #endif /* BFD_ASSEMBLER */
   else
@@ -565,9 +566,10 @@ symbol_find_or_make (name)
	  if (symbolP != NULL)
	    return symbolP;

-	  symbolP = (symbolS *) local_symbol_make (name, undefined_section,
+	  symbolP = local_symbol_convert (
+				local_symbol_make (name, undefined_section,
						   (valueT) 0,
-						   &zero_address_frag);
+						   &zero_address_frag));
	  return symbolP;
	}
 #endif
Comment 3 Alan Modra 2007-10-13 10:50:27 UTC
The code you are patching is perfectly good as is.
Comment 4 Evandro 2007-10-13 16:39:10 UTC
Interesting, for it seems that unless local_symbol_convert is used, the frag
information is lost and it results in an assertion at elf_common when the symbol
is local (starting with "." or "L")...
Comment 5 Alan Modra 2007-10-13 21:54:18 UTC
Yes, it is possible that local_symbol_convert needs to be called at some other
place in the gas code, but not here (see the comment above struct local_symbol
in struc-symbol.h).  I can't tell where because you haven't explained exactly
what is going wrong, or better, provided a test case.  I also gather you are
using an old source code base by the "#ifdef BFD_ASSEMBLER" in your patch. 
Mysterious bug  reports against some unknown old version of binutils don't help
us make a better binutils..