From e1b5d517d1c293a64df311d2749bbbbfbe035a4c Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Wed, 10 Jun 2020 05:31:19 -0700 Subject: [PATCH] ELF: Properly handle section symbols When defining the section symbol, __start_FOO, for the section FOO: 1. Treat the common symbol, __start_FOO, in input object file as definition. 2. Clear verinfo.verdef. bfd/ PR ld/26094 * elflink.c (bfd_elf_define_start_stop): Handle common symbols. Clear verinfo.verdef. ld/ PR ld/26094 * testsuite/ld-elf/pr26094-1.ver: New fike. * testsuite/ld-elf/pr26094-1a.c: Likewise. * testsuite/ld-elf/pr26094-1a.rd: Likewise. * testsuite/ld-elf/pr26094-1b.c: Likewise. * testsuite/ld-elf/pr26094-1b.rd: Likewise. * testsuite/ld-elf/pr26094-1c.c: Likewise. * testsuite/ld-elf/shared.exp: Run ld/26094 tests. --- bfd/ChangeLog | 6 ++++++ bfd/elflink.c | 6 +++++- ld/ChangeLog | 11 +++++++++++ ld/testsuite/ld-elf/pr26094-1.ver | 3 +++ ld/testsuite/ld-elf/pr26094-1a.c | 7 +++++++ ld/testsuite/ld-elf/pr26094-1a.rd | 8 ++++++++ ld/testsuite/ld-elf/pr26094-1b.c | 6 ++++++ ld/testsuite/ld-elf/pr26094-1b.rd | 8 ++++++++ ld/testsuite/ld-elf/pr26094-1c.c | 7 +++++++ ld/testsuite/ld-elf/shared.exp | 19 +++++++++++++++++++ 10 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 ld/testsuite/ld-elf/pr26094-1.ver create mode 100644 ld/testsuite/ld-elf/pr26094-1a.c create mode 100644 ld/testsuite/ld-elf/pr26094-1a.rd create mode 100644 ld/testsuite/ld-elf/pr26094-1b.c create mode 100644 ld/testsuite/ld-elf/pr26094-1b.rd create mode 100644 ld/testsuite/ld-elf/pr26094-1c.c diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 8f9e69c6c71..928d4bddaf4 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2020-06-10 H.J. Lu + + PR ld/26094 + * elflink.c (bfd_elf_define_start_stop): Handle common symbols. + Clear verinfo.verdef. + 2020-06-09 H.J. Lu PR ld/18801 diff --git a/bfd/elflink.c b/bfd/elflink.c index 60a3c2216f3..3e56a297f69 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -14802,12 +14802,16 @@ bfd_elf_define_start_stop (struct bfd_link_info *info, h = elf_link_hash_lookup (elf_hash_table (info), symbol, FALSE, FALSE, TRUE); + /* NB: Common symbols will be turned into definition later. */ if (h != NULL && (h->root.type == bfd_link_hash_undefined || h->root.type == bfd_link_hash_undefweak - || ((h->ref_regular || h->def_dynamic) && !h->def_regular))) + || ((h->ref_regular || h->def_dynamic) + && !h->def_regular + && h->root.type != bfd_link_hash_common))) { bfd_boolean was_dynamic = h->ref_dynamic || h->def_dynamic; + h->verinfo.verdef = NULL; h->root.type = bfd_link_hash_defined; h->root.u.def.section = sec; h->root.u.def.value = 0; diff --git a/ld/ChangeLog b/ld/ChangeLog index ba4151ee833..74636bbb7c8 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,14 @@ +2020-06-10 H.J. Lu + + PR ld/26094 + * testsuite/ld-elf/pr26094-1.ver: New fike. + * testsuite/ld-elf/pr26094-1a.c: Likewise. + * testsuite/ld-elf/pr26094-1a.rd: Likewise. + * testsuite/ld-elf/pr26094-1b.c: Likewise. + * testsuite/ld-elf/pr26094-1b.rd: Likewise. + * testsuite/ld-elf/pr26094-1c.c: Likewise. + * testsuite/ld-elf/shared.exp: Run ld/26094 tests. + 2020-06-09 H.J. Lu PR ld/18801 diff --git a/ld/testsuite/ld-elf/pr26094-1.ver b/ld/testsuite/ld-elf/pr26094-1.ver new file mode 100644 index 00000000000..eda3854d75a --- /dev/null +++ b/ld/testsuite/ld-elf/pr26094-1.ver @@ -0,0 +1,3 @@ +SOME_VERSION_NAME { + global: *; +}; diff --git a/ld/testsuite/ld-elf/pr26094-1a.c b/ld/testsuite/ld-elf/pr26094-1a.c new file mode 100644 index 00000000000..7a802159c44 --- /dev/null +++ b/ld/testsuite/ld-elf/pr26094-1a.c @@ -0,0 +1,7 @@ +char foo_data __attribute__(( section("FOO") )) = { 0 }; + +extern void * __start_FOO; + +void * foo() { + return __start_FOO; +} diff --git a/ld/testsuite/ld-elf/pr26094-1a.rd b/ld/testsuite/ld-elf/pr26094-1a.rd new file mode 100644 index 00000000000..0e7bdde29fb --- /dev/null +++ b/ld/testsuite/ld-elf/pr26094-1a.rd @@ -0,0 +1,8 @@ +#ld: -shared +#readelf: --dyn-syms --wide +#target: *-*-linux* *-*-gnu* arm*-*-uclinuxfdpiceabi +#xfail: ![check_shared_lib_support] + +#... + +[0-9]+: +[0-9a-f]+ +[0-9a-f]+ +NOTYPE +GLOBAL +PROTECTED +[0-9]+ +___?start_FOO@@SOME_VERSION_NAME +#pass diff --git a/ld/testsuite/ld-elf/pr26094-1b.c b/ld/testsuite/ld-elf/pr26094-1b.c new file mode 100644 index 00000000000..650a36fd893 --- /dev/null +++ b/ld/testsuite/ld-elf/pr26094-1b.c @@ -0,0 +1,6 @@ +extern void *foo(); + +void main() +{ + foo(); +} \ No newline at end of file diff --git a/ld/testsuite/ld-elf/pr26094-1b.rd b/ld/testsuite/ld-elf/pr26094-1b.rd new file mode 100644 index 00000000000..ec0c13d83c3 --- /dev/null +++ b/ld/testsuite/ld-elf/pr26094-1b.rd @@ -0,0 +1,8 @@ +#ld: +#readelf: --dyn-syms --wide +#target: *-*-linux* *-*-gnu* arm*-*-uclinuxfdpiceabi +#xfail: ![check_shared_lib_support] + +#... + +[0-9]+: +[0-9a-f]+ +[0-9a-f]+ +OBJECT +GLOBAL +PROTECTED +[0-9]+ +___?start_FOO@@SOME_VERSION_NAME +#pass diff --git a/ld/testsuite/ld-elf/pr26094-1c.c b/ld/testsuite/ld-elf/pr26094-1c.c new file mode 100644 index 00000000000..782f4932f97 --- /dev/null +++ b/ld/testsuite/ld-elf/pr26094-1c.c @@ -0,0 +1,7 @@ +char foo_data __attribute__(( section("FOO") )) = { 0 }; + +void * __start_FOO; + +void * foo() { + return __start_FOO; +} diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp index b1e1f62d50e..9d72cad78d6 100644 --- a/ld/testsuite/ld-elf/shared.exp +++ b/ld/testsuite/ld-elf/shared.exp @@ -832,6 +832,25 @@ append build_tests { run_cc_link_tests $build_tests +run_cc_link_tests [list \ + [list \ + "Build pr26094-1.so" \ + "-shared -Wl,--version-script=pr26094-1.ver" \ + "-fPIC" \ + {pr26094-1a.c} \ + {{readelf {--dyn-syms --wide} pr26094-1a.rd}} \ + "pr26094-1.so" \ + ] \ + [list \ + "Build pr26094-1" \ + "-Wl,--no-as-needed tmpdir/pr26094-1.so" \ + "-fcommon" \ + {pr26094-1b.c pr26094-1c.c} \ + {{readelf {--dyn-syms --wide} pr26094-1b.rd}} \ + "pr26094-1" \ + ] \ +] + run_ld_link_tests [list \ [list \ "pr22269-1 (static pie undefined weak)" \ -- 2.30.2