PATCH: Multiple sections with same name don't work

H. J. Lu hjl@lucon.org
Sat May 1 17:31:00 GMT 2004


On Sat, May 01, 2004 at 08:37:20AM -0700, H. J. Lu wrote:
> On Sun, May 02, 2004 at 12:14:39AM +0930, Alan Modra wrote:
> > On Sat, May 01, 2004 at 12:06:18AM -0700, H. J. Lu wrote:
> > > On Fri, Apr 30, 2004 at 10:50:08PM -0700, H. J. Lu wrote:
> > > > On Fri, Apr 30, 2004 at 10:12:01PM -0700, Zack Weinberg wrote:
> > > > > Alan Modra <amodra@bigpond.net.au> writes:
> > > > > > The real question is: Do we need multiple sections of the same name
> > > > > > in assembly files?  I don't think we do.
> > > > > 
> > > > > I need them in order to generate COMDAT sections compatible with the
> > > > > HPUX linker.  gcc might emit e.g.
> > > > > 
> > > > >      .section .text 
> > > > >      # non-COMDAT code  ...
> > > > > 
> > > > >      .section .text,"G",symbol_name,comdat
> > > > >      # code for symbol_name ...
> > 
> > Hmm, it wouldn't be much harder to use
> > 
> >      .section .text.symbol_name,"G",symbol_name,comdat
> >      # code for symbol_name ...
> > 
> > I fear HJ is going to be repeating the following a few more times.. 
> > 
> 
> I am ready for it.
> 
> > > This patch is not enough. Here is an updated one.
> > 
> > [snip]
> > > +  /* Don't reset it if it is already a BFD section symbol.  */
> > > +  if ((s->bsym->flags & BSF_SECTION_SYM) == 0)
> > > +    s->bsym = bsym;
> 
> This patch is no longer needed for multiple section with the same
> name. The section_symbol patch is enough.
> 
> > 
> > This is a useless comment.  It just says what anyone can see from the
> > next line of code.  It would be better to say _why_ it is necessary to
> > treat section symbols specially.
> > 
> 
> Since now we create multiple symbols with the same name, I think
> we need a new interface to lookup symbols with matching section.
> 
> 

I was wrong on both. We don't need a new interface for symbol lookup.
Also we do need the symbol_set_bfdsym change.


H.J.
----
2004-05-01  H.J. Lu  <hongjiu.lu@intel.com>

	* subsegs.c (section_symbol): Create a new section symbol if
	the existing one doesn't match.

	* symbols.c (symbol_set_bfdsym): Don't reset BFD section symbol.

--- gas/subsegs.c.same	2003-12-04 10:43:25.000000000 -0800
+++ gas/subsegs.c	2004-05-01 09:13:31.000000000 -0700
@@ -524,7 +524,9 @@ section_symbol (segT sec)
   else
     {
       s = symbol_find_base (sec->symbol->name, 0);
-      if (s == NULL)
+      /* We have to make sure it is the right symbol when we have
+	 multiple sections with the same section name.  */
+      if (s == NULL || S_GET_SEGMENT (s) != sec)
 	s = symbol_new (sec->symbol->name, sec, 0, &zero_address_frag);
       else
 	{
--- gas/symbols.c.same	2004-05-01 07:55:53.000000000 -0700
+++ gas/symbols.c	2004-05-01 10:11:31.000000000 -0700
@@ -2260,7 +2260,15 @@ symbol_set_bfdsym (symbolS *s, asymbol *
 {
   if (LOCAL_SYMBOL_CHECK (s))
     s = local_symbol_convert ((struct local_symbol *) s);
-  s->bsym = bsym;
+  /* Usually, it is harmless to reset a symbol to a BFD section
+     symbol. For example, obj_elf_change_section sets the BFD symbol
+     of an old symbol with the newly created section symbol. But when
+     we have multiple sections with the same name, the newly created
+     section may have the same name as an old section. We check if the
+     old symbol has been already marked as a section symbol before
+     resetting it.  */
+  if ((s->bsym->flags & BSF_SECTION_SYM) == 0)
+    s->bsym = bsym;
 }
 
 #endif /* BFD_ASSEMBLER */



More information about the Binutils mailing list