From 36b8fda5d614cb5aaf701a92befa9919bd0b195a Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Mon, 29 Jan 2018 21:45:09 +1030 Subject: [PATCH] Make __start/__stop symbols dynamic and add testcase bfd/ * elflink.c (bfd_elf_define_start_stop): Make __start and __stop symbols dynamic. ld/ * testsuite/ld-elf/pr21964-3a.c: New file. * testsuite/ld-elf/pr21964-3c.c: New file. * testsuite/ld-elf/shared.exp: Run new __start/__stop testcase. --- bfd/ChangeLog | 5 +++++ bfd/elflink.c | 9 +++++++-- ld/ChangeLog | 6 ++++++ ld/testsuite/ld-elf/pr21964-3a.c | 11 +++++++++++ ld/testsuite/ld-elf/pr21964-3c.c | 17 +++++++++++++++++ ld/testsuite/ld-elf/shared.exp | 6 ++++++ 6 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 ld/testsuite/ld-elf/pr21964-3a.c create mode 100644 ld/testsuite/ld-elf/pr21964-3c.c diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 95661980211..4a45b55859e 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,8 @@ +2018-01-30 Alan Modra + + * elflink.c (bfd_elf_define_start_stop): Make __start and __stop + symbols dynamic. + 2018-01-29 Alan Modra PR 22741 diff --git a/bfd/elflink.c b/bfd/elflink.c index e81f6c6d820..f1ec880f987 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -14354,8 +14354,13 @@ bfd_elf_define_start_stop (struct bfd_link_info *info, bed = get_elf_backend_data (info->output_bfd); (*bed->elf_backend_hide_symbol) (info, h, TRUE); } - else if (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) - h->other = (h->other & ~ELF_ST_VISIBILITY (-1)) | STV_PROTECTED; + else + { + if (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) + h->other = (h->other & ~ELF_ST_VISIBILITY (-1)) | STV_PROTECTED; + if (h->ref_dynamic || h->def_dynamic) + bfd_elf_link_record_dynamic_symbol (info, h); + } return &h->root; } return NULL; diff --git a/ld/ChangeLog b/ld/ChangeLog index c14c479de69..a90dcb8b96d 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,9 @@ +2018-01-29 Alan Modra + + * testsuite/ld-elf/pr21964-3a.c: New file. + * testsuite/ld-elf/pr21964-3c.c: New file. + * testsuite/ld-elf/shared.exp: Run new __start/__stop testcase. + 2018-01-29 Eric Botcazou * testsuite/ld-elf/shared.exp (AFLAGS_PIC): Define on SPARC. diff --git a/ld/testsuite/ld-elf/pr21964-3a.c b/ld/testsuite/ld-elf/pr21964-3a.c new file mode 100644 index 00000000000..835040ee342 --- /dev/null +++ b/ld/testsuite/ld-elf/pr21964-3a.c @@ -0,0 +1,11 @@ +extern int __start___verbose[]; +extern int __stop___verbose[]; +int +foo3 (void) +{ + if (__start___verbose == __stop___verbose + || __start___verbose[0] != 6) + return -1; + else + return 0; +} diff --git a/ld/testsuite/ld-elf/pr21964-3c.c b/ld/testsuite/ld-elf/pr21964-3c.c new file mode 100644 index 00000000000..5b750d153e4 --- /dev/null +++ b/ld/testsuite/ld-elf/pr21964-3c.c @@ -0,0 +1,17 @@ +#include + +extern int foo1 (void); +extern int foo2 (void); +extern int foo3 (void); + +static int my_var __attribute__((used, section("__verbose"))) = 6; + +int +main () +{ + if (foo1 () == 0 + && foo2 () == 0 + && foo3 () == 0) + printf ("PASS\n"); + return 0; +} diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp index 9b9cbaadfd6..3dfcef2e62c 100644 --- a/ld/testsuite/ld-elf/shared.exp +++ b/ld/testsuite/ld-elf/shared.exp @@ -569,6 +569,9 @@ set build_tests { {"Build pr21964-2b.so" "-shared" "-fPIC" {pr21964-2b.c} {} "pr21964-2b.so"} + {"Build pr21964-3a.so" + "-shared" "-fPIC" + {pr21964-3a.c} {} "pr21964-3a.so"} {"Dump pr21978.so" "-shared" "-fPIC -g -O2" {pr21978a.c pr21978b.c} {{objdump {-Sl} pr21978.od}} "pr21978.so"} @@ -705,6 +708,9 @@ set run_tests [list \ [list "Run pr21964-1" \ "-Wl,--no-as-needed,-rpath,tmpdir tmpdir/pr21964-1a.so tmpdir/pr21964-1b.so" "" \ {pr21964-1c.c} "pr21964-1" "pass.out" ] \ + [list "Run pr21964-3" \ + "-Wl,--no-as-needed,-rpath,tmpdir tmpdir/pr21964-1a.so tmpdir/pr21964-1b.so tmpdir/pr21964-3a.so" "" \ + {pr21964-3c.c} "pr21964-3" "pass.out" ] \ ] # NetBSD ELF systems do not currently support the .*_array sections. -- 2.30.2