bfd: xtensa: fix shrink_dynamic_reloc_sections for export-dynamic

Message ID 20190329010507.22518-1-jcmvbkbc@gmail.com
State New
Headers show
Series
  • bfd: xtensa: fix shrink_dynamic_reloc_sections for export-dynamic
Related show

Commit Message

Max Filippov March 29, 2019, 1:05 a.m.
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-28  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/elf32-xtensa.c                                         |  3 ++-
 .../ld-xtensa/relax-undef-weak-pie-export-dynamic.d        | 14 ++++++++++++++
 ld/testsuite/ld-xtensa/xtensa.exp                          |  1 +
 3 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 ld/testsuite/ld-xtensa/relax-undef-weak-pie-export-dynamic.d

-- 
2.11.0

Comments

Max Filippov March 29, 2019, 5:40 p.m. | #1
On Thu, Mar 28, 2019 at 9:52 PM augustine.sterling@gmail.com
<augustine.sterling@gmail.com> wrote:
> On Thu, Mar 28, 2019 at 6:05 PM Max Filippov <jcmvbkbc@gmail.com> wrote:

> >

> > 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-28  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.

>

>

> Looks good.


Applied to master.

-- 
Thanks.
-- Max

Patch

diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c
index c3df3d6db756..37ea200eea74 100644
--- a/bfd/elf32-xtensa.c
+++ b/bfd/elf32-xtensa.c
@@ -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;
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
index 000000000000..e2ff601bf3c1
--- /dev/null
+++ b/ld/testsuite/ld-xtensa/relax-undef-weak-pie-export-dynamic.d
@@ -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.*
+#...
diff --git a/ld/testsuite/ld-xtensa/xtensa.exp b/ld/testsuite/ld-xtensa/xtensa.exp
index 91b23142b126..d800c647a32d 100644
--- a/ld/testsuite/ld-xtensa/xtensa.exp
+++ b/ld/testsuite/ld-xtensa/xtensa.exp
@@ -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"