public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: binutils@sourceware.org
Subject: PowerPC64: plt_stub_pad
Date: Tue, 28 Jun 2022 13:00:49 +0930	[thread overview]
Message-ID: <Yrp16SnESxck5KvK@squeak.grove.modra.org> (raw)

Another tidy.

	* elf64-ppc.c (plt_stub_pad): Simplify parameters and untangle
	from plt_stub_size.
	(ppc_size_one_stub): Call plt_stub_size before plt_stub_pad to
	provide size.  Recalculate size if it might change.

diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c
index 9491a0f9e66..202c941515d 100644
--- a/bfd/elf64-ppc.c
+++ b/bfd/elf64-ppc.c
@@ -11183,29 +11183,22 @@ plt_stub_size (struct ppc_link_hash_table *htab,
    boundaries if we align, then return the padding needed to do so.  */
 
 static inline unsigned int
-plt_stub_pad (struct ppc_link_hash_table *htab,
-	      struct ppc_stub_hash_entry *stub_entry,
+plt_stub_pad (int plt_stub_align,
 	      bfd_vma stub_off,
-	      bfd_vma plt_off,
-	      unsigned int odd)
+	      unsigned int stub_size)
 {
-  int stub_align;
-  unsigned stub_size;
+  unsigned int stub_align;
 
-  if (htab->params->plt_stub_align >= 0)
+  if (plt_stub_align >= 0)
+    stub_align = 1u << plt_stub_align;
+  else
     {
-      stub_align = 1 << htab->params->plt_stub_align;
-      if ((stub_off & (stub_align - 1)) != 0)
-	return stub_align - (stub_off & (stub_align - 1));
-      return 0;
+      stub_align = 1u << -plt_stub_align;
+      if (((stub_off + stub_size - 1) & -stub_align) - (stub_off & -stub_align)
+	  <= ((stub_size - 1) & -stub_align))
+	return 0;
     }
-
-  stub_align = 1 << -htab->params->plt_stub_align;
-  stub_size = plt_stub_size (htab, stub_entry, plt_off, odd);
-  if (((stub_off + stub_size - 1) & -stub_align) - (stub_off & -stub_align)
-      > ((stub_size - 1) & -stub_align))
-    return stub_align - (stub_off & (stub_align - 1));
-  return 0;
+  return stub_align - 1 - ((stub_off - 1) & (stub_align - 1));
 }
 
 /* Build a toc using .plt call stub.  */
@@ -12245,7 +12238,7 @@ ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
   struct ppc_link_hash_table *htab;
   asection *plt;
   bfd_vma targ, off, r2off;
-  unsigned int size, extra, lr_used, delta, odd;
+  unsigned int size, pad, extra, lr_used, delta, odd;
   bfd_vma stub_offset;
 
   /* Massage our args to the form they really have.  */
@@ -12504,13 +12497,14 @@ ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
       odd = off & 4;
       off = targ - off;
 
-      if (htab->params->plt_stub_align != 0)
+      size = plt_stub_size (htab, stub_entry, off, odd);
+      pad = plt_stub_pad (htab->params->plt_stub_align, stub_offset, size);
+      if (pad != 0)
 	{
-	  unsigned pad = plt_stub_pad (htab, stub_entry, stub_offset, off, odd);
-
 	  stub_offset += pad;
 	  off -= pad;
 	  odd ^= pad & 4;
+	  size = plt_stub_size (htab, stub_entry, off, odd);
 	}
 
       if (info->emitrelocations)
@@ -12524,8 +12518,6 @@ ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
 	  stub_entry->group->stub_sec->flags |= SEC_RELOC;
 	}
 
-      size = plt_stub_size (htab, stub_entry, off, odd);
-
       if (stub_entry->type.sub != ppc_stub_notoc)
 	{
 	  /* After the bcl, lr has been modified so we need to emit
@@ -12578,12 +12570,9 @@ ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
 	     + htab->sec_info[stub_entry->group->link_sec->id].toc_off);
       off = targ - off;
 
-      if (htab->params->plt_stub_align != 0)
-	{
-	  unsigned pad = plt_stub_pad (htab, stub_entry, stub_offset, off, 0);
-
-	  stub_offset += pad;
-	}
+      size = plt_stub_size (htab, stub_entry, off, 0);
+      pad = plt_stub_pad (htab->params->plt_stub_align, stub_offset, size);
+      stub_offset += pad;
 
       if (info->emitrelocations)
 	{
@@ -12596,8 +12585,6 @@ ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
 	  stub_entry->group->stub_sec->flags |= SEC_RELOC;
 	}
 
-      size = plt_stub_size (htab, stub_entry, off, 0);
-
       if (stub_entry->h != NULL
 	  && is_tls_get_addr (&stub_entry->h->elf, htab)
 	  && htab->params->tls_get_addr_opt

-- 
Alan Modra
Australia Development Lab, IBM

                 reply	other threads:[~2022-06-28  3:30 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=Yrp16SnESxck5KvK@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).