public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] x86: Use ud2 assembly mnemonic when available.
@ 2014-02-13 23:47 Roland McGrath
  2014-02-13 23:51 ` Andrew Pinski
  0 siblings, 1 reply; 6+ messages in thread
From: Roland McGrath @ 2014-02-13 23:47 UTC (permalink / raw)
  To: gcc-patches

Non-ancient assemblers support the "ud2" mnemonic, so there is no need
to emit the literal opcode as data.

OK for trunk and 4.8?


Thanks,
Roland


gcc/
2014-02-13  Roland McGrath  <mcgrathr@google.com>

	* configure.ac (HAVE_AS_IX86_UD2): New test for 'ud2' mnemonic.
	* configure: Regenerated.
	* config.in: Regenerated.
	* config/i386/i386.md (trap) [HAVE_AS_IX86_UD2]: Use the mnemonic
	instead of ASM_SHORT.

--- a/gcc/config.in
+++ b/gcc/config.in
@@ -375,6 +375,12 @@
 #endif


+/* Define if your assembler supports the 'ud2' mnemonic. */
+#ifndef USED_FOR_TARGET
+#undef HAVE_AS_IX86_UD2
+#endif
+
+
 /* Define if your assembler supports the lituse_jsrdirect relocation. */
 #ifndef USED_FOR_TARGET
 #undef HAVE_AS_JSRDIRECT_RELOCS
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -17843,7 +17843,13 @@
 (define_insn "trap"
   [(trap_if (const_int 1) (const_int 6))]
   ""
-  { return ASM_SHORT "0x0b0f"; }
+{
+#ifdef HAVE_AS_IX86_UD2
+  return "ud2";
+#else
+  return ASM_SHORT "0x0b0f";
+#endif
+}
   [(set_attr "length" "2")])

 (define_expand "prefetch"
--- a/gcc/configure
+++ b/gcc/configure
@@ -25109,6 +25109,37 @@ $as_echo "#define
HAVE_AS_IX86_REP_LOCK_PREFIX 1" >>confdefs.h

 fi

+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for
ud2 mnemonic" >&5
+$as_echo_n "checking assembler for ud2 mnemonic... " >&6; }
+if test "${gcc_cv_as_ix86_ud2+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  gcc_cv_as_ix86_ud2=no
+  if test x$gcc_cv_as != x; then
+    $as_echo 'ud2' > conftest.s
+    if { ac_try='$gcc_cv_as $gcc_cv_as_flags  -o conftest.o conftest.s >&5'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }
+    then
+	gcc_cv_as_ix86_ud2=yes
+    else
+      echo "configure: failed program was" >&5
+      cat conftest.s >&5
+    fi
+    rm -f conftest.o conftest.s
+  fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_as_ix86_ud2" >&5
+$as_echo "$gcc_cv_as_ix86_ud2" >&6; }
+if test $gcc_cv_as_ix86_ud2 = yes; then
+
+$as_echo "#define HAVE_AS_IX86_UD2 1" >>confdefs.h
+
+fi
+
     { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for
R_386_TLS_GD_PLT reloc" >&5
 $as_echo_n "checking assembler for R_386_TLS_GD_PLT reloc... " >&6; }
 if test "${gcc_cv_as_ix86_tlsgdplt+set}" = set; then :
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -3895,6 +3895,12 @@ foo:	nop
         [AC_DEFINE(HAVE_AS_IX86_REP_LOCK_PREFIX, 1,
           [Define if the assembler supports 'rep <insn>, lock <insn>'.])])

+    gcc_GAS_CHECK_FEATURE([ud2 mnemonic],
+	gcc_cv_as_ix86_ud2,,,
+	[ud2],,
+      [AC_DEFINE(HAVE_AS_IX86_UD2, 1,
+	[Define if your assembler supports the 'ud2' mnemonic.])])
+
     gcc_GAS_CHECK_FEATURE([R_386_TLS_GD_PLT reloc],
         gcc_cv_as_ix86_tlsgdplt,,,
 	[call    tls_gd@tlsgdplt],

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

* Re: [PATCH] x86: Use ud2 assembly mnemonic when available.
  2014-02-13 23:47 [PATCH] x86: Use ud2 assembly mnemonic when available Roland McGrath
@ 2014-02-13 23:51 ` Andrew Pinski
  2014-02-13 23:52   ` Andrew Pinski
  0 siblings, 1 reply; 6+ messages in thread
From: Andrew Pinski @ 2014-02-13 23:51 UTC (permalink / raw)
  To: Roland McGrath; +Cc: gcc-patches

On Thu, Feb 13, 2014 at 3:46 PM, Roland McGrath <mcgrathr@google.com> wrote:
> Non-ancient assemblers support the "ud2" mnemonic, so there is no need
> to emit the literal opcode as data.
>
> OK for trunk and 4.8?

I changed this to use .word due to openbsd3.1:
http://gcc.gnu.org/ml/gcc-patches/2005-07/msg01347.html .  I no longer
have access to this older openbsd box so I don't object to this
change.  In fact I doubt we support any binutils that are pre 2.0 any
more; so maybe move over unconditionally to ud.

Thanks,
Andrew Pinski

>
>
> Thanks,
> Roland
>
>
> gcc/
> 2014-02-13  Roland McGrath  <mcgrathr@google.com>
>
>         * configure.ac (HAVE_AS_IX86_UD2): New test for 'ud2' mnemonic.
>         * configure: Regenerated.
>         * config.in: Regenerated.
>         * config/i386/i386.md (trap) [HAVE_AS_IX86_UD2]: Use the mnemonic
>         instead of ASM_SHORT.
>
> --- a/gcc/config.in
> +++ b/gcc/config.in
> @@ -375,6 +375,12 @@
>  #endif
>
>
> +/* Define if your assembler supports the 'ud2' mnemonic. */
> +#ifndef USED_FOR_TARGET
> +#undef HAVE_AS_IX86_UD2
> +#endif
> +
> +
>  /* Define if your assembler supports the lituse_jsrdirect relocation. */
>  #ifndef USED_FOR_TARGET
>  #undef HAVE_AS_JSRDIRECT_RELOCS
> --- a/gcc/config/i386/i386.md
> +++ b/gcc/config/i386/i386.md
> @@ -17843,7 +17843,13 @@
>  (define_insn "trap"
>    [(trap_if (const_int 1) (const_int 6))]
>    ""
> -  { return ASM_SHORT "0x0b0f"; }
> +{
> +#ifdef HAVE_AS_IX86_UD2
> +  return "ud2";
> +#else
> +  return ASM_SHORT "0x0b0f";
> +#endif
> +}
>    [(set_attr "length" "2")])
>
>  (define_expand "prefetch"
> --- a/gcc/configure
> +++ b/gcc/configure
> @@ -25109,6 +25109,37 @@ $as_echo "#define
> HAVE_AS_IX86_REP_LOCK_PREFIX 1" >>confdefs.h
>
>  fi
>
> +    { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for
> ud2 mnemonic" >&5
> +$as_echo_n "checking assembler for ud2 mnemonic... " >&6; }
> +if test "${gcc_cv_as_ix86_ud2+set}" = set; then :
> +  $as_echo_n "(cached) " >&6
> +else
> +  gcc_cv_as_ix86_ud2=no
> +  if test x$gcc_cv_as != x; then
> +    $as_echo 'ud2' > conftest.s
> +    if { ac_try='$gcc_cv_as $gcc_cv_as_flags  -o conftest.o conftest.s >&5'
> +  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
> +  (eval $ac_try) 2>&5
> +  ac_status=$?
> +  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
> +  test $ac_status = 0; }; }
> +    then
> +       gcc_cv_as_ix86_ud2=yes
> +    else
> +      echo "configure: failed program was" >&5
> +      cat conftest.s >&5
> +    fi
> +    rm -f conftest.o conftest.s
> +  fi
> +fi
> +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_as_ix86_ud2" >&5
> +$as_echo "$gcc_cv_as_ix86_ud2" >&6; }
> +if test $gcc_cv_as_ix86_ud2 = yes; then
> +
> +$as_echo "#define HAVE_AS_IX86_UD2 1" >>confdefs.h
> +
> +fi
> +
>      { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for
> R_386_TLS_GD_PLT reloc" >&5
>  $as_echo_n "checking assembler for R_386_TLS_GD_PLT reloc... " >&6; }
>  if test "${gcc_cv_as_ix86_tlsgdplt+set}" = set; then :
> --- a/gcc/configure.ac
> +++ b/gcc/configure.ac
> @@ -3895,6 +3895,12 @@ foo:     nop
>          [AC_DEFINE(HAVE_AS_IX86_REP_LOCK_PREFIX, 1,
>            [Define if the assembler supports 'rep <insn>, lock <insn>'.])])
>
> +    gcc_GAS_CHECK_FEATURE([ud2 mnemonic],
> +       gcc_cv_as_ix86_ud2,,,
> +       [ud2],,
> +      [AC_DEFINE(HAVE_AS_IX86_UD2, 1,
> +       [Define if your assembler supports the 'ud2' mnemonic.])])
> +
>      gcc_GAS_CHECK_FEATURE([R_386_TLS_GD_PLT reloc],
>          gcc_cv_as_ix86_tlsgdplt,,,
>         [call    tls_gd@tlsgdplt],

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

* Re: [PATCH] x86: Use ud2 assembly mnemonic when available.
  2014-02-13 23:51 ` Andrew Pinski
@ 2014-02-13 23:52   ` Andrew Pinski
  2014-02-13 23:57     ` Roland McGrath
  0 siblings, 1 reply; 6+ messages in thread
From: Andrew Pinski @ 2014-02-13 23:52 UTC (permalink / raw)
  To: Roland McGrath; +Cc: gcc-patches

On Thu, Feb 13, 2014 at 3:50 PM, Andrew Pinski <pinskia@gmail.com> wrote:
> On Thu, Feb 13, 2014 at 3:46 PM, Roland McGrath <mcgrathr@google.com> wrote:
>> Non-ancient assemblers support the "ud2" mnemonic, so there is no need
>> to emit the literal opcode as data.
>>
>> OK for trunk and 4.8?
>
> I changed this to use .word due to openbsd3.1:
> http://gcc.gnu.org/ml/gcc-patches/2005-07/msg01347.html .  I no longer
> have access to this older openbsd box so I don't object to this
> change.  In fact I doubt we support any binutils that are pre 2.0 any
> more; so maybe move over unconditionally to ud.


Oh looking into this further, it looks like Sun's assembler does not
support it either:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23359

Thanks,
Andrew

>
> Thanks,
> Andrew Pinski
>
>>
>>
>> Thanks,
>> Roland
>>
>>
>> gcc/
>> 2014-02-13  Roland McGrath  <mcgrathr@google.com>
>>
>>         * configure.ac (HAVE_AS_IX86_UD2): New test for 'ud2' mnemonic.
>>         * configure: Regenerated.
>>         * config.in: Regenerated.
>>         * config/i386/i386.md (trap) [HAVE_AS_IX86_UD2]: Use the mnemonic
>>         instead of ASM_SHORT.
>>
>> --- a/gcc/config.in
>> +++ b/gcc/config.in
>> @@ -375,6 +375,12 @@
>>  #endif
>>
>>
>> +/* Define if your assembler supports the 'ud2' mnemonic. */
>> +#ifndef USED_FOR_TARGET
>> +#undef HAVE_AS_IX86_UD2
>> +#endif
>> +
>> +
>>  /* Define if your assembler supports the lituse_jsrdirect relocation. */
>>  #ifndef USED_FOR_TARGET
>>  #undef HAVE_AS_JSRDIRECT_RELOCS
>> --- a/gcc/config/i386/i386.md
>> +++ b/gcc/config/i386/i386.md
>> @@ -17843,7 +17843,13 @@
>>  (define_insn "trap"
>>    [(trap_if (const_int 1) (const_int 6))]
>>    ""
>> -  { return ASM_SHORT "0x0b0f"; }
>> +{
>> +#ifdef HAVE_AS_IX86_UD2
>> +  return "ud2";
>> +#else
>> +  return ASM_SHORT "0x0b0f";
>> +#endif
>> +}
>>    [(set_attr "length" "2")])
>>
>>  (define_expand "prefetch"
>> --- a/gcc/configure
>> +++ b/gcc/configure
>> @@ -25109,6 +25109,37 @@ $as_echo "#define
>> HAVE_AS_IX86_REP_LOCK_PREFIX 1" >>confdefs.h
>>
>>  fi
>>
>> +    { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for
>> ud2 mnemonic" >&5
>> +$as_echo_n "checking assembler for ud2 mnemonic... " >&6; }
>> +if test "${gcc_cv_as_ix86_ud2+set}" = set; then :
>> +  $as_echo_n "(cached) " >&6
>> +else
>> +  gcc_cv_as_ix86_ud2=no
>> +  if test x$gcc_cv_as != x; then
>> +    $as_echo 'ud2' > conftest.s
>> +    if { ac_try='$gcc_cv_as $gcc_cv_as_flags  -o conftest.o conftest.s >&5'
>> +  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
>> +  (eval $ac_try) 2>&5
>> +  ac_status=$?
>> +  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
>> +  test $ac_status = 0; }; }
>> +    then
>> +       gcc_cv_as_ix86_ud2=yes
>> +    else
>> +      echo "configure: failed program was" >&5
>> +      cat conftest.s >&5
>> +    fi
>> +    rm -f conftest.o conftest.s
>> +  fi
>> +fi
>> +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_as_ix86_ud2" >&5
>> +$as_echo "$gcc_cv_as_ix86_ud2" >&6; }
>> +if test $gcc_cv_as_ix86_ud2 = yes; then
>> +
>> +$as_echo "#define HAVE_AS_IX86_UD2 1" >>confdefs.h
>> +
>> +fi
>> +
>>      { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for
>> R_386_TLS_GD_PLT reloc" >&5
>>  $as_echo_n "checking assembler for R_386_TLS_GD_PLT reloc... " >&6; }
>>  if test "${gcc_cv_as_ix86_tlsgdplt+set}" = set; then :
>> --- a/gcc/configure.ac
>> +++ b/gcc/configure.ac
>> @@ -3895,6 +3895,12 @@ foo:     nop
>>          [AC_DEFINE(HAVE_AS_IX86_REP_LOCK_PREFIX, 1,
>>            [Define if the assembler supports 'rep <insn>, lock <insn>'.])])
>>
>> +    gcc_GAS_CHECK_FEATURE([ud2 mnemonic],
>> +       gcc_cv_as_ix86_ud2,,,
>> +       [ud2],,
>> +      [AC_DEFINE(HAVE_AS_IX86_UD2, 1,
>> +       [Define if your assembler supports the 'ud2' mnemonic.])])
>> +
>>      gcc_GAS_CHECK_FEATURE([R_386_TLS_GD_PLT reloc],
>>          gcc_cv_as_ix86_tlsgdplt,,,
>>         [call    tls_gd@tlsgdplt],

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

* Re: [PATCH] x86: Use ud2 assembly mnemonic when available.
  2014-02-13 23:52   ` Andrew Pinski
@ 2014-02-13 23:57     ` Roland McGrath
  0 siblings, 0 replies; 6+ messages in thread
From: Roland McGrath @ 2014-02-13 23:57 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: gcc-patches

Did you read the patch?  It uses an empirical configure check to
discover if the assembler does in fact support ud2.

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

* Re: [PATCH] x86: Use ud2 assembly mnemonic when available.
  2014-02-14  6:58 Uros Bizjak
@ 2014-02-14 17:38 ` Roland McGrath
  0 siblings, 0 replies; 6+ messages in thread
From: Roland McGrath @ 2014-02-14 17:38 UTC (permalink / raw)
  To: Uros Bizjak; +Cc: gcc-patches

On Thu, Feb 13, 2014 at 10:58 PM, Uros Bizjak <ubizjak@gmail.com> wrote:
> You forgot to tell us how the patch tested...

Right.  It's a pretty obviously harmless change.  I tested that the
configure check passes with binutils-2.22, and eyeball'd a -S compile of a
trivial function calling __builtin_trap() to see it uses the mnemonic.  I
don't have ready access to an assembler that does not support the mnemonic,
so I simulated the negative case by momentarily hacking configure to try
'ud2x' instead of 'ud2' and verified that this configure check failed and
that for the same trivial function it then emits '.value 0x0b0f' as before.

> OK for mainline and release branches.

Committed to trunk and 4.8.


Thanks,
Roland

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

* Re: [PATCH] x86: Use ud2 assembly mnemonic when available.
@ 2014-02-14  6:58 Uros Bizjak
  2014-02-14 17:38 ` Roland McGrath
  0 siblings, 1 reply; 6+ messages in thread
From: Uros Bizjak @ 2014-02-14  6:58 UTC (permalink / raw)
  To: gcc-patches; +Cc: Roland McGrath

Hello!

> Non-ancient assemblers support the "ud2" mnemonic, so there is no need
> to emit the literal opcode as data.
>
> OK for trunk and 4.8?

You forgot to tell us how the patch tested...

> gcc/
> 2014-02-13  Roland McGrath  <mcgrathr@google.com>
>
> * configure.ac (HAVE_AS_IX86_UD2): New test for 'ud2' mnemonic.
> * configure: Regenerated.
> * config.in: Regenerated.
> * config/i386/i386.md (trap) [HAVE_AS_IX86_UD2]: Use the mnemonic
> instead of ASM_SHORT.

OK for mainline and release branches.

Thanks,
Uros.

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

end of thread, other threads:[~2014-02-14 17:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-13 23:47 [PATCH] x86: Use ud2 assembly mnemonic when available Roland McGrath
2014-02-13 23:51 ` Andrew Pinski
2014-02-13 23:52   ` Andrew Pinski
2014-02-13 23:57     ` Roland McGrath
2014-02-14  6:58 Uros Bizjak
2014-02-14 17:38 ` Roland McGrath

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