Re: [PATCH] fix -mnop-mcount generate 5byte nop in 32bit.

2017-11-15 Thread Uros Bizjak
Hello!

> "-mnop-mcount" needs to make 5byte size "nop" instruction.
> however recently gcc make only 4byte "nop" in 32bit.
> I have test in gcc 5.4, 7.2.

-fprintf (file, "1:\tnopl 0x00(%%eax,%%eax,1)\n"); /* 5 byte nop.  */
+fprintf (file, "1:\tnopl 0x01(%%eax,%%eax,1)\n"); /* 5 byte nop.  */

Even the above change is not correct, since it will be assembled in a
different way on 32 bit and 64 bit targets (size prefix will be added
on 64 bit targets). Attached patch fixes this issue by emitting a
stream of bytes.

2017-11-15  Uros Bizjak  

* config/i386/i386.c (x86_print_call_or_nop): Emit 5 byte nop
explicitly as a stream of bytes.

Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}.

Committed to mainline, will be committed to release branches.

Uros.
Index: i386.c
===
--- i386.c  (revision 254773)
+++ i386.c  (working copy)
@@ -40473,7 +40473,8 @@ static void
 x86_print_call_or_nop (FILE *file, const char *target)
 {
   if (flag_nop_mcount)
-fprintf (file, "1:\tnopl 0x00(%%eax,%%eax,1)\n"); /* 5 byte nop.  */
+/* 5 byte nop: nopl 0(%[re]ax,%[re]ax,1) */
+fprintf (file, "1:" ASM_BYTE "0x0f, 0x1f, 0x44, 0x00, 0x00\n");
   else
 fprintf (file, "1:\tcall\t%s\n", target);
 }


[PATCH] fix -mnop-mcount generate 5byte nop in 32bit.

2017-11-15 Thread 박한범
"-mnop-mcount" needs to make 5byte size "nop" instruction.
however recently gcc make only 4byte "nop" in 32bit.
I have test in gcc 5.4, 7.2.


===
bug result
===
080485c5 :
 80485c5:   0f 1f 04 00 nopl   (%eax,%eax,1)
 80485c9:   8d 4c 24 04 lea0x4(%esp),%ecx
 80485cd:   83 e4 f0and$0xfff0,%esp

===
fixed result
===
08048598 :
 8048598:   0f 1f 44 00 01  nopl   0x1(%eax,%eax,1)
 804859d:   8d 4c 24 04 lea0x4(%esp),%ecx
 80485a1:   83 e4 f0and$0xfff0,%esp


is it OK?


===
Index : gcc/config/i386/i386.c
===
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index c6ca071..e574de3 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -40474,7 +40474,7 @@ static void
 x86_print_call_or_nop (FILE *file, const char *target)
 {
   if (flag_nop_mcount)
-fprintf (file, "1:\tnopl 0x00(%%eax,%%eax,1)\n"); /* 5 byte nop.  */
+fprintf (file, "1:\tnopl 0x01(%%eax,%%eax,1)\n"); /* 5 byte nop.  */
   else
 fprintf (file, "1:\tcall\t%s\n", target);
 }