aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2009-01-02 19:29:38 +0000
committerH.J. Lu <hjl.tools@gmail.com>2009-01-02 19:29:38 +0000
commit54ac0771d70dc2db461671bb5e1cd00852278de9 (patch)
treef42c1523fa7eca4e044306ceca32c80f193377d0
parentd88805311b781c162446afb8d31c2bb854b024cc (diff)
downloadgdb-54ac0771d70dc2db461671bb5e1cd00852278de9.zip
gdb-54ac0771d70dc2db461671bb5e1cd00852278de9.tar.gz
gdb-54ac0771d70dc2db461671bb5e1cd00852278de9.tar.bz2
bfd/
2009-01-02 H.J. Lu <hongjiu.lu@intel.com> PR ld/9679 * elflink.c (elf_merge_st_other): New. (_bfd_elf_merge_symbol): Use it on skipped weak definitions and hide them if needed. (elf_link_add_object_symbols): Updated. ld/testsuite/ 2009-01-02 H.J. Lu <hongjiu.lu@intel.com> PR ld/9679 * ld-elf/pr9679-1.c: New. * ld-elf/pr9679-2.c: Likewise. * ld-elf/pr9679.rd: Likewise. * ld-elf/shared.exp (build_tests): Add test for libpr9679.so.
-rw-r--r--bfd/ChangeLog8
-rw-r--r--bfd/elflink.c103
-rw-r--r--ld/testsuite/ChangeLog9
-rw-r--r--ld/testsuite/ld-elf/pr9679-1.c5
-rw-r--r--ld/testsuite/ld-elf/pr9679-2.c13
-rw-r--r--ld/testsuite/ld-elf/pr9679.rd5
-rw-r--r--ld/testsuite/ld-elf/shared.exp3
7 files changed, 109 insertions, 37 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index a896f01..79fb7b2 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,5 +1,13 @@
2009-01-02 H.J. Lu <hongjiu.lu@intel.com>
+ PR ld/9679
+ * elflink.c (elf_merge_st_other): New.
+ (_bfd_elf_merge_symbol): Use it on skipped weak definitions and
+ hide them if needed.
+ (elf_link_add_object_symbols): Updated.
+
+2009-01-02 H.J. Lu <hongjiu.lu@intel.com>
+
PR ld/9676
* elflink.c (elf_link_add_object_symbols): Update def_dynamic,
ref_dynamic and dynamic_def fields when setting def_regular
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 2b246bd..95d1219 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -822,6 +822,54 @@ _bfd_elf_link_renumber_dynsyms (bfd *output_bfd,
return dynsymcount;
}
+/* Merge st_other field. */
+
+static void
+elf_merge_st_other (bfd *abfd, struct elf_link_hash_entry *h,
+ Elf_Internal_Sym *isym, bfd_boolean definition,
+ bfd_boolean dynamic)
+{
+ const struct elf_backend_data *bed = get_elf_backend_data (abfd);
+
+ /* If st_other has a processor-specific meaning, specific
+ code might be needed here. We never merge the visibility
+ attribute with the one from a dynamic object. */
+ if (bed->elf_backend_merge_symbol_attribute)
+ (*bed->elf_backend_merge_symbol_attribute) (h, isym, definition,
+ dynamic);
+
+ /* If this symbol has default visibility and the user has requested
+ we not re-export it, then mark it as hidden. */
+ if (definition
+ && !dynamic
+ && (abfd->no_export
+ || (abfd->my_archive && abfd->my_archive->no_export))
+ && ELF_ST_VISIBILITY (isym->st_other) != STV_INTERNAL)
+ isym->st_other = (STV_HIDDEN
+ | (isym->st_other & ~ELF_ST_VISIBILITY (-1)));
+
+ if (!dynamic && ELF_ST_VISIBILITY (isym->st_other) != 0)
+ {
+ unsigned char hvis, symvis, other, nvis;
+
+ /* Only merge the visibility. Leave the remainder of the
+ st_other field to elf_backend_merge_symbol_attribute. */
+ other = h->other & ~ELF_ST_VISIBILITY (-1);
+
+ /* Combine visibilities, using the most constraining one. */
+ hvis = ELF_ST_VISIBILITY (h->other);
+ symvis = ELF_ST_VISIBILITY (isym->st_other);
+ if (! hvis)
+ nvis = symvis;
+ else if (! symvis)
+ nvis = hvis;
+ else
+ nvis = hvis < symvis ? hvis : symvis;
+
+ h->other = other | nvis;
+ }
+}
+
/* This function is called when we want to define a new symbol. It
handles the various cases which arise when we find a definition in
a dynamic object, or when there is already a definition in a
@@ -1347,7 +1395,22 @@ _bfd_elf_merge_symbol (bfd *abfd,
/* Skip weak definitions of symbols that are already defined. */
if (newdef && olddef && newweak)
- *skip = TRUE;
+ {
+ *skip = TRUE;
+
+ /* Merge st_other. If the symbol already has a dynamic index,
+ but visibility says it should not be visible, turn it into a
+ local symbol. */
+ elf_merge_st_other (abfd, h, sym, newdef, newdyn);
+ if (h->dynindx != -1)
+ switch (ELF_ST_VISIBILITY (h->other))
+ {
+ case STV_INTERNAL:
+ case STV_HIDDEN:
+ (*bed->elf_backend_hide_symbol) (info, h, TRUE);
+ break;
+ }
+ }
/* If the old symbol is from a dynamic object, and the new symbol is
a definition which is not from a dynamic object, then the new
@@ -4244,42 +4307,8 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
h->type = ELF_ST_TYPE (isym->st_info);
}
- /* If st_other has a processor-specific meaning, specific
- code might be needed here. We never merge the visibility
- attribute with the one from a dynamic object. */
- if (bed->elf_backend_merge_symbol_attribute)
- (*bed->elf_backend_merge_symbol_attribute) (h, isym, definition,
- dynamic);
-
- /* If this symbol has default visibility and the user has requested
- we not re-export it, then mark it as hidden. */
- if (definition && !dynamic
- && (abfd->no_export
- || (abfd->my_archive && abfd->my_archive->no_export))
- && ELF_ST_VISIBILITY (isym->st_other) != STV_INTERNAL)
- isym->st_other = (STV_HIDDEN
- | (isym->st_other & ~ELF_ST_VISIBILITY (-1)));
-
- if (ELF_ST_VISIBILITY (isym->st_other) != 0 && !dynamic)
- {
- unsigned char hvis, symvis, other, nvis;
-
- /* Only merge the visibility. Leave the remainder of the
- st_other field to elf_backend_merge_symbol_attribute. */
- other = h->other & ~ELF_ST_VISIBILITY (-1);
-
- /* Combine visibilities, using the most constraining one. */
- hvis = ELF_ST_VISIBILITY (h->other);
- symvis = ELF_ST_VISIBILITY (isym->st_other);
- if (! hvis)
- nvis = symvis;
- else if (! symvis)
- nvis = hvis;
- else
- nvis = hvis < symvis ? hvis : symvis;
-
- h->other = other | nvis;
- }
+ /* Merge st_other field. */
+ elf_merge_st_other (abfd, h, isym, definition, dynamic);
/* Set a flag in the hash table entry indicating the type of
reference or definition we just found. Keep a count of
diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
index 7936368..30be1ed 100644
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -1,5 +1,14 @@
2009-01-02 H.J. Lu <hongjiu.lu@intel.com>
+ PR ld/9679
+ * ld-elf/pr9679-1.c: New.
+ * ld-elf/pr9679-2.c: Likewise.
+ * ld-elf/pr9679.rd: Likewise.
+
+ * ld-elf/shared.exp (build_tests): Add test for libpr9679.so.
+
+2009-01-02 H.J. Lu <hongjiu.lu@intel.com>
+
PR ld/9676
* ld-elf/pr9676-1.c: New.
* ld-elf/pr9676-2.c: Likewiswe.
diff --git a/ld/testsuite/ld-elf/pr9679-1.c b/ld/testsuite/ld-elf/pr9679-1.c
new file mode 100644
index 0000000..cf7abbb
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr9679-1.c
@@ -0,0 +1,5 @@
+int
+foo (void)
+{
+ return 1;
+}
diff --git a/ld/testsuite/ld-elf/pr9679-2.c b/ld/testsuite/ld-elf/pr9679-2.c
new file mode 100644
index 0000000..e125a6b
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr9679-2.c
@@ -0,0 +1,13 @@
+extern int foo (void) __attribute__((weak,__visibility__ ("hidden")));
+
+int
+foo (void)
+{
+ return 1;
+}
+
+int
+bar (void)
+{
+ return foo ();
+}
diff --git a/ld/testsuite/ld-elf/pr9679.rd b/ld/testsuite/ld-elf/pr9679.rd
new file mode 100644
index 0000000..0585b1c
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr9679.rd
@@ -0,0 +1,5 @@
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+#...
+ +[0-9]+: +[0-9a-f]+ +[0-9a-f]+ +FUNC +LOCAL +HIDDEN +[0-9]+ +foo
+#...
diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp
index ff8bc8f..4f45bdd 100644
--- a/ld/testsuite/ld-elf/shared.exp
+++ b/ld/testsuite/ld-elf/shared.exp
@@ -145,6 +145,9 @@ set build_tests {
"-shared tmpdir/pr9676-4.o -Ltmpdir -lpr9676-3 -Wl,--start-group -lpr9676-1 -lpr9676-2 -Wl,--end-group"
"-fPIC"
{dummy.c} {{readelf {-s} pr9676.rd}} "libpr9676-4a.so"}
+ {"Build libpr9679.so"
+ "-shared" "-fPIC -O0"
+ {pr9679-1.c pr9679-2.c} {{readelf {-s} pr9679.rd}} "libpr9679.so"}
}
set run_tests {