bfd_elf_define_start_stop: Fix check
authorMichael Matz <matz@suse.de>
Wed, 31 Jan 2018 13:26:46 +0000 (14:26 +0100)
committerMichael Matz <matz@suse.de>
Wed, 31 Jan 2018 13:37:32 +0000 (14:37 +0100)
We really need to check for a dynamic def, not only a ref.
See added testcase.

bfd/
* elflink.c (bfd_elf_define_start_stop): Fix check of
def_dynamic.

ld/
* testsuite/ld-elf/pr21964-5.c: New test.
* testsuite/ld-elf/shared.exp: Run it.

bfd/ChangeLog
bfd/elflink.c
ld/ChangeLog
ld/testsuite/ld-elf/pr21964-5.c [new file with mode: 0644]
ld/testsuite/ld-elf/shared.exp

index 2a0330c8a8f7abc7310a4cddcbcde0b02f777941..e71a53a32081487afe84dabad404472c38d34892 100644 (file)
@@ -1,3 +1,8 @@
+2018-01-31  Michael Matz  <matz@suse.de>
+
+       * elflink.c (bfd_elf_define_start_stop): Fix check of
+       def_dynamic.
+
 2018-01-31  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/21964
index 3787c85e49d74073ad3adf67b0cacbbabb516e9c..3fe4555230ad4160aba37e988255163e3cc13a2a 100644 (file)
@@ -14338,8 +14338,9 @@ bfd_elf_define_start_stop (struct bfd_link_info *info,
   if (h != NULL
       && (h->root.type == bfd_link_hash_undefined
          || h->root.type == bfd_link_hash_undefweak
-         || ((h->ref_regular || h->ref_dynamic) && !h->def_regular)))
+         || ((h->ref_regular || h->def_dynamic) && !h->def_regular)))
     {
+      bfd_boolean was_dynamic = h->ref_dynamic || h->def_dynamic;
       h->root.type = bfd_link_hash_defined;
       h->root.u.def.section = sec;
       h->root.u.def.value = 0;
@@ -14358,7 +14359,7 @@ bfd_elf_define_start_stop (struct bfd_link_info *info,
        {
          if (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
            h->other = (h->other & ~ELF_ST_VISIBILITY (-1)) | STV_PROTECTED;
-         if (h->ref_dynamic)
+         if (was_dynamic)
            bfd_elf_link_record_dynamic_symbol (info, h);
        }
       return &h->root;
index 67e29b9653a6686af6262fe3aa4046580a249dbe..2042e6c0031fc036fd13ac5488addabb61b260e8 100644 (file)
@@ -1,3 +1,8 @@
+2018-01-31  Michael Matz  <matz@suse.de>
+
+       * testsuite/ld-elf/pr21964-5.c: New test.
+       * testsuite/ld-elf/shared.exp: Run it.
+
 2018-01-31  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/21964
diff --git a/ld/testsuite/ld-elf/pr21964-5.c b/ld/testsuite/ld-elf/pr21964-5.c
new file mode 100644 (file)
index 0000000..56ed5a9
--- /dev/null
@@ -0,0 +1,26 @@
+#define _GNU_SOURCE
+#include <stdlib.h>
+#include <stdio.h>
+#include <dlfcn.h>
+
+extern int foo (void);
+
+extern int __start___verbose[];
+extern int __stop___verbose[];
+int bar (void)
+{
+  static int my_var __attribute__((section("__verbose"))) = 6;
+  int *ptr;
+  ptr = (int*) dlsym(RTLD_DEFAULT, "__start___verbose");
+  if (!ptr || *ptr != 6)
+    return -1;
+  return 0;
+}
+
+int main()
+{
+  if (bar () == 0)
+    printf ("PASS\n");
+
+  return 0;
+}
index 833a4280551c29706c53f68f113452553bf4f878..9bc2fde17f0567f8422db665e7261fa9b2a56007 100644 (file)
@@ -772,6 +772,9 @@ set dlopen_run_tests [list \
     [list "Run pr21964-2" \
      "-Wl,--no-as-needed,-rpath,tmpdir tmpdir/pr21964-2a.so $extralibs" "" \
      {pr21964-2c.c} "pr21964-2" "pass.out" ] \
+    [list "Run pr21964-5" \
+     "-Wl,--no-as-needed,-rpath,tmpdir tmpdir/pr21964-1a.so $extralibs" "" \
+     {pr21964-5.c} "pr21964-5" "pass.out" ] \
 ]
 
 # Only run them when libdl is available.