From d4d8aee345704f7c39ebe9910cc08386708637b1 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Wed, 3 Jun 2020 09:25:51 -0700 Subject: [PATCH] nios2: Call _bfd_elf_maybe_set_textrel to set DF_TEXTREL Call _bfd_elf_maybe_set_textrel to set DF_TEXTREL by scanning dynamic relocations in read-only section. PR ld/26066 * elf32-nios2.c (nios2_elf32_size_dynamic_sections): Call _bfd_elf_maybe_set_textrel to set DF_TEXTREL. --- bfd/ChangeLog | 6 ++++++ bfd/elf32-nios2.c | 25 +++++++++++++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 08f8a50eede..c9f46d6d67d 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2020-06-03 H.J. Lu + + PR ld/26066 + * elf32-nios2.c (nios2_elf32_size_dynamic_sections): Call + _bfd_elf_maybe_set_textrel to set DF_TEXTREL. + 2020-06-03 H.J. Lu PR ld/26066 diff --git a/bfd/elf32-nios2.c b/bfd/elf32-nios2.c index 453b7cf5a3d..71200da9b57 100644 --- a/bfd/elf32-nios2.c +++ b/bfd/elf32-nios2.c @@ -5761,8 +5761,6 @@ nios2_elf32_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, { srel = elf_section_data (p->sec)->sreloc; srel->size += p->count * sizeof (Elf32_External_Rela); - if ((p->sec->output_section->flags & SEC_READONLY) != 0) - info->flags |= DF_TEXTREL; } } } @@ -5911,17 +5909,24 @@ nios2_elf32_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, || !add_dynamic_entry (DT_JMPREL, 0))) return FALSE; - if (relocs - && (!add_dynamic_entry (DT_RELA, 0) + if (relocs) + { + if (!add_dynamic_entry (DT_RELA, 0) || !add_dynamic_entry (DT_RELASZ, 0) - || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))) - return FALSE; + || !add_dynamic_entry (DT_RELAENT, + sizeof (Elf32_External_Rela))) + return FALSE; - if (!bfd_link_pic (info) && !add_dynamic_entry (DT_NIOS2_GP, 0)) - return FALSE; + if ((info->flags & DF_TEXTREL) == 0) + elf_link_hash_traverse (&htab->root, + _bfd_elf_maybe_set_textrel, info); - if ((info->flags & DF_TEXTREL) != 0 - && !add_dynamic_entry (DT_TEXTREL, 0)) + if ((info->flags & DF_TEXTREL) != 0 + && !add_dynamic_entry (DT_TEXTREL, 0)) + return FALSE; + } + + if (!bfd_link_pic (info) && !add_dynamic_entry (DT_NIOS2_GP, 0)) return FALSE; } #undef add_dynamic_entry -- 2.30.2