public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] libgcc: Special-case BFD ld unwind table encodings in find_fde_tail
@ 2022-10-17  9:06 Florian Weimer
  2022-10-29  4:20 ` Jeff Law
  0 siblings, 1 reply; 2+ messages in thread
From: Florian Weimer @ 2022-10-17  9:06 UTC (permalink / raw)
  To: gcc-patches

BFD ld (and the other linkers) only produce one encoding of these
values.  It is not necessary to use the general
read_encoded_value_with_base decoding routine.  This avoids the
data-dependent branches in its implementation.

libgcc/

	* unwind-dw2-fde-dip.c (find_fde_tail): Special-case encoding
	values actually used by BFD ld.

---
 libgcc/unwind-dw2-fde-dip.c | 58 +++++++++++++++++++++++++++++++++++++--------
 1 file changed, 48 insertions(+), 10 deletions(-)

diff --git a/libgcc/unwind-dw2-fde-dip.c b/libgcc/unwind-dw2-fde-dip.c
index 7f9be5e6b02..f370c1279ae 100644
--- a/libgcc/unwind-dw2-fde-dip.c
+++ b/libgcc/unwind-dw2-fde-dip.c
@@ -396,10 +396,21 @@ find_fde_tail (_Unwind_Ptr pc,
   if (hdr->version != 1)
     return NULL;
 
-  p = read_encoded_value_with_base (hdr->eh_frame_ptr_enc,
-				    base_from_cb_data (hdr->eh_frame_ptr_enc,
-						       dbase),
-				    p, &eh_frame);
+  if (__builtin_expect (hdr->eh_frame_ptr_enc == (DW_EH_PE_sdata4
+						  | DW_EH_PE_pcrel), 1))
+    {
+      /* Specialized version of read_encoded_value_with_base, based on what
+	 BFD ld generates.  */
+      signed value __attribute__ ((mode (SI)));
+      memcpy (&value, p, sizeof (value));
+      p += sizeof (value);
+      dbase = value;		/* No adjustment because pcrel has base 0.  */
+    }
+  else
+    p = read_encoded_value_with_base (hdr->eh_frame_ptr_enc,
+				      base_from_cb_data (hdr->eh_frame_ptr_enc,
+							 dbase),
+				      p, &eh_frame);
 
   /* We require here specific table encoding to speed things up.
      Also, DW_EH_PE_datarel here means using PT_GNU_EH_FRAME start
@@ -409,10 +420,20 @@ find_fde_tail (_Unwind_Ptr pc,
     {
       _Unwind_Ptr fde_count;
 
-      p = read_encoded_value_with_base (hdr->fde_count_enc,
-					base_from_cb_data (hdr->fde_count_enc,
-							   dbase),
-					p, &fde_count);
+      if (__builtin_expect (hdr->fde_count_enc == DW_EH_PE_udata4, 1))
+	{
+	  /* Specialized version of read_encoded_value_with_base, based on
+	     what BFD ld generates.  */
+	  unsigned value __attribute__ ((mode (SI)));
+	  memcpy (&value, p, sizeof (value));
+	  p += sizeof (value);
+	  fde_count = value;
+	}
+      else
+	p = read_encoded_value_with_base (hdr->fde_count_enc,
+					  base_from_cb_data (hdr->fde_count_enc,
+							     dbase),
+					  p, &fde_count);
       /* Shouldn't happen.  */
       if (fde_count == 0)
 	return NULL;
@@ -454,8 +475,25 @@ find_fde_tail (_Unwind_Ptr pc,
 	  f = (fde *) (table[mid].fde + data_base);
 	  f_enc = get_fde_encoding (f);
 	  f_enc_size = size_of_encoded_value (f_enc);
-	  read_encoded_value_with_base (f_enc & 0x0f, 0,
-					&f->pc_begin[f_enc_size], &range);
+
+	  /* BFD ld uses DW_EH_PE_sdata4 | DW_EH_PE_pcrel on non-FDPIC targets,
+	     so optimize for that.
+
+	     This optimization is not valid for FDPIC targets.  f_enc & 0x0f as
+	     passed to read_encoded_value_with_base masks away the base flags,
+	     but they are implicit for FDPIC.  */
+#ifndef __FDPIC__
+	  if (__builtin_expect (f_enc == (DW_EH_PE_sdata4 | DW_EH_PE_pcrel),
+				1))
+	    {
+	      signed value __attribute__ ((mode (SI)));
+	      memcpy (&value, &f->pc_begin[f_enc_size], sizeof (value));
+	      range = value;
+	    }
+	  else
+#endif
+	    read_encoded_value_with_base (f_enc & 0x0f, 0,
+					  &f->pc_begin[f_enc_size], &range);
 	  _Unwind_Ptr func = table[mid].initial_loc + data_base;
 	  if (pc < table[mid].initial_loc + data_base + range)
 	    {

base-commit: de7d6310862c6045cf2dfb0ef209ff0e0923e648


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] libgcc: Special-case BFD ld unwind table encodings in find_fde_tail
  2022-10-17  9:06 [PATCH] libgcc: Special-case BFD ld unwind table encodings in find_fde_tail Florian Weimer
@ 2022-10-29  4:20 ` Jeff Law
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2022-10-29  4:20 UTC (permalink / raw)
  To: Florian Weimer, gcc-patches


On 10/17/22 03:06, Florian Weimer via Gcc-patches wrote:
> BFD ld (and the other linkers) only produce one encoding of these
> values.  It is not necessary to use the general
> read_encoded_value_with_base decoding routine.  This avoids the
> data-dependent branches in its implementation.
>
> libgcc/
>
> 	* unwind-dw2-fde-dip.c (find_fde_tail): Special-case encoding
> 	values actually used by BFD ld.

OK.

jeff



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-10-29  4:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-17  9:06 [PATCH] libgcc: Special-case BFD ld unwind table encodings in find_fde_tail Florian Weimer
2022-10-29  4:20 ` Jeff Law

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