This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
PATCH: Check symbol type for symbol alias
Here is a patch to add a testcase and check symbol type for symbol
alias.
H.J.
----
bfd/
2007-07-19 H.J. Lu <hongjiu.lu@intel.com>
* elflink.c (elf_link_add_object_symbols): Check symbol type
for symbol alias in a dynamic object.
ld/testsuite/
2007-07-19 H.J. Lu <hongjiu.lu@intel.com>
* ld-elf/data2.c: New.
* ld-elf/weakdef1.c: Likewise.
* ld-elf/shared.exp: Add tests for libdata2 and weakdef1.
--- binutils/bfd/elflink.c.weakdef 2007-07-19 08:12:55.000000000 -0700
+++ binutils/bfd/elflink.c 2007-07-19 10:24:57.000000000 -0700
@@ -4585,6 +4585,7 @@ elf_link_add_object_symbols (bfd *abfd,
asection *slook;
bfd_vma vlook;
long ilook;
+ int tlook;
size_t i, j, idx;
hlook = weaks;
@@ -4597,6 +4598,7 @@ elf_link_add_object_symbols (bfd *abfd,
|| hlook->root.type == bfd_link_hash_indirect);
slook = hlook->root.u.def.section;
vlook = hlook->root.u.def.value;
+ tlook = hlook->type;
ilook = -1;
i = 0;
@@ -4634,9 +4636,10 @@ elf_link_add_object_symbols (bfd *abfd,
{
h = sorted_sym_hash [i];
- /* Stop if value or section doesn't match. */
+ /* Stop if value, section or type doesn't match. */
if (h->root.u.def.value != vlook
- || h->root.u.def.section != slook)
+ || h->root.u.def.section != slook
+ || h->type != tlook)
break;
else if (h != hlook)
{
--- binutils/ld/testsuite/ld-elf/data2.c.weakdef 2007-07-19 10:22:33.000000000 -0700
+++ binutils/ld/testsuite/ld-elf/data2.c 2007-07-19 10:16:33.000000000 -0700
@@ -0,0 +1,9 @@
+int foo = 0;
+extern int foo_alias __attribute__ ((weak, alias ("foo")));
+
+void
+bar (void)
+{
+ foo = -1;
+}
+
--- binutils/ld/testsuite/ld-elf/shared.exp.weakdef 2007-07-06 13:12:26.000000000 -0700
+++ binutils/ld/testsuite/ld-elf/shared.exp 2007-07-19 10:20:15.000000000 -0700
@@ -123,6 +123,9 @@ set build_tests {
{"Build libdata1.so"
"-shared" "-fPIC"
{data1.c} {} "libdata1.so"}
+ {"Build libdata2.so"
+ "-shared" "-fPIC"
+ {data2.c} {} "libdata2.so"}
}
set run_tests {
@@ -235,6 +238,9 @@ set run_tests {
{"Run with libdata1.so"
"tmpdir/libdata1.so" ""
{dynbss1.c} "dynbss1" "pass.out"}
+ {"Run with libdata2.so"
+ "tmpdir/libdata2.so" ""
+ {weakdef1.c} "weakdef1" "pass.out"}
}
run_cc_link_tests $build_tests
--- binutils/ld/testsuite/ld-elf/weakdef1.c.weakdef 2007-07-19 10:21:52.000000000 -0700
+++ binutils/ld/testsuite/ld-elf/weakdef1.c 2007-07-19 10:21:28.000000000 -0700
@@ -0,0 +1,15 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+extern int foo_alias;
+extern void bar (void);
+
+int
+main (void)
+{
+ bar ();
+ if (foo_alias != -1)
+ abort ();
+ printf ("PASS\n");
+ return 0;
+}