From bf3077a6c3c9ff21c072a6f42c91bffefd35bc15 Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Wed, 31 Jan 2018 14:26:46 +0100 Subject: [PATCH] bfd_elf_define_start_stop: Fix check 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 | 5 +++++ bfd/elflink.c | 5 +++-- ld/ChangeLog | 5 +++++ ld/testsuite/ld-elf/pr21964-5.c | 26 ++++++++++++++++++++++++++ ld/testsuite/ld-elf/shared.exp | 3 +++ 5 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 ld/testsuite/ld-elf/pr21964-5.c diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 2a0330c..e71a53a 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,8 @@ +2018-01-31 Michael Matz + + * elflink.c (bfd_elf_define_start_stop): Fix check of + def_dynamic. + 2018-01-31 H.J. Lu PR ld/21964 diff --git a/bfd/elflink.c b/bfd/elflink.c index 3787c85..3fe4555 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -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; diff --git a/ld/ChangeLog b/ld/ChangeLog index 67e29b9..2042e6c 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,8 @@ +2018-01-31 Michael Matz + + * testsuite/ld-elf/pr21964-5.c: New test. + * testsuite/ld-elf/shared.exp: Run it. + 2018-01-31 H.J. Lu 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 index 0000000..56ed5a9 --- /dev/null +++ b/ld/testsuite/ld-elf/pr21964-5.c @@ -0,0 +1,26 @@ +#define _GNU_SOURCE +#include +#include +#include + +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; +} diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp index 833a428..9bc2fde 100644 --- a/ld/testsuite/ld-elf/shared.exp +++ b/ld/testsuite/ld-elf/shared.exp @@ -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. -- 2.7.4