[PATCH] BFD: Handle copying of absolute section symbols

Maciej W. Rozycki macro@linux-mips.org
Mon May 7 05:30:00 GMT 2012


On Wed, 18 Apr 2012, Alan Modra wrote:

> >  Hmm, you can't mean we should keep global symbols from dropped sections 
> > (be it section or ordinary symbols), can you?
> > 
> >  We're dropping this symbol because it does not belong to any section 
> > being output, not because it's global or not.  If it wasn't absolute, but 
> > its section was dropped, it would be (correctly) dropped as well.  
> > Likewise if it was local and absolute, it would be (incorrectly) dropped 
> > too -- this is fixed by my change just as for global absolute symbols.
> > 
> >  I'm confused, sorry.
> 
> The comment on ignore_section_symbol is no doubt the source of your
> confusion.  ignore_section_symbol doesn't just drop section symbols
> from dropped sections, it also drops duplicates.  For example, each
> .text section in an input file normally has a section symbol.  We only
> need to keep one.  At least, that is the case for the st_value==0,
> st_name==0 STB_LOCAL section symbols that gas usually emits.

 Oh, I see, that's the "sym->section->output_offset == 0" condition.  

> When you have other sorts of section symbols they probably shouldn't
> be dropped as duplicates.  That's what I was getting at. 

 Hmm, I think you're right, do you mean something like the change below?  
It works for my case too and otherwise doesn't cause any regressions for 
mips64-linux-gnu.

 Note that I have preserved the current behaviour of producing the special 
section symbols pointing to the base of each section output regardless of 
the presence of any global section symbols that might be defined for the 
same section.  I wonder how this is going to work if such a global symbol 
is indeed present, but perhaps that's not something we should be concerned 
about until we actually have a real case.  What do you think?

2012-05-07  Maciej W. Rozycki  <macro@linux-mips.org>

	bfd/
	* elf.c (elf_map_symbols): Never discard global section symbols.

  Maciej

binutils-mips-dynamic-linking.patch
Index: binutils/bfd/elf.c
===================================================================
--- binutils.orig/bfd/elf.c
+++ binutils/bfd/elf.c
@@ -3308,12 +3308,10 @@ elf_map_symbols (bfd *abfd)
   /* Classify all of the symbols.  */
   for (idx = 0; idx < symcount; idx++)
     {
-      if (ignore_section_sym (abfd, syms[idx]))
-	continue;
-      if (!sym_is_global (abfd, syms[idx]))
-	num_locals++;
-      else
+      if (sym_is_global (abfd, syms[idx]))
 	num_globals++;
+      else if (!ignore_section_sym (abfd, syms[idx]))
+	num_locals++;
     }
 
   /* We will be adding a section symbol for each normal BFD section.  Most
@@ -3343,12 +3341,12 @@ elf_map_symbols (bfd *abfd)
       asymbol *sym = syms[idx];
       unsigned int i;
 
-      if (ignore_section_sym (abfd, sym))
-	continue;
-      if (!sym_is_global (abfd, sym))
+      if (sym_is_global (abfd, sym))
+	i = num_locals + num_globals2++;
+      else if (!ignore_section_sym (abfd, sym))
 	i = num_locals2++;
       else
-	i = num_locals + num_globals2++;
+	continue;
       new_syms[i] = sym;
       sym->udata.i = i + 1;
     }



More information about the Binutils mailing list