This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH] BFD: Handle copying of absolute section symbols
- From: "Maciej W. Rozycki" <macro at linux-mips dot org>
- To: Alan Modra <amodra at gmail dot com>
- Cc: binutils at sourceware dot org, Richard Sandiford <rdsandiford at googlemail dot com>
- Date: Mon, 7 May 2012 06:30:02 +0100 (BST)
- Subject: Re: [PATCH] BFD: Handle copying of absolute section symbols
- References: <alpine.LFD.2.00.1204090102360.19691@eddie.linux-mips.org> <20120410233400.GA24704@bubble.grove.modra.org> <alpine.LFD.2.00.1204161249480.19691@eddie.linux-mips.org> <20120416124817.GD3218@bubble.grove.modra.org> <alpine.LFD.2.00.1204161429070.19691@eddie.linux-mips.org> <20120417144802.GE3218@bubble.grove.modra.org>
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;
}