public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: binutils@sourceware.org
Subject: nds32, sh, kvx: DT_JMPREL/DT_PLTRELSZ
Date: Thu, 24 Aug 2023 15:52:56 +0930	[thread overview]
Message-ID: <ZOb3QNjRWbzhqk6o@squeak.grove.modra.org> (raw)

As commit fa4f2d46f9 did for x86, there a few other targets that
wrongly use the output section rather than the dynamic section for
DT_JMPREL and others.

	* elfnn-kvx.c (elfNN_kvx_finish_dynamic_sections): Use input
	section for DT_JMPREL.
	* elf32-sh.c (sh_elf_finish_dynamic_sections): Use input
	section for DT_JMPREL and DT_PLTRELSZ.
	* elf32-nds32.c (nds32_elf_finish_dynamic_sections): Likewise,
	and for DT_PLTGOT and when adjusting DT_RELA.

diff --git a/bfd/elf32-nds32.c b/bfd/elf32-nds32.c
index f8e24cbc6ef..ac9106a55d4 100644
--- a/bfd/elf32-nds32.c
+++ b/bfd/elf32-nds32.c
@@ -6385,18 +6385,18 @@ nds32_elf_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
 
 	    case DT_PLTGOT:
 	      /* name = ".got";  */
-	      s = ehtab->sgot->output_section;
+	      s = ehtab->sgot;
 	      goto get_vma;
 	    case DT_JMPREL:
-	      s = ehtab->srelplt->output_section;
+	      s = ehtab->srelplt;
 	    get_vma:
 	      BFD_ASSERT (s != NULL);
-	      dyn.d_un.d_ptr = s->vma;
+	      dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
 	      bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
 	      break;
 
 	    case DT_PLTRELSZ:
-	      s = ehtab->srelplt->output_section;
+	      s = ehtab->srelplt;
 	      BFD_ASSERT (s != NULL);
 	      dyn.d_un.d_val = s->size;
 	      bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
@@ -6414,7 +6414,7 @@ nds32_elf_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
 		 about changing the DT_RELA entry.  */
 	      if (ehtab->srelplt != NULL)
 		{
-		  s = ehtab->srelplt->output_section;
+		  s = ehtab->srelplt;
 		  dyn.d_un.d_val -= s->size;
 		}
 	      bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
diff --git a/bfd/elf32-sh.c b/bfd/elf32-sh.c
index cba3529e2a5..817efb58454 100644
--- a/bfd/elf32-sh.c
+++ b/bfd/elf32-sh.c
@@ -6291,15 +6291,13 @@ sh_elf_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
 	      break;
 
 	    case DT_JMPREL:
-	      s = htab->root.srelplt->output_section;
-	      BFD_ASSERT (s != NULL);
-	      dyn.d_un.d_ptr = s->vma;
+	      s = htab->root.srelplt;
+	      dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
 	      bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
 	      break;
 
 	    case DT_PLTRELSZ:
-	      s = htab->root.srelplt->output_section;
-	      BFD_ASSERT (s != NULL);
+	      s = htab->root.srelplt;
 	      dyn.d_un.d_val = s->size;
 	      bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
 	      break;
diff --git a/bfd/elfnn-kvx.c b/bfd/elfnn-kvx.c
index 95580d19930..2dc6ae603ac 100644
--- a/bfd/elfnn-kvx.c
+++ b/bfd/elfnn-kvx.c
@@ -4589,7 +4589,8 @@ elfNN_kvx_finish_dynamic_sections (bfd *output_bfd,
 	      break;
 
 	    case DT_JMPREL:
-	      dyn.d_un.d_ptr = htab->root.srelplt->output_section->vma;
+	      s = htab->root.srelplt;
+	      dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
 	      break;
 
 	    case DT_PLTRELSZ:

-- 
Alan Modra
Australia Development Lab, IBM

                 reply	other threads:[~2023-08-24  6:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZOb3QNjRWbzhqk6o@squeak.grove.modra.org \
    --to=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).