Properly check undefined symbols when gc_sections is active.
authorH.J. Lu <hjl.tools@gmail.com>
Tue, 26 Jan 2010 13:21:36 +0000 (13:21 +0000)
committerH.J. Lu <hjl.tools@gmail.com>
Tue, 26 Jan 2010 13:21:36 +0000 (13:21 +0000)
bfd/

2010-01-26  Alan Modra  <amodra@gmail.com>
    H.J. Lu  <hongjiu.lu@intel.com>

PR ld/11218
* elflink.c (elf_link_output_extsym): Do not ignore undefined
symbols with ref_regular set when gc_sections is active.

ld/testsuite/

2010-01-26  H.J. Lu  <hongjiu.lu@intel.com>

PR ld/11218
* ld-gc/dummy.s: New.
* ld-gc/pr11218-1.c: Likewise.
* ld-gc/pr11218-2.c: Likewise.
* ld-gc/pr11218.d: Likewise.

bfd/ChangeLog
bfd/elflink.c
ld/testsuite/ChangeLog
ld/testsuite/ld-gc/dummy.s [new file with mode: 0644]
ld/testsuite/ld-gc/gc.exp
ld/testsuite/ld-gc/pr11218-1.c [new file with mode: 0644]
ld/testsuite/ld-gc/pr11218-2.c [new file with mode: 0644]
ld/testsuite/ld-gc/pr11218.d [new file with mode: 0644]

index c9c2d3acad9b976011f54e056c0ba70e5feb1965..75118cb68152dad2aa05dcc8b203c2a2f362e191 100644 (file)
@@ -1,3 +1,10 @@
+2010-01-26  Alan Modra  <amodra@gmail.com>
+           H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/11218
+       * elflink.c (elf_link_output_extsym): Do not ignore undefined
+       symbols with ref_regular set when gc_sections is active.
+
 2010-01-25  Alan Modra  <amodra@gmail.com>
 
        PR ld/11217
index 6576252a774becd7be6460ee01baf832a2e4cb41..cca2d53ff7a6e1e557442cdb3e4610862e80853e 100644 (file)
@@ -8579,7 +8579,9 @@ elf_link_output_extsym (struct elf_link_hash_entry *h, void *data)
     {
       /* If we have an undefined symbol reference here then it must have
         come from a shared library that is being linked in.  (Undefined
-        references in regular files have already been handled).  */
+        references in regular files have already been handled unless
+        they are in unreferenced sections which are removed by garbage
+        collection).  */
       bfd_boolean ignore_undef = FALSE;
 
       /* Some symbols may be special in that the fact that they're
@@ -8590,12 +8592,13 @@ elf_link_output_extsym (struct elf_link_hash_entry *h, void *data)
       /* If we are reporting errors for this situation then do so now.  */
       if (ignore_undef == FALSE
          && h->ref_dynamic
-         && ! h->ref_regular
+         && (!h->ref_regular || finfo->info->gc_sections)
          && ! elf_link_check_versioned_symbol (finfo->info, bed, h)
          && finfo->info->unresolved_syms_in_shared_libs != RM_IGNORE)
        {
          if (! (finfo->info->callbacks->undefined_symbol
-                (finfo->info, h->root.root.string, h->root.u.undef.abfd,
+                (finfo->info, h->root.root.string,
+                 h->ref_regular ? NULL : h->root.u.undef.abfd,
                  NULL, 0, finfo->info->unresolved_syms_in_shared_libs == RM_GENERATE_ERROR)))
            {
              eoinfo->failed = TRUE;
index 3a2dc34bb1606fcb13f2edaa46c5602dd643f603..224aa939efb6abc399b68a7324fa1330bbc89cd6 100644 (file)
@@ -1,3 +1,11 @@
+2010-01-26  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/11218
+       * ld-gc/dummy.s: New.
+       * ld-gc/pr11218-1.c: Likewise.
+       * ld-gc/pr11218-2.c: Likewise.
+       * ld-gc/pr11218.d: Likewise.
+
 2010-01-23  Richard Sandiford  <r.sandiford@uk.ibm.com>
 
        * ld-powerpc/aix-ref-1-32.od, ld-powerpc/aix-ref-1-64.od,
diff --git a/ld/testsuite/ld-gc/dummy.s b/ld/testsuite/ld-gc/dummy.s
new file mode 100644 (file)
index 0000000..403f980
--- /dev/null
@@ -0,0 +1 @@
+# Dummy
index c271a3d25457e0b042f9ed8ba7b613ebadefa03f..700544289c648b3c2cc7d965a920d0334bfba03d 100644 (file)
@@ -92,3 +92,11 @@ test_gc "Check --gc-section/-r/-u" "gcrel" $ld "-r --gc-sections -u used_func"
 run_dump_test "noent"
 run_dump_test "abi-note"
 run_dump_test "start"
+if { [is_remote host] || [which $CC] != 0 } {
+    if { [istarget "*-*-linux*"] } {
+       ld_compile "$CC -fPIC $CFLAGS $cflags" $srcdir/$subdir/pr11218-1.c tmpdir/pr11218-1.o
+       ld_simple_link $ld tmpdir/pr11218-1.so "-shared tmpdir/pr11218-1.o"
+       ld_compile "$CC -c $CFLAGS $cflags" $srcdir/$subdir/pr11218-2.c tmpdir/pr11218-2.o
+       run_dump_test "pr11218"
+    }
+}
diff --git a/ld/testsuite/ld-gc/pr11218-1.c b/ld/testsuite/ld-gc/pr11218-1.c
new file mode 100644 (file)
index 0000000..9cc79f0
--- /dev/null
@@ -0,0 +1,5 @@
+extern void unresolved_detected_at_runtime_not_at_linktime(void);
+void foo_in_so(void)
+{
+   unresolved_detected_at_runtime_not_at_linktime();
+}
diff --git a/ld/testsuite/ld-gc/pr11218-2.c b/ld/testsuite/ld-gc/pr11218-2.c
new file mode 100644 (file)
index 0000000..2515bc6
--- /dev/null
@@ -0,0 +1,13 @@
+extern void foo_in_so(void);
+
+void call_unresolved(void)
+{
+   unresolved_detected_at_runtime_not_at_linktime();
+}
+
+int main(int argc, char *argv[])
+{
+   foo_in_so();
+
+   return 0;
+}
diff --git a/ld/testsuite/ld-gc/pr11218.d b/ld/testsuite/ld-gc/pr11218.d
new file mode 100644 (file)
index 0000000..27019a8
--- /dev/null
@@ -0,0 +1,5 @@
+# name: --gc-sections with shared library
+# source: dummy.s
+# ld: --gc-sections -e main tmpdir/pr11218-2.o tmpdir/pr11218-1.so
+# target: *-*-linux*
+# error: undefined reference to `unresolved_detected_at_runtime_not_at_linktime'
This page took 0.0342 seconds and 4 git commands to generate.