bfd: xtensa: fix shrink_dynamic_reloc_sections for export-dynamic
authorMax Filippov <jcmvbkbc@gmail.com>
Fri, 29 Mar 2019 00:03:57 +0000 (17:03 -0700)
committerMax Filippov <jcmvbkbc@gmail.com>
Fri, 29 Mar 2019 17:02:10 +0000 (10:02 -0700)
shrink_dynamic_reloc_sections must remove PLT entry that was created for
an undefined weak symbol in the presence of --export-dynamic option when
relaxation coalesces literals pointing to that symbol. This fixes the
following assertion:

  ld: BFD (GNU Binutils) 2.31.1 internal error, aborting at
  elf32-xtensa.c:3292 in elf_xtensa_finish_dynamic_sections

2019-03-29  Max Filippov  <jcmvbkbc@gmail.com>
bfd/
* elf32-xtensa.c (shrink_dynamic_reloc_sections): Add
info->export_dynamic to the conditional.

ld/
* testsuite/ld-xtensa/relax-undef-weak-pie-export-dynamic.d: New
test definition.
* testsuite/ld-xtensa/xtensa.exp
(relax-undef-weak-pie-export-dynamic): Add new test.

bfd/ChangeLog
bfd/elf32-xtensa.c
ld/ChangeLog
ld/testsuite/ld-xtensa/relax-undef-weak-pie-export-dynamic.d [new file with mode: 0644]
ld/testsuite/ld-xtensa/xtensa.exp

index 4dd3f27a31d935273613325360bc9a787414954c..6662b708c16c4c2a71aec2a5f1c38b238eace950 100644 (file)
@@ -1,3 +1,8 @@
+2019-03-29  Max Filippov  <jcmvbkbc@gmail.com>
+
+       * elf32-xtensa.c (shrink_dynamic_reloc_sections): Add
+       info->export_dynamic to the conditional.
+
 2019-03-28  Alan Modra  <amodra@gmail.com>
 
        PR 24392
index c3df3d6db756eaeafb49bfb7a1439b73d77162b2..37ea200eea74f5c3b8bcd4d11b0eed99e0ffed97 100644 (file)
@@ -10083,7 +10083,8 @@ shrink_dynamic_reloc_sections (struct bfd_link_info *info,
       && (input_section->flags & SEC_ALLOC) != 0
       && (dynamic_symbol || bfd_link_pic (info))
       && (!h || h->root.type != bfd_link_hash_undefweak
-         || (dynamic_symbol && bfd_link_dll (info))))
+         || (dynamic_symbol
+             && (bfd_link_dll (info) || info->export_dynamic))))
     {
       asection *srel;
       bfd_boolean is_plt = FALSE;
index da1e8e1b179d0adacf4f430a36263371f47fdbd0..b987a13edb745782d1e643c25ef47766bcc43f78 100644 (file)
@@ -1,3 +1,10 @@
+2019-03-29  Max Filippov  <jcmvbkbc@gmail.com>
+
+       * testsuite/ld-xtensa/relax-undef-weak-pie-export-dynamic.d: New
+       test definition.
+       * testsuite/ld-xtensa/xtensa.exp
+       (relax-undef-weak-pie-export-dynamic): Add new test.
+
 2019-03-26  Martin Liska  <mliska@suse.cz>
 
        * plugin.c (get_symbols): Add lto_kind_str, lto_resolution_str,
diff --git a/ld/testsuite/ld-xtensa/relax-undef-weak-pie-export-dynamic.d b/ld/testsuite/ld-xtensa/relax-undef-weak-pie-export-dynamic.d
new file mode 100644 (file)
index 0000000..e2ff601
--- /dev/null
@@ -0,0 +1,14 @@
+#source: relax-undef-weak.s
+#ld: -pie --export-dynamic
+#readelf: -r
+#...
+Relocation section '\.rela\.dyn' .* 3 .*
+#...
+.*R_XTENSA_RTLD.*
+.*R_XTENSA_RTLD.*
+.*R_XTENSA_GLOB_DAT.*fd.*
+#...
+Relocation section '\.rela\.plt' .* 1 .*
+#...
+.*R_XTENSA_JMP_SLOT.*fd.*
+#...
index 91b23142b126dac7244813b16fbc0038a2e4f669..d800c647a32d08438587acce380fed16ae7c2b1d 100644 (file)
@@ -34,6 +34,7 @@ run_dump_test "relax-static-shared"
 run_dump_test "relax-static-local-shared"
 
 run_dump_test "relax-undef-weak-pie"
+run_dump_test "relax-undef-weak-pie-export-dynamic"
 run_dump_test "relax-undef-weak-local-pie"
 run_dump_test "relax-undef-weak-shared"
 run_dump_test "relax-undef-weak-local-shared"