X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=bfd%2Felflink.c;h=f9f804de739dcf0ffefbd18cac767f036bc50222;hb=bde6f3eb6dff94cea1d471e15c6154d55d49820f;hp=65bba873cf6a8a93864e00addd4e1b972c8261b6;hpb=3703bab932d537a9a7136e0d4cf1985bc2249259;p=deliverable%2Fbinutils-gdb.git diff --git a/bfd/elflink.c b/bfd/elflink.c index 65bba873cf..f9f804de73 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -1,6 +1,6 @@ /* ELF linking support for BFD. Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, - 2005, 2006, 2007, 2008, 2009 + 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. This file is part of BFD, the Binary File Descriptor library. @@ -185,7 +185,7 @@ bfd_boolean _bfd_elf_link_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) { flagword flags; - register asection *s; + asection *s; const struct elf_backend_data *bed; if (! is_elf_hash_table (info->hash)) @@ -570,8 +570,7 @@ bfd_elf_record_link_assignment (bfd *output_bfd, if (provide && hidden) { - const struct elf_backend_data *bed = get_elf_backend_data (output_bfd); - + bed = get_elf_backend_data (output_bfd); h->other = (h->other & ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN; (*bed->elf_backend_hide_symbol) (info, h, TRUE); } @@ -1184,9 +1183,8 @@ _bfd_elf_merge_symbol (bfd *abfd, was referenced before. */ if (h->ref_regular) { - const struct elf_backend_data *bed - = get_elf_backend_data (abfd); struct elf_link_hash_entry *vh = *sym_hash; + vh->root.type = h->root.type; h->root.type = bfd_link_hash_indirect; (*bed->elf_backend_copy_indirect_symbol) (info, vh, h); @@ -1548,7 +1546,6 @@ _bfd_elf_merge_symbol (bfd *abfd, /* Handle the case where we had a versioned symbol in a dynamic library and now find a definition in a normal object. In this case, we make the versioned symbol point to the normal one. */ - const struct elf_backend_data *bed = get_elf_backend_data (abfd); flip->root.type = h->root.type; flip->root.u.undef.abfd = h->root.u.undef.abfd; h->root.type = bfd_link_hash_indirect; @@ -3877,6 +3874,7 @@ error_free_dyn: bfd_boolean common; unsigned int old_alignment; bfd *old_bfd; + bfd * undef_bfd = NULL; override = FALSE; @@ -4108,6 +4106,20 @@ error_free_dyn: name = newname; } + /* If this is a definition of a previously undefined symbol + make a note of the bfd that contained the reference in + case we need to refer to it later on in error messages. */ + if (! bfd_is_und_section (sec)) + { + h = elf_link_hash_lookup (elf_hash_table (info), name, FALSE, FALSE, FALSE); + + if (h != NULL + && (h->root.type == bfd_link_hash_undefined + || h->root.type == bfd_link_hash_undefweak) + && h->root.u.undef.abfd) + undef_bfd = h->root.u.undef.abfd; + } + if (!_bfd_elf_merge_symbol (abfd, info, name, isym, &sec, &value, &old_alignment, sym_hash, &skip, &override, @@ -4447,9 +4459,12 @@ error_free_dyn: if ((elf_dyn_lib_class (abfd) & DYN_NO_NEEDED) != 0) { (*_bfd_error_handler) - (_("%B: invalid DSO for symbol `%s' definition"), + (_("%B: undefined reference to symbol '%s'"), + undef_bfd == NULL ? info->output_bfd : undef_bfd, name); + (*_bfd_error_handler) + (_("note: '%s' is defined in DSO %B so try adding it to the linker command line"), abfd, name); - bfd_set_error (bfd_error_bad_value); + bfd_set_error (bfd_error_invalid_operation); goto error_free_vers; } @@ -8621,9 +8636,11 @@ elf_link_output_extsym (struct elf_link_hash_entry *h, void *data) strip = FALSE; /* If we're stripping it, and it's not a dynamic symbol, there's - nothing else to do unless it is a forced local symbol. */ + nothing else to do unless it is a forced local symbol or a + STT_GNU_IFUNC symbol. */ if (strip && h->dynindx == -1 + && h->type != STT_GNU_IFUNC && !h->forced_local) return TRUE; @@ -10091,9 +10108,9 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info) bfd_boolean emit_relocs; bfd *dynobj; struct elf_final_link_info finfo; - register asection *o; - register struct bfd_link_order *p; - register bfd *sub; + asection *o; + struct bfd_link_order *p; + bfd *sub; bfd_size_type max_contents_size; bfd_size_type max_external_reloc_size; bfd_size_type max_internal_reloc_count; @@ -10542,9 +10559,10 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info) if (size == 0 && (sec->flags & SEC_HAS_CONTENTS) == 0) { - struct bfd_link_order *o = sec->map_tail.link_order; - if (o != NULL) - size = o->offset + o->size; + struct bfd_link_order *ord = sec->map_tail.link_order; + + if (ord != NULL) + size = ord->offset + ord->size; } end = sec->vma + size; } @@ -11313,6 +11331,8 @@ _bfd_elf_gc_mark_hook (asection *sec, struct elf_link_hash_entry *h, Elf_Internal_Sym *sym) { + const char *sec_name; + if (h != NULL) { switch (h->root.type) @@ -11324,6 +11344,33 @@ _bfd_elf_gc_mark_hook (asection *sec, case bfd_link_hash_common: return h->root.u.c.p->section; + case bfd_link_hash_undefined: + case bfd_link_hash_undefweak: + /* To work around a glibc bug, keep all XXX input sections + when there is an as yet undefined reference to __start_XXX + or __stop_XXX symbols. The linker will later define such + symbols for orphan input sections that have a name + representable as a C identifier. */ + if (strncmp (h->root.root.string, "__start_", 8) == 0) + sec_name = h->root.root.string + 8; + else if (strncmp (h->root.root.string, "__stop_", 7) == 0) + sec_name = h->root.root.string + 7; + else + sec_name = NULL; + + if (sec_name && *sec_name != '\0') + { + bfd *i; + + for (i = info->input_bfds; i; i = i->link_next) + { + sec = bfd_get_section_by_name (i, sec_name); + if (sec) + sec->flags |= SEC_KEEP; + } + } + break; + default: break; } @@ -11509,9 +11556,10 @@ elf_gc_sweep (bfd *abfd, struct bfd_link_info *info) o->gc_mark = first->gc_mark; } else if ((o->flags & (SEC_DEBUGGING | SEC_LINKER_CREATED)) != 0 - || (o->flags & (SEC_ALLOC | SEC_LOAD | SEC_RELOC)) == 0) + || (o->flags & (SEC_ALLOC | SEC_LOAD | SEC_RELOC)) == 0 + || elf_section_data (o)->this_hdr.sh_type == SHT_NOTE) { - /* Keep debug and special sections. */ + /* Keep debug, special and SHT_NOTE sections. */ o->gc_mark = 1; } @@ -12576,3 +12624,15 @@ _bfd_elf_make_dynamic_reloc_section (asection * sec, return reloc_sec; } + +/* Copy the ELF symbol type associated with a linker hash entry. */ +void +_bfd_elf_copy_link_hash_symbol_type (bfd *abfd ATTRIBUTE_UNUSED, + struct bfd_link_hash_entry * hdest, + struct bfd_link_hash_entry * hsrc) +{ + struct elf_link_hash_entry *ehdest = (struct elf_link_hash_entry *)hdest; + struct elf_link_hash_entry *ehsrc = (struct elf_link_hash_entry *)hsrc; + + ehdest->type = ehsrc->type; +}