Undefined weak symbols in shared libraries

Daniel Jacobowitz drow@false.org
Mon Jul 28 21:29:00 GMT 2008


I've been working on a MIPS linker bug that causes bogus dynamic
relocations for undefined weak symbols with non-default visibility.
I've had trouble with this so many times on different ports that I
wrote a non-port-specific test case.

There's a couple of problems with it though.

- The testsuite never runs C tests on cross targets.  This is an
annoying limitation for me since I mostly cross-test.  It's fixable,
but will introduce some dependencies on having a target during cross
testing that are not currently present.  Any opinions on that?  It's
somewhat orthogonal to this patch.

- The test case fails on x86_64, telling me to recompile the shared
library with -fPIC.

- The case I'm fixing is bar, but foo fails too on mips-linux.

So before I do anything with this test, I'd like to know: is there any
agreement that it should pass?

-- 
Daniel Jacobowitz
CodeSourcery

2008-07-28  Daniel Jacobowitz  <dan@codesourcery.com>

	* ld-elf/shared.exp: Add undefexec and undefweak.
	* ld-elf/undefexec.c, ld-elf/undefweak.c: New files.

Index: ld/testsuite/ld-elf/shared.exp
===================================================================
--- ld/testsuite/ld-elf/shared.exp	(revision 215799)
+++ ld/testsuite/ld-elf/shared.exp	(working copy)
@@ -123,6 +123,9 @@ set build_tests {
   {"Build libdata1.so"
    "-shared" "-fPIC"
    {data1.c} {} "libdata1.so"}
+  {"Build libundefweak.so"
+   "-shared" "-fPIC"
+   {undefweak.c} {} "libundefweak.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 libundefweak.so"
+     "tmpdir/libundefweak.so" ""
+     {undefexec.c} "undefexec" "pass.out"}
 }
 
 run_cc_link_tests $build_tests
Index: ld/testsuite/ld-elf/undefexec.c
===================================================================
--- ld/testsuite/ld-elf/undefexec.c	(revision 0)
+++ ld/testsuite/ld-elf/undefexec.c	(revision 0)
@@ -0,0 +1,15 @@
+#include <stdlib.h>
+#include <stdio.h>
+
+int *foo (void);
+int *bar (void);
+
+int main()
+{
+  if (foo () != NULL)
+    abort ();
+  if (bar () != NULL)
+    abort ();
+  printf ("PASS\n");
+  return 0;
+}
Index: ld/testsuite/ld-elf/undefweak.c
===================================================================
--- ld/testsuite/ld-elf/undefweak.c	(revision 0)
+++ ld/testsuite/ld-elf/undefweak.c	(revision 0)
@@ -0,0 +1,14 @@
+__attribute__ ((weak, visibility ("hidden"))) extern int missing_var;
+static int *ptr = &missing_var;
+
+int *
+foo (void)
+{
+  return &missing_var;
+}
+
+int *
+bar (void)
+{
+  return ptr;
+}



More information about the Binutils mailing list