+2011-08-17 Alan Modra <amodra@gmail.com>
+
+ PR ld/12762
+ * bfd-in.h (struct bfd_section_already_linked): Forward declare.
+ (_bfd_handle_already_linked): Declare.
+ * coff-alpha.c (_bfd_ecoff_section_already_linked): Define as
+ _bfd_coff_section_already_linked.
+ * coff-mips.c (_bfd_ecoff_section_already_linked): Likewise.
+ * coffcode.h (coff_section_already_linked): Likewise.
+ * cofflink.c (coff_link_add_symbols): Revert 2011-07-09 changes.
+ * elf-bfd.h: Likewise.
+ * libbfd-in.h: Likewise.
+ * targets.c: Likewise.
+ * linker.c (bfd_section_already_linked): Likewise.
+ (bfd_section_already_linked_table_lookup): Likewise.
+ (bfd_section_already_linked_table_insert): Likewise.
+ (_bfd_generic_section_already_linked): Likewise. Call
+ _bfd_handle_already_linked.
+ (_bfd_handle_already_linked): New function, split out from..
+ * elflink.c (_bfd_elf_section_already_linked): ..here. Revert
+ 2011-07-09 changes. Avoid unnecessary strcmp when matching
+ already_linked_list entries. Match plugin linkonce section.
+ (section_signature): Delete.
+ * coffgen.c (_bfd_coff_section_already_linked): New function.
+ * libcoff-in.h (_bfd_coff_section_already_linked): Declare.
+ * libbfd.h: Regenerate.
+ * libcoff.h: Regenerate.
+ * bfd-in2.h: Regenerate.
+
2011-08-14 Alan Modra <amodra@gmail.com>
* elf32-ppc.c (ppc_elf_select_plt_layout): Force bss-plt when
bfd_uint64_t bfd_get_bits (const void *, int, bfd_boolean);
void bfd_put_bits (bfd_uint64_t, void *, int, bfd_boolean);
-extern bfd_boolean bfd_section_already_linked_table_init (void);
-extern void bfd_section_already_linked_table_free (void);
-\f
-/* Externally visible ECOFF routines. */
-
#if defined(__STDC__) || defined(ALMOST_STDC)
struct ecoff_debug_info;
struct ecoff_debug_swap;
struct bfd_symbol;
struct bfd_link_info;
struct bfd_link_hash_entry;
+struct bfd_section_already_linked;
struct bfd_elf_version_tree;
#endif
+
+extern bfd_boolean bfd_section_already_linked_table_init (void);
+extern void bfd_section_already_linked_table_free (void);
+extern bfd_boolean _bfd_handle_already_linked
+ (struct bfd_section *, struct bfd_section_already_linked *,
+ struct bfd_link_info *);
+\f
+/* Externally visible ECOFF routines. */
+
extern bfd_vma bfd_ecoff_get_gp_value
(bfd * abfd);
extern bfd_boolean bfd_ecoff_set_gp_value
bfd_uint64_t bfd_get_bits (const void *, int, bfd_boolean);
void bfd_put_bits (bfd_uint64_t, void *, int, bfd_boolean);
-extern bfd_boolean bfd_section_already_linked_table_init (void);
-extern void bfd_section_already_linked_table_free (void);
-\f
-/* Externally visible ECOFF routines. */
-
#if defined(__STDC__) || defined(ALMOST_STDC)
struct ecoff_debug_info;
struct ecoff_debug_swap;
struct bfd_symbol;
struct bfd_link_info;
struct bfd_link_hash_entry;
+struct bfd_section_already_linked;
struct bfd_elf_version_tree;
#endif
+
+extern bfd_boolean bfd_section_already_linked_table_init (void);
+extern void bfd_section_already_linked_table_free (void);
+extern bfd_boolean _bfd_handle_already_linked
+ (struct bfd_section *, struct bfd_section_already_linked *,
+ struct bfd_link_info *);
+\f
+/* Externally visible ECOFF routines. */
+
extern bfd_vma bfd_ecoff_get_gp_value
(bfd * abfd);
extern bfd_boolean bfd_ecoff_set_gp_value
/* Forward declaration. */
typedef struct bfd_link_info _bfd_link_info;
-struct already_linked;
/* Forward declaration. */
typedef struct flag_info flag_info;
/* Check if SEC has been already linked during a reloceatable or
final link. */
- bfd_boolean (*_section_already_linked) (bfd *, struct already_linked *,
+ bfd_boolean (*_section_already_linked) (bfd *, asection *,
struct bfd_link_info *);
/* Define a common symbol. */
BFD_SEND (abfd, _bfd_link_split_section, (abfd, sec))
bfd_boolean bfd_section_already_linked (bfd *abfd,
- struct already_linked *data,
+ asection *sec,
struct bfd_link_info *info);
-#define bfd_section_already_linked(abfd, data, info) \
- BFD_SEND (abfd, _section_already_linked, (abfd, data, info))
+#define bfd_section_already_linked(abfd, sec, info) \
+ BFD_SEND (abfd, _section_already_linked, (abfd, sec, info))
bfd_boolean bfd_generic_define_common_symbol
(bfd *output_bfd, struct bfd_link_info *info,
#define _bfd_ecoff_bfd_is_group_section bfd_generic_is_group_section
#define _bfd_ecoff_bfd_discard_group bfd_generic_discard_group
#define _bfd_ecoff_section_already_linked \
- _bfd_generic_section_already_linked
+ _bfd_coff_section_already_linked
#define _bfd_ecoff_bfd_define_common_symbol bfd_generic_define_common_symbol
const bfd_target ecoffalpha_little_vec =
#define _bfd_ecoff_bfd_is_group_section bfd_generic_is_group_section
#define _bfd_ecoff_bfd_discard_group bfd_generic_discard_group
#define _bfd_ecoff_section_already_linked \
- _bfd_generic_section_already_linked
+ _bfd_coff_section_already_linked
#define _bfd_ecoff_bfd_define_common_symbol bfd_generic_define_common_symbol
extern const bfd_target ecoff_big_vec;
#ifndef coff_section_already_linked
#define coff_section_already_linked \
- _bfd_generic_section_already_linked
+ _bfd_coff_section_already_linked
#endif
#ifndef coff_bfd_define_common_symbol
else
return NULL;
}
+
+bfd_boolean
+_bfd_coff_section_already_linked (bfd *abfd,
+ asection *sec,
+ struct bfd_link_info *info)
+{
+ flagword flags;
+ const char *name, *key;
+ struct bfd_section_already_linked *l;
+ struct bfd_section_already_linked_hash_entry *already_linked_list;
+ struct coff_comdat_info *s_comdat;
+
+ flags = sec->flags;
+ if ((flags & SEC_LINK_ONCE) == 0)
+ return FALSE;
+
+ /* The COFF backend linker doesn't support group sections. */
+ if ((flags & SEC_GROUP) != 0)
+ return FALSE;
+
+ name = bfd_get_section_name (abfd, sec);
+ s_comdat = bfd_coff_get_comdat_section (abfd, sec);
+
+ if (s_comdat != NULL)
+ key = s_comdat->name;
+ else
+ {
+ if (CONST_STRNEQ (name, ".gnu.linkonce.")
+ && (key = strchr (name + sizeof (".gnu.linkonce.") - 1, '.')) != NULL)
+ key++;
+ else
+ /* FIXME: gcc as of 2011-09 emits sections like .text$<key>,
+ .xdata$<key> and .pdata$<key> only the first of which has a
+ comdat key. Should these all match the LTO IR key? */
+ key = name;
+ }
+
+ already_linked_list = bfd_section_already_linked_table_lookup (key);
+
+ for (l = already_linked_list->entry; l != NULL; l = l->next)
+ {
+ struct coff_comdat_info *l_comdat;
+
+ l_comdat = bfd_coff_get_comdat_section (l->sec->owner, l->sec);
+
+ /* The section names must match, and both sections must be
+ comdat and have the same comdat name, or both sections must
+ be non-comdat. LTO IR plugin sections are an exception. They
+ are always named .gnu.linkonce.t.<key> (<key> is some string)
+ and match any comdat section with comdat name of <key>, and
+ any linkonce section with the same suffix, ie.
+ .gnu.linkonce.*.<key>. */
+ if (((s_comdat != NULL) == (l_comdat != NULL)
+ && strcmp (name, l->sec->name) == 0)
+ || (l->sec->owner->flags & BFD_PLUGIN) != 0)
+ {
+ /* The section has already been linked. See if we should
+ issue a warning. */
+ return _bfd_handle_already_linked (sec, l, info);
+ }
+ }
+
+ /* This is the first section with this name. Record it. */
+ if (!bfd_section_already_linked_table_insert (already_linked_list, sec))
+ info->callbacks->einfo (_("%F%P: already_linked_table: %E\n"));
+ return FALSE;
+}
section = coff_section_from_bfd_index (abfd, sym.n_scnum);
if (! obj_pe (abfd))
value -= section->vma;
- /* Treat a symbol from a discarded section as undefined. */
- if (bfd_is_abs_section (section)
- || !bfd_is_abs_section (section->output_section))
- break;
- /* Fall thru */
+ break;
case COFF_SYMBOL_UNDEFINED:
flags = 0;
(bfd *, const asection *, bfd *, const asection *);
extern bfd_boolean bfd_elf_is_group_section
(bfd *, const struct bfd_section *);
-struct already_linked;
extern bfd_boolean _bfd_elf_section_already_linked
- (bfd *, struct already_linked *, struct bfd_link_info *);
+ (bfd *, asection *, struct bfd_link_info *);
extern void bfd_elf_set_group_contents
(bfd *, asection *, void *);
extern asection *_bfd_elf_check_kept_section
return ret;
}
-/* For a SHT_GROUP section, return the group signature. For other
- sections, return the normal section name. */
-
-static const char *
-section_signature (asection *sec)
-{
- if ((sec->flags & SEC_GROUP) != 0
- && elf_next_in_group (sec) != NULL
- && elf_group_name (elf_next_in_group (sec)) != NULL)
- return elf_group_name (elf_next_in_group (sec));
- return sec->name;
-}
-
bfd_boolean
_bfd_elf_section_already_linked (bfd *abfd,
- struct already_linked *linked,
+ asection *sec,
struct bfd_link_info *info)
{
flagword flags;
- const char *name, *p;
+ const char *name, *key;
struct bfd_section_already_linked *l;
struct bfd_section_already_linked_hash_entry *already_linked_list;
- asection *sec, *l_sec;
- bfd_boolean matched;
-
- p = name = linked->comdat_key;
- if (name)
- {
- sec = NULL;
- flags = SEC_GROUP | SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
- }
- else
- {
- sec = linked->u.sec;
- if (sec->output_section == bfd_abs_section_ptr)
- return FALSE;
- flags = sec->flags;
-
- /* Return if it isn't a linkonce section. A comdat group section
- also has SEC_LINK_ONCE set. */
- if ((flags & SEC_LINK_ONCE) == 0)
- return FALSE;
-
- /* Don't put group member sections on our list of already linked
- sections. They are handled as a group via their group section.
- */
- if (elf_sec_group (sec) != NULL)
- return FALSE;
-
- /* FIXME: When doing a relocatable link, we may have trouble
- copying relocations in other sections that refer to local symbols
- in the section being discarded. Those relocations will have to
- be converted somehow; as of this writing I'm not sure that any of
- the backends handle that correctly.
+ if (sec->output_section == bfd_abs_section_ptr)
+ return FALSE;
- It is tempting to instead not discard link once sections when
- doing a relocatable link (technically, they should be discarded
- whenever we are building constructors). However, that fails,
- because the linker winds up combining all the link once sections
- into a single large link once section, which defeats the purpose
- of having link once sections in the first place.
+ flags = sec->flags;
- Also, not merging link once sections in a relocatable link
- causes trouble for MIPS ELF, which relies on link once semantics
- to handle the .reginfo section correctly. */
+ /* Return if it isn't a linkonce section. A comdat group section
+ also has SEC_LINK_ONCE set. */
+ if ((flags & SEC_LINK_ONCE) == 0)
+ return FALSE;
- name = section_signature (sec);
+ /* Don't put group member sections on our list of already linked
+ sections. They are handled as a group via their group section. */
+ if (elf_sec_group (sec) != NULL)
+ return FALSE;
+ /* For a SHT_GROUP section, use the group signature as the key. */
+ name = sec->name;
+ if ((flags & SEC_GROUP) != 0
+ && elf_next_in_group (sec) != NULL
+ && elf_group_name (elf_next_in_group (sec)) != NULL)
+ key = elf_group_name (elf_next_in_group (sec));
+ else
+ {
+ /* Otherwise we should have a .gnu.linkonce.<type>.<key> section. */
if (CONST_STRNEQ (name, ".gnu.linkonce.")
- && ((p = strchr (name + sizeof (".gnu.linkonce.") - 1, '.'))
- != NULL))
- p++;
+ && (key = strchr (name + sizeof (".gnu.linkonce.") - 1, '.')) != NULL)
+ key++;
else
- p = name;
+ /* Must be a user linkonce section that doesn't follow gcc's
+ naming convention. In this case we won't be matching
+ single member groups. */
+ key = name;
}
- already_linked_list = bfd_section_already_linked_table_lookup (p);
+ already_linked_list = bfd_section_already_linked_table_lookup (key);
for (l = already_linked_list->entry; l != NULL; l = l->next)
{
- flagword l_flags;
- bfd *l_owner;
- const char *l_name = l->linked.comdat_key;
- if (l_name)
- {
- l_sec = NULL;
- l_owner = l->linked.u.abfd;
- l_flags = (SEC_GROUP
- | SEC_LINK_ONCE
- | SEC_LINK_DUPLICATES_DISCARD);
- }
- else
- {
- l_sec = l->linked.u.sec;
- l_owner = l_sec->owner;
- l_flags = l_sec->flags;
- l_name = section_signature (l_sec);
- }
-
/* We may have 2 different types of sections on the list: group
- sections and linkonce sections. Match like sections. */
- if ((flags & SEC_GROUP) == (l_flags & SEC_GROUP)
- && strcmp (name, l_name) == 0)
+ sections with a signature of <key> (<key> is some string),
+ and linkonce sections named .gnu.linkonce.<type>.<key>.
+ Match like sections. LTO plugin sections are an exception.
+ They are always named .gnu.linkonce.t.<key> and match either
+ type of section. */
+ if (((flags & SEC_GROUP) == (l->sec->flags & SEC_GROUP)
+ && ((flags & SEC_GROUP) != 0
+ || strcmp (name, l->sec->name) == 0))
+ || (l->sec->owner->flags & BFD_PLUGIN) != 0)
{
/* The section has already been linked. See if we should
issue a warning. */
- switch (flags & SEC_LINK_DUPLICATES)
- {
- default:
- abort ();
-
- case SEC_LINK_DUPLICATES_DISCARD:
- /* If we found an LTO IR match for this comdat group on
- the first pass, replace it with the LTO output on the
- second pass. We can't simply choose real object
- files over IR because the first pass may contain a
- mix of LTO and normal objects and we must keep the
- first match, be it IR or real. */
- if (info->loading_lto_outputs
- && (l_owner->flags & BFD_PLUGIN) != 0)
- {
- l->linked = *linked;
- return FALSE;
- }
- break;
-
- case SEC_LINK_DUPLICATES_ONE_ONLY:
- (*_bfd_error_handler)
- (_("%B: ignoring duplicate section `%A'"),
- abfd, sec);
- break;
-
- case SEC_LINK_DUPLICATES_SAME_SIZE:
- if (!sec || !l_sec)
- abort ();
-
- if (sec->size != l_sec->size)
- (*_bfd_error_handler)
- (_("%B: duplicate section `%A' has different size"),
- abfd, sec);
- break;
-
- case SEC_LINK_DUPLICATES_SAME_CONTENTS:
- if (!sec || !l_sec)
- abort ();
-
- if (sec->size != l_sec->size)
- (*_bfd_error_handler)
- (_("%B: duplicate section `%A' has different size"),
- abfd, sec);
- else if (sec->size != 0)
- {
- bfd_byte *sec_contents, *l_sec_contents;
-
- if (!bfd_malloc_and_get_section (abfd, sec, &sec_contents))
- (*_bfd_error_handler)
- (_("%B: warning: could not read contents of section `%A'"),
- abfd, sec);
- else if (!bfd_malloc_and_get_section (l_sec->owner, l_sec,
- &l_sec_contents))
- (*_bfd_error_handler)
- (_("%B: warning: could not read contents of section `%A'"),
- l_sec->owner, l_sec);
- else if (memcmp (sec_contents, l_sec_contents, sec->size) != 0)
- (*_bfd_error_handler)
- (_("%B: warning: duplicate section `%A' has different contents"),
- abfd, sec);
-
- if (sec_contents)
- free (sec_contents);
- if (l_sec_contents)
- free (l_sec_contents);
- }
- break;
- }
+ if (!_bfd_handle_already_linked (sec, l, info))
+ return FALSE;
- if (sec)
+ if (flags & SEC_GROUP)
{
- /* Set the output_section field so that lang_add_section
- does not create a lang_input_section structure for this
- section. Since there might be a symbol in the section
- being discarded, we must retain a pointer to the section
- which we are really going to use. */
- sec->output_section = bfd_abs_section_ptr;
- sec->kept_section = l_sec;
+ asection *first = elf_next_in_group (sec);
+ asection *s = first;
- if (flags & SEC_GROUP)
+ while (s != NULL)
{
- asection *first = elf_next_in_group (sec);
- asection *s = first;
-
- while (s != NULL)
- {
- s->output_section = bfd_abs_section_ptr;
- /* Record which group discards it. */
- s->kept_section = l_sec;
- s = elf_next_in_group (s);
- /* These lists are circular. */
- if (s == first)
- break;
- }
+ s->output_section = bfd_abs_section_ptr;
+ /* Record which group discards it. */
+ s->kept_section = l->sec;
+ s = elf_next_in_group (s);
+ /* These lists are circular. */
+ if (s == first)
+ break;
}
}
}
}
- matched = FALSE;
- if (sec)
+ /* A single member comdat group section may be discarded by a
+ linkonce section and vice versa. */
+ if ((flags & SEC_GROUP) != 0)
{
- /* A single member comdat group section may be discarded by a
- linkonce section and vice versa. */
+ asection *first = elf_next_in_group (sec);
- if ((flags & SEC_GROUP) != 0)
+ if (first != NULL && elf_next_in_group (first) == first)
+ /* Check this single member group against linkonce sections. */
+ for (l = already_linked_list->entry; l != NULL; l = l->next)
+ if ((l->sec->flags & SEC_GROUP) == 0
+ && bfd_elf_match_symbols_in_sections (l->sec, first, info))
+ {
+ first->output_section = bfd_abs_section_ptr;
+ first->kept_section = l->sec;
+ sec->output_section = bfd_abs_section_ptr;
+ break;
+ }
+ }
+ else
+ /* Check this linkonce section against single member groups. */
+ for (l = already_linked_list->entry; l != NULL; l = l->next)
+ if (l->sec->flags & SEC_GROUP)
{
- asection *first = elf_next_in_group (sec);
+ asection *first = elf_next_in_group (l->sec);
- if (first != NULL && elf_next_in_group (first) == first)
- /* Check this single member group against linkonce sections. */
- for (l = already_linked_list->entry; l != NULL; l = l->next)
- {
- if (l->linked.comdat_key == NULL)
- {
- l_sec = l->linked.u.sec;
-
- if ((l_sec->flags & SEC_GROUP) == 0
- && bfd_coff_get_comdat_section (l_sec->owner,
- l_sec) == NULL
- && bfd_elf_match_symbols_in_sections (l_sec,
- first,
- info))
- {
- first->output_section = bfd_abs_section_ptr;
- first->kept_section = l_sec;
- sec->output_section = bfd_abs_section_ptr;
- matched = TRUE;
- break;
- }
- }
- }
+ if (first != NULL
+ && elf_next_in_group (first) == first
+ && bfd_elf_match_symbols_in_sections (first, sec, info))
+ {
+ sec->output_section = bfd_abs_section_ptr;
+ sec->kept_section = first;
+ break;
+ }
}
- else
- /* Check this linkonce section against single member groups. */
- for (l = already_linked_list->entry; l != NULL; l = l->next)
- {
- if (l->linked.comdat_key == NULL)
- {
- l_sec = l->linked.u.sec;
-
- if (l_sec->flags & SEC_GROUP)
- {
- asection *first = elf_next_in_group (l_sec);
-
- if (first != NULL
- && elf_next_in_group (first) == first
- && bfd_elf_match_symbols_in_sections (first,
- sec,
- info))
- {
- sec->output_section = bfd_abs_section_ptr;
- sec->kept_section = first;
- matched = TRUE;
- break;
- }
- }
- }
- }
- /* Do not complain on unresolved relocations in `.gnu.linkonce.r.F'
- referencing its discarded `.gnu.linkonce.t.F' counterpart -
- g++-3.4 specific as g++-4.x is using COMDAT groups (without the
- `.gnu.linkonce' prefix) instead. `.gnu.linkonce.r.*' were the
- `.rodata' part of its matching `.gnu.linkonce.t.*'. If
- `.gnu.linkonce.r.F' is not discarded but its `.gnu.linkonce.t.F'
- is discarded means we chose one-only `.gnu.linkonce.t.F' section
- from a different bfd not requiring any `.gnu.linkonce.r.F'.
- Thus `.gnu.linkonce.r.F' should be discarded. The reverse order
- cannot happen as there is never a bfd with only the
- `.gnu.linkonce.r.F' section. The order of sections in a bfd
- does not matter as here were are looking only for cross-bfd
- sections. */
-
- if ((flags & SEC_GROUP) == 0
- && CONST_STRNEQ (name, ".gnu.linkonce.r."))
- for (l = already_linked_list->entry; l != NULL; l = l->next)
- {
- if (l->linked.comdat_key == NULL)
- {
- l_sec = l->linked.u.sec;
-
- if ((l_sec->flags & SEC_GROUP) == 0
- && CONST_STRNEQ (l_sec->name, ".gnu.linkonce.t."))
- {
- if (abfd != l_sec->owner)
- {
- sec->output_section = bfd_abs_section_ptr;
- matched = TRUE;
- }
- break;
- }
- }
- }
- }
+ /* Do not complain on unresolved relocations in `.gnu.linkonce.r.F'
+ referencing its discarded `.gnu.linkonce.t.F' counterpart - g++-3.4
+ specific as g++-4.x is using COMDAT groups (without the `.gnu.linkonce'
+ prefix) instead. `.gnu.linkonce.r.*' were the `.rodata' part of its
+ matching `.gnu.linkonce.t.*'. If `.gnu.linkonce.r.F' is not discarded
+ but its `.gnu.linkonce.t.F' is discarded means we chose one-only
+ `.gnu.linkonce.t.F' section from a different bfd not requiring any
+ `.gnu.linkonce.r.F'. Thus `.gnu.linkonce.r.F' should be discarded.
+ The reverse order cannot happen as there is never a bfd with only the
+ `.gnu.linkonce.r.F' section. The order of sections in a bfd does not
+ matter as here were are looking only for cross-bfd sections. */
+
+ if ((flags & SEC_GROUP) == 0 && CONST_STRNEQ (name, ".gnu.linkonce.r."))
+ for (l = already_linked_list->entry; l != NULL; l = l->next)
+ if ((l->sec->flags & SEC_GROUP) == 0
+ && CONST_STRNEQ (l->sec->name, ".gnu.linkonce.t."))
+ {
+ if (abfd != l->sec->owner)
+ sec->output_section = bfd_abs_section_ptr;
+ break;
+ }
/* This is the first section with this name. Record it. */
- if (! bfd_section_already_linked_table_insert (already_linked_list,
- linked))
+ if (!bfd_section_already_linked_table_insert (already_linked_list, sec))
info->callbacks->einfo (_("%F%P: already_linked_table: %E\n"));
- return matched;
+ return sec->output_section == bfd_abs_section_ptr;
}
bfd_boolean
Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
- 2010
+ 2010, 2011
Free Software Foundation, Inc.
Written by Cygnus Support.
#define _bfd_nolink_bfd_link_split_section \
((bfd_boolean (*) (bfd *, struct bfd_section *)) bfd_false)
#define _bfd_nolink_section_already_linked \
- ((bfd_boolean (*) (bfd *, struct already_linked*, \
+ ((bfd_boolean (*) (bfd *, asection *, \
struct bfd_link_info *)) bfd_false)
#define _bfd_nolink_bfd_define_common_symbol \
((bfd_boolean (*) (bfd *, struct bfd_link_info *, \
(bfd *, struct bfd_section *);
extern bfd_boolean _bfd_generic_section_already_linked
- (bfd *, struct already_linked *, struct bfd_link_info *);
+ (bfd *, asection *, struct bfd_link_info *);
/* Generic reloc_link_order processing routine. */
extern bfd_boolean _bfd_generic_reloc_link_order
struct bfd_section_already_linked *entry;
};
-struct already_linked
-{
- const char *comdat_key;
- union
- {
- asection *sec;
- bfd *abfd;
- } u;
-};
-
struct bfd_section_already_linked
{
struct bfd_section_already_linked *next;
- struct already_linked linked;
+ asection *sec;
};
extern struct bfd_section_already_linked_hash_entry *
bfd_section_already_linked_table_lookup (const char *);
extern bfd_boolean bfd_section_already_linked_table_insert
- (struct bfd_section_already_linked_hash_entry *, struct already_linked *);
+ (struct bfd_section_already_linked_hash_entry *, asection *);
extern void bfd_section_already_linked_table_traverse
(bfd_boolean (*) (struct bfd_section_already_linked_hash_entry *,
void *), void *);
Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
- 2010
+ 2010, 2011
Free Software Foundation, Inc.
Written by Cygnus Support.
#define _bfd_nolink_bfd_link_split_section \
((bfd_boolean (*) (bfd *, struct bfd_section *)) bfd_false)
#define _bfd_nolink_section_already_linked \
- ((bfd_boolean (*) (bfd *, struct already_linked*, \
+ ((bfd_boolean (*) (bfd *, asection *, \
struct bfd_link_info *)) bfd_false)
#define _bfd_nolink_bfd_define_common_symbol \
((bfd_boolean (*) (bfd *, struct bfd_link_info *, \
(bfd *, struct bfd_section *);
extern bfd_boolean _bfd_generic_section_already_linked
- (bfd *, struct already_linked *, struct bfd_link_info *);
+ (bfd *, asection *, struct bfd_link_info *);
/* Generic reloc_link_order processing routine. */
extern bfd_boolean _bfd_generic_reloc_link_order
struct bfd_section_already_linked *entry;
};
-struct already_linked
-{
- const char *comdat_key;
- union
- {
- asection *sec;
- bfd *abfd;
- } u;
-};
-
struct bfd_section_already_linked
{
struct bfd_section_already_linked *next;
- struct already_linked linked;
+ asection *sec;
};
extern struct bfd_section_already_linked_hash_entry *
bfd_section_already_linked_table_lookup (const char *);
extern bfd_boolean bfd_section_already_linked_table_insert
- (struct bfd_section_already_linked_hash_entry *, struct already_linked *);
+ (struct bfd_section_already_linked_hash_entry *, asection *);
extern void bfd_section_already_linked_table_traverse
(bfd_boolean (*) (struct bfd_section_already_linked_hash_entry *,
void *), void *);
(bfd *);
extern const char *_bfd_coff_internal_syment_name
(bfd *, const struct internal_syment *, char *);
+extern bfd_boolean _bfd_coff_section_already_linked
+ (bfd *, asection *, struct bfd_link_info *);
extern bfd_boolean _bfd_coff_link_add_symbols
(bfd *, struct bfd_link_info *);
extern bfd_boolean _bfd_coff_final_link
(bfd *);
extern const char *_bfd_coff_internal_syment_name
(bfd *, const struct internal_syment *, char *);
+extern bfd_boolean _bfd_coff_section_already_linked
+ (bfd *, asection *, struct bfd_link_info *);
extern bfd_boolean _bfd_coff_link_add_symbols
(bfd *, struct bfd_link_info *);
extern bfd_boolean _bfd_coff_final_link
SYNOPSIS
bfd_boolean bfd_section_already_linked (bfd *abfd,
- struct already_linked *data,
+ asection *sec,
struct bfd_link_info *info);
DESCRIPTION
Check if @var{data} has been already linked during a reloceatable
or final link. Return TRUE if it has.
-.#define bfd_section_already_linked(abfd, data, info) \
-. BFD_SEND (abfd, _section_already_linked, (abfd, data, info))
+.#define bfd_section_already_linked(abfd, sec, info) \
+. BFD_SEND (abfd, _section_already_linked, (abfd, sec, info))
.
*/
bfd_boolean
bfd_section_already_linked_table_insert
(struct bfd_section_already_linked_hash_entry *already_linked_list,
- struct already_linked *data)
+ asection *sec)
{
struct bfd_section_already_linked *l;
bfd_hash_allocate (&_bfd_section_already_linked_table, sizeof *l);
if (l == NULL)
return FALSE;
- l->linked = *data;
+ l->sec = sec;
l->next = already_linked_list->entry;
already_linked_list->entry = l;
return TRUE;
bfd_hash_table_free (&_bfd_section_already_linked_table);
}
-/* This is used on non-ELF inputs. */
+/* Report warnings as appropriate for duplicate section SEC.
+ Return FALSE if we decide to keep SEC after all. */
bfd_boolean
-_bfd_generic_section_already_linked (bfd *abfd,
- struct already_linked *linked,
- struct bfd_link_info *info)
+_bfd_handle_already_linked (asection *sec,
+ struct bfd_section_already_linked *l,
+ struct bfd_link_info *info)
{
- flagword flags;
- const char *name;
- struct bfd_section_already_linked *l;
- struct bfd_section_already_linked_hash_entry *already_linked_list;
- struct coff_comdat_info *s_comdat;
- asection *sec;
-
- name = linked->comdat_key;
- if (name)
- {
- sec = NULL;
- flags = SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
- s_comdat = NULL;
- }
- else
+ switch (sec->flags & SEC_LINK_DUPLICATES)
{
- sec = linked->u.sec;
- flags = sec->flags;
- if ((flags & SEC_LINK_ONCE) == 0)
- return FALSE;
+ default:
+ abort ();
- s_comdat = bfd_coff_get_comdat_section (abfd, sec);
+ case SEC_LINK_DUPLICATES_DISCARD:
+ /* If we found an LTO IR match for this comdat group on
+ the first pass, replace it with the LTO output on the
+ second pass. We can't simply choose real object
+ files over IR because the first pass may contain a
+ mix of LTO and normal objects and we must keep the
+ first match, be it IR or real. */
+ if (info->loading_lto_outputs
+ && (l->sec->owner->flags & BFD_PLUGIN) != 0)
+ {
+ l->sec = sec;
+ return FALSE;
+ }
+ break;
- /* FIXME: When doing a relocatable link, we may have trouble
- copying relocations in other sections that refer to local symbols
- in the section being discarded. Those relocations will have to
- be converted somehow; as of this writing I'm not sure that any of
- the backends handle that correctly.
+ case SEC_LINK_DUPLICATES_ONE_ONLY:
+ info->callbacks->einfo
+ (_("%B: ignoring duplicate section `%A'\n"),
+ sec->owner, sec);
+ break;
- It is tempting to instead not discard link once sections when
- doing a relocatable link (technically, they should be discarded
- whenever we are building constructors). However, that fails,
- because the linker winds up combining all the link once sections
- into a single large link once section, which defeats the purpose
- of having link once sections in the first place. */
+ case SEC_LINK_DUPLICATES_SAME_SIZE:
+ if ((l->sec->owner->flags & BFD_PLUGIN) != 0)
+ ;
+ else if (sec->size != l->sec->size)
+ info->callbacks->einfo
+ (_("%B: duplicate section `%A' has different size\n"),
+ sec->owner, sec);
+ break;
- name = bfd_get_section_name (abfd, sec);
+ case SEC_LINK_DUPLICATES_SAME_CONTENTS:
+ if ((l->sec->owner->flags & BFD_PLUGIN) != 0)
+ ;
+ else if (sec->size != l->sec->size)
+ info->callbacks->einfo
+ (_("%B: duplicate section `%A' has different size\n"),
+ sec->owner, sec);
+ else if (sec->size != 0)
+ {
+ bfd_byte *sec_contents, *l_sec_contents = NULL;
+
+ if (!bfd_malloc_and_get_section (sec->owner, sec, &sec_contents))
+ info->callbacks->einfo
+ (_("%B: could not read contents of section `%A'\n"),
+ sec->owner, sec);
+ else if (!bfd_malloc_and_get_section (l->sec->owner, l->sec,
+ &l_sec_contents))
+ info->callbacks->einfo
+ (_("%B: could not read contents of section `%A'\n"),
+ l->sec->owner, l->sec);
+ else if (memcmp (sec_contents, l_sec_contents, sec->size) != 0)
+ info->callbacks->einfo
+ (_("%B: duplicate section `%A' has different contents\n"),
+ sec->owner, sec);
+
+ if (sec_contents)
+ free (sec_contents);
+ if (l_sec_contents)
+ free (l_sec_contents);
+ }
+ break;
}
- already_linked_list = bfd_section_already_linked_table_lookup (name);
+ /* Set the output_section field so that lang_add_section
+ does not create a lang_input_section structure for this
+ section. Since there might be a symbol in the section
+ being discarded, we must retain a pointer to the section
+ which we are really going to use. */
+ sec->output_section = bfd_abs_section_ptr;
+ sec->kept_section = l->sec;
+ return TRUE;
+}
- for (l = already_linked_list->entry; l != NULL; l = l->next)
- {
- bfd_boolean skip = FALSE;
- bfd *l_owner;
- flagword l_flags;
- struct coff_comdat_info *l_comdat;
- asection *l_sec;
+/* This is used on non-ELF inputs. */
- if (l->linked.comdat_key)
- {
- l_sec = NULL;
- l_owner = l->linked.u.abfd;
- l_comdat = NULL;
- l_flags = SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
- }
- else
- {
- l_sec = l->linked.u.sec;
- l_owner = l_sec->owner;
- l_flags = l_sec->flags;
- l_comdat = bfd_coff_get_comdat_section (l_sec->owner, l_sec);
- }
+bfd_boolean
+_bfd_generic_section_already_linked (bfd *abfd ATTRIBUTE_UNUSED,
+ asection *sec,
+ struct bfd_link_info *info)
+{
+ const char *name;
+ struct bfd_section_already_linked *l;
+ struct bfd_section_already_linked_hash_entry *already_linked_list;
- /* We may have 3 different sections on the list: group section,
- comdat section and linkonce section. SEC may be a linkonce or
- comdat section. We always ignore group section. For non-COFF
- inputs, we also ignore comdat section.
+ if ((sec->flags & SEC_LINK_ONCE) == 0)
+ return FALSE;
- FIXME: Is that safe to match a linkonce section with a comdat
- section for COFF inputs? */
- if ((l_flags & SEC_GROUP) != 0)
- skip = TRUE;
- else if (bfd_get_flavour (abfd) == bfd_target_coff_flavour)
- {
- if (s_comdat != NULL
- && l_comdat != NULL
- && strcmp (s_comdat->name, l_comdat->name) != 0)
- skip = TRUE;
- }
- else if (l_comdat != NULL)
- skip = TRUE;
+ /* The generic linker doesn't handle section groups. */
+ if ((sec->flags & SEC_GROUP) != 0)
+ return FALSE;
- if (!skip)
- {
- /* The section has already been linked. See if we should
- issue a warning. */
- switch (flags & SEC_LINK_DUPLICATES)
- {
- default:
- abort ();
-
- case SEC_LINK_DUPLICATES_DISCARD:
- /* If we found an LTO IR match for this comdat group on
- the first pass, replace it with the LTO output on the
- second pass. We can't simply choose real object
- files over IR because the first pass may contain a
- mix of LTO and normal objects and we must keep the
- first match, be it IR or real. */
- if (info->loading_lto_outputs
- && (l_owner->flags & BFD_PLUGIN) != 0)
- {
- l->linked = *linked;
- return FALSE;
- }
- break;
+ /* FIXME: When doing a relocatable link, we may have trouble
+ copying relocations in other sections that refer to local symbols
+ in the section being discarded. Those relocations will have to
+ be converted somehow; as of this writing I'm not sure that any of
+ the backends handle that correctly.
- case SEC_LINK_DUPLICATES_ONE_ONLY:
- (*_bfd_error_handler)
- (_("%B: warning: ignoring duplicate section `%A'\n"),
- abfd, sec);
- break;
+ It is tempting to instead not discard link once sections when
+ doing a relocatable link (technically, they should be discarded
+ whenever we are building constructors). However, that fails,
+ because the linker winds up combining all the link once sections
+ into a single large link once section, which defeats the purpose
+ of having link once sections in the first place. */
- case SEC_LINK_DUPLICATES_SAME_CONTENTS:
- /* FIXME: We should really dig out the contents of both
- sections and memcmp them. The COFF/PE spec says that
- the Microsoft linker does not implement this
- correctly, so I'm not going to bother doing it
- either. */
- /* Fall through. */
- case SEC_LINK_DUPLICATES_SAME_SIZE:
- if (sec->size != l_sec->size)
- (*_bfd_error_handler)
- (_("%B: warning: duplicate section `%A' has different size\n"),
- abfd, sec);
- break;
- }
+ name = bfd_get_section_name (abfd, sec);
- if (sec)
- {
- /* Set the output_section field so that lang_add_section
- does not create a lang_input_section structure for this
- section. Since there might be a symbol in the section
- being discarded, we must retain a pointer to the section
- which we are really going to use. */
- sec->output_section = bfd_abs_section_ptr;
- sec->kept_section = l_sec;
- }
+ already_linked_list = bfd_section_already_linked_table_lookup (name);
- return TRUE;
- }
+ l = already_linked_list->entry;
+ if (l != NULL)
+ {
+ /* The section has already been linked. See if we should
+ issue a warning. */
+ return _bfd_handle_already_linked (sec, l, info);
}
/* This is the first section with this name. Record it. */
- if (! bfd_section_already_linked_table_insert (already_linked_list,
- linked))
+ if (!bfd_section_already_linked_table_insert (already_linked_list, sec))
info->callbacks->einfo (_("%F%P: already_linked_table: %E\n"));
return FALSE;
}
.
.{* Forward declaration. *}
.typedef struct bfd_link_info _bfd_link_info;
-.struct already_linked;
.
.{* Forward declaration. *}
.typedef struct flag_info flag_info;
.
. {* Check if SEC has been already linked during a reloceatable or
. final link. *}
-. bfd_boolean (*_section_already_linked) (bfd *, struct already_linked *,
+. bfd_boolean (*_section_already_linked) (bfd *, asection *,
. struct bfd_link_info *);
.
. {* Define a common symbol. *}
+2011-08-17 Alan Modra <amodra@gmail.com>
+
+ PR ld/12762
+ * ldlang.c (section_already_linked): Revert 2011-07-09 changes.
+ * plugin.c: Likewise.
+ (asymbol_from_plugin_symbol): Create linkonce section for syms
+ with comdat_key.
+
2011-08-09 Matthew Gretton-Dann <matthew.gretton-dann@arm.com>
* emultempl/armelf.em (fix_arm1176): New variable.
}
if (!(abfd->flags & DYNAMIC))
- {
- struct already_linked linked;
- linked.comdat_key = NULL;
- linked.u.sec = sec;
- bfd_section_already_linked (abfd, &linked, &link_info);
- }
+ bfd_section_already_linked (abfd, sec, &link_info);
}
\f
/* The wild routines.
#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
{
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))
/* FALLTHRU */
case LDPK_DEF:
flags |= BSF_GLOBAL;
- section = bfd_get_section_by_name (abfd, ".text");
+ if (ldsym->comdat_key)
+ {
+ char *name = concat (".gnu.linkonce.t.", ldsym->comdat_key,
+ (const char *) NULL);
+ section = bfd_get_section_by_name (abfd, name);
+ if (section != NULL)
+ free (name);
+ else
+ {
+ 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, name, sflags);
+ if (section == NULL)
+ return LDPS_ERR;
+ }
+ }
+ else
+ section = bfd_get_section_by_name (abfd, ".text");
break;
case LDPK_WEAKUNDEF:
enum ld_plugin_status rv;
asymbol *bfdsym;
- if (syms[n].comdat_key)
- {
- struct already_linked linked;
- linked.comdat_key = xstrdup (syms[n].comdat_key);
- linked.u.abfd = abfd;
- bfd_section_already_linked (abfd, &linked, &link_info);
- }
bfdsym = bfd_make_empty_symbol (abfd);
symptrs[n] = bfdsym;
rv = asymbol_from_plugin_symbol (abfd, bfdsym, syms + n);