aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
Diffstat (limited to 'bfd')
-rw-r--r--bfd/ChangeLog11
-rw-r--r--bfd/bfd-in2.h4
-rw-r--r--bfd/elf32-i386.c6
-rw-r--r--bfd/elf64-x86-64.c14
-rw-r--r--bfd/linker.c89
5 files changed, 114 insertions, 10 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 19723d2..c838043 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,14 @@
+2015-10-26 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR ld/19171
+ * elf32-i386.c (elf_i386_convert_load): Call
+ bfd_link_get_defined_symbol to check if a symbol is defined.
+ * elf64-x86-64.c (elf_x86_64_convert_load): Call
+ bfd_link_get_defined_symbol to get defined symbol section and
+ value.
+ * linker.c (bfd_link_get_defined_symbol): New function.
+ * bfd-in2.h: Regenerated.
+
2015-10-23 Alan Modra <amodra@gmail.com>
PR ld/11133
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index 9345e88..57d31f2 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -7515,6 +7515,10 @@ struct bfd_elf_version_tree * bfd_find_version_for_sym
bfd_boolean bfd_hide_sym_by_version
(struct bfd_elf_version_tree *verdefs, const char *sym_name);
+bfd_boolean bfd_link_get_defined_symbol
+ (struct bfd_link_info *info, struct bfd_link_hash_entry *h,
+ asection **sec, bfd_vma *value);
+
/* Extracted from simple.c. */
bfd_byte *bfd_simple_get_relocated_section_contents
(bfd *abfd, asection *sec, bfd_byte *outbuf, asymbol **symbol_table);
diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index 60cd91a..9717062 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -2753,7 +2753,7 @@ elf_i386_readonly_dynrelocs (struct elf_link_hash_entry *h, void *inf)
static bfd_boolean
elf_i386_convert_load (bfd *abfd, asection *sec,
- struct bfd_link_info *link_info)
+ struct bfd_link_info *link_info)
{
Elf_Internal_Shdr *symtab_hdr;
Elf_Internal_Rela *internal_relocs;
@@ -2976,8 +2976,8 @@ convert_branch:
if (h == htab->elf.hdynamic)
continue;
- if ((h->root.type == bfd_link_hash_defined
- || h->root.type == bfd_link_hash_defweak)
+ if (bfd_link_get_defined_symbol (link_info, &h->root, NULL,
+ NULL)
&& SYMBOL_REFERENCES_LOCAL (link_info, h))
{
convert_load:
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index f864834..9778f2f 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -3116,6 +3116,8 @@ elf_x86_64_convert_load (bfd *abfd, asection *sec,
}
else
{
+ bfd_boolean defined;
+
indx = r_symndx - symtab_hdr->sh_info;
h = elf_sym_hashes (abfd)[indx];
BFD_ASSERT (h != NULL);
@@ -3124,19 +3126,17 @@ elf_x86_64_convert_load (bfd *abfd, asection *sec,
|| h->root.type == bfd_link_hash_warning)
h = (struct elf_link_hash_entry *) h->root.u.i.link;
+ defined = bfd_link_get_defined_symbol (link_info, &h->root,
+ &tsec, &toff);
+
/* STT_GNU_IFUNC must keep GOTPCREL relocations. We also
avoid optimizing GOTPCREL relocations againt _DYNAMIC
since ld.so may use its link-time address. */
- if ((h->root.type == bfd_link_hash_defined
- || h->root.type == bfd_link_hash_defweak)
+ if (defined
&& h->type != STT_GNU_IFUNC
&& h != htab->elf.hdynamic
&& SYMBOL_REFERENCES_LOCAL (link_info, h))
- {
- tsec = h->root.u.def.section;
- toff = h->root.u.def.value;
- symtype = h->type;
- }
+ symtype = h->type;
else
continue;
}
diff --git a/bfd/linker.c b/bfd/linker.c
index 86a7a19..f2290e0 100644
--- a/bfd/linker.c
+++ b/bfd/linker.c
@@ -3303,3 +3303,92 @@ bfd_hide_sym_by_version (struct bfd_elf_version_tree *verdefs,
bfd_find_version_for_sym (verdefs, sym_name, &hidden);
return hidden;
}
+
+/*
+FUNCTION
+ bfd_link_get_defined_symbol
+
+SYNOPSIS
+ bfd_boolean bfd_link_get_defined_symbol
+ (struct bfd_link_info *info, struct bfd_link_hash_entry *h,
+ asection **sec, bfd_vma *value);
+
+DESCRIPTION
+ Return TRUE, store symbol section and value in @var{*sec} and
+ @var{*value} if symbol @var{h} is defined during a final link.
+*/
+
+bfd_boolean
+bfd_link_get_defined_symbol (struct bfd_link_info *info,
+ struct bfd_link_hash_entry *h,
+ asection **sec, bfd_vma *value)
+{
+ if (h->type == bfd_link_hash_defined
+ || h->type == bfd_link_hash_defweak)
+ {
+ if (sec)
+ *sec = h->u.def.section;
+ if (value)
+ *value = h->u.def.value;
+ return TRUE;
+ }
+
+ if (h->type == bfd_link_hash_new
+ || h->type == bfd_link_hash_undefined
+ || h->type == bfd_link_hash_undefweak)
+ {
+ /* Check yet undefined reference to __start_XXX or __stop_XXX
+ symbols. The linker will later define such symbols for output
+ sections that have a name representable as a C identifier. */
+ const char *sec_name;
+ if (strncmp (h->root.string, "__start_", 8) == 0)
+ sec_name = h->root.string + 8;
+ else if (strncmp (h->root.string, "__stop_", 7) == 0)
+ sec_name = h->root.string + 7;
+ else
+ sec_name = NULL;
+
+ if (sec_name != NULL && *sec_name != '\0')
+ {
+ bfd *i;
+
+ for (i = info->input_bfds; i != NULL; i = i->link.next)
+ {
+ asection *s = bfd_get_section_by_name (i, sec_name);
+ if (s != NULL)
+ {
+ asection *asect;
+ bfd_vma size;
+
+ if (sec)
+ *sec = s;
+
+ if (!value)
+ return TRUE;
+ if (sec_name == (h->root.string + 8))
+ {
+ /* Set __start_XXX symbol value. */
+ *value = 0;
+ return TRUE;
+ }
+
+ /* Get the size of the output XXX section for
+ __stop_XXX symbol value. */
+ size = 0;
+ for (asect = s->output_section->map_head.s;
+ asect != NULL;
+ asect = asect->map_head.s)
+ {
+ size = align_power (size, asect->alignment_power);
+ size += asect->size;
+ }
+
+ *value = size;
+ return TRUE;
+ }
+ }
+ }
+ }
+
+ return FALSE;
+}