Fix PR12762 using linkonce sections in plugin bfd
H.J. Lu
hjl.tools@gmail.com
Thu Aug 11 13:18:00 GMT 2011
On Thu, Aug 11, 2011 at 6:08 AM, Alan Modra <amodra@gmail.com> wrote:
> This patch undoes HJ's changes to bfd_section_already_linked in
> http://sourceware.org/ml/binutils/2011-07/msg00070.html, and some of
> my later changes. HJ's patch effectively added another type of entry
> to the already_linked list for plugin comdat symbols. This works fine
> most of the time, but there are parts of the bfd and linker code that
> really want separate sections for comdat symbols. For example,
> ldmain.c:multiple_definition just after the FIXME comment. So
> this patch simply provides dummy linkonce sections for plugin comdat
> symbols.
>
> Ironically, the FIXME advocates doing exactly what we were attempting
> in plugin.c:add_symbols, so in some respects this patch is a backwards
> step. It also uses more memory. The reason I didn't apply further
> tweaks like the patch in PR13066 is that bfd_section_already_linked
> was getting quite messy. If we are going to go the way this FIXME
> suggests then we really aught to do so for all symbols, not just
> plugin symbols. I'd like to see that happen but don't have time at
> the moment to fix all the fallout.
>
> Index: ld/plugin.c
> ===================================================================
> RCS file: /cvs/src/src/ld/plugin.c,v
> retrieving revision 1.38
> diff -u -p -r1.38 plugin.c
> --- ld/plugin.c 9 Aug 2011 09:27:34 -0000 1.38
> +++ ld/plugin.c 11 Aug 2011 06:24:21 -0000
> @@ -32,7 +32,6 @@
> #include "plugin.h"
> #include "plugin-api.h"
> #include "elf-bfd.h"
> -#include "libbfd.h"
> #if !defined (HAVE_DLFCN_H) && defined (HAVE_WINDOWS_H)
> #include <windows.h>
> #endif
> @@ -240,7 +239,7 @@ plugin_get_ir_dummy_bfd (const char *nam
> {
> flagword flags;
>
> - /* Create sections to own the symbols. */
> + /* Create section to own the symbols. */
> flags = (SEC_CODE | SEC_HAS_CONTENTS | SEC_READONLY
> | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_EXCLUDE);
> if (bfd_make_section_anyway_with_flags (abfd, ".text", flags))
> @@ -285,7 +284,25 @@ asymbol_from_plugin_symbol (bfd *abfd, a
> /* FALLTHRU */
> case LDPK_DEF:
> flags |= BSF_GLOBAL;
> - section = bfd_get_section_by_name (abfd, ".text");
> + if (ldsym->comdat_key)
> + {
> + section = bfd_get_section_by_name (abfd, ldsym->comdat_key);
> + if (section == NULL)
> + {
> + flagword sflags;
> +
> + sflags = (SEC_CODE | SEC_HAS_CONTENTS | SEC_READONLY
> + | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_EXCLUDE
> + | SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD);
> + section = bfd_make_section_anyway_with_flags (abfd,
> + xstrdup (ldsym->comdat_key),
> + sflags);
> + if (section == NULL)
> + return LDPS_ERR;
> + }
> + }
> + else
> + section = bfd_get_section_by_name (abfd, ".text");
> break;
>
This is the first approach I tried and failed with GCC 4.7 LTO
tests on Linux/x86-64 since adding new sections to dummy
LTO bfd at this stage didn't work very well.
--
H.J.
More information about the Binutils
mailing list