public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] x86-64: restrict PC32 -> PLT32 conversion
@ 2022-01-05 11:14 Jan Beulich
  2022-01-05 14:54 ` H.J. Lu
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Beulich @ 2022-01-05 11:14 UTC (permalink / raw)
  To: Binutils

Neither non-64-bit code nor uses with a non-zero offset from a symbol
should be converted to PLT32, as an eventual PLT entry would not express
what was requested.

--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -8857,6 +8857,8 @@ output_branch (void)
       off = 0;
     }
 
+  frag_now->tc_frag_data.code64 = flag_code == CODE_64BIT;
+
   /* 1 possible extra opcode + 4 byte displacement go in var part.
      Pass reloc in fr_var.  */
   frag_var (rs_machine_dependent, 5, i.reloc[0], subtype, sym, off, p);
@@ -8985,8 +8987,8 @@ output_jump (void)
     }
 
 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
-  if (size == 4
-      && jump_reloc == NO_RELOC
+  if (flag_code == CODE_64BIT && size == 4
+      && jump_reloc == NO_RELOC && i.op[0].disps->X_add_number == 0
       && need_plt32_p (i.op[0].disps->X_add_symbol))
     jump_reloc = BFD_RELOC_X86_64_PLT32;
 #endif
@@ -12289,7 +12291,8 @@ md_estimate_size_before_relax (fragS *fr
       else if (size == 2)
 	reloc_type = BFD_RELOC_16_PCREL;
 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
-      else if (need_plt32_p (fragP->fr_symbol))
+      else if (fragP->tc_frag_data.code64 && fragP->fr_offset == 0
+	       && need_plt32_p (fragP->fr_symbol))
 	reloc_type = BFD_RELOC_X86_64_PLT32;
 #endif
       else
--- a/gas/config/tc-i386.h
+++ b/gas/config/tc-i386.h
@@ -283,6 +283,7 @@ struct i386_tc_frag_data
   unsigned int mf_type : 3;
   unsigned int classified : 1;
   unsigned int branch_type : 3;
+  unsigned int code64 : 1; /* Only set by output_branch for now.  */
 };
 
 /* We need to emit the right NOP pattern in .align frags.  This is


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

* Re: [PATCH] x86-64: restrict PC32 -> PLT32 conversion
  2022-01-05 11:14 [PATCH] x86-64: restrict PC32 -> PLT32 conversion Jan Beulich
@ 2022-01-05 14:54 ` H.J. Lu
  0 siblings, 0 replies; 2+ messages in thread
From: H.J. Lu @ 2022-01-05 14:54 UTC (permalink / raw)
  To: Jan Beulich; +Cc: Binutils

On Wed, Jan 5, 2022 at 3:14 AM Jan Beulich <jbeulich@suse.com> wrote:
>
> Neither non-64-bit code nor uses with a non-zero offset from a symbol
> should be converted to PLT32, as an eventual PLT entry would not express
> what was requested.
>
> --- a/gas/config/tc-i386.c
> +++ b/gas/config/tc-i386.c
> @@ -8857,6 +8857,8 @@ output_branch (void)
>        off = 0;
>      }
>
> +  frag_now->tc_frag_data.code64 = flag_code == CODE_64BIT;
> +
>    /* 1 possible extra opcode + 4 byte displacement go in var part.
>       Pass reloc in fr_var.  */
>    frag_var (rs_machine_dependent, 5, i.reloc[0], subtype, sym, off, p);
> @@ -8985,8 +8987,8 @@ output_jump (void)
>      }
>
>  #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
> -  if (size == 4
> -      && jump_reloc == NO_RELOC
> +  if (flag_code == CODE_64BIT && size == 4
> +      && jump_reloc == NO_RELOC && i.op[0].disps->X_add_number == 0
>        && need_plt32_p (i.op[0].disps->X_add_symbol))
>      jump_reloc = BFD_RELOC_X86_64_PLT32;
>  #endif
> @@ -12289,7 +12291,8 @@ md_estimate_size_before_relax (fragS *fr
>        else if (size == 2)
>         reloc_type = BFD_RELOC_16_PCREL;
>  #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
> -      else if (need_plt32_p (fragP->fr_symbol))
> +      else if (fragP->tc_frag_data.code64 && fragP->fr_offset == 0
> +              && need_plt32_p (fragP->fr_symbol))
>         reloc_type = BFD_RELOC_X86_64_PLT32;
>  #endif
>        else
> --- a/gas/config/tc-i386.h
> +++ b/gas/config/tc-i386.h
> @@ -283,6 +283,7 @@ struct i386_tc_frag_data
>    unsigned int mf_type : 3;
>    unsigned int classified : 1;
>    unsigned int branch_type : 3;
> +  unsigned int code64 : 1; /* Only set by output_branch for now.  */
>  };
>
>  /* We need to emit the right NOP pattern in .align frags.  This is
>

OK.

Thanks.

-- 
H.J.

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

end of thread, other threads:[~2022-01-05 14:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-05 11:14 [PATCH] x86-64: restrict PC32 -> PLT32 conversion Jan Beulich
2022-01-05 14:54 ` H.J. Lu

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