Small retpoline clean-up.

Message ID b0a55477-be14-1530-119b-7421aec38545@suse.cz
State New
Headers show
Series
  • Small retpoline clean-up.
Related show

Commit Message

Martin Liška Jan. 18, 2018, 12:48 p.m.
Hello.

The patch is small clean-up of retpoline stuff. I know that H.J. is planning
to introduce an option driving which retpoline loop filler is selected.
Hopefully the suggested patch clarifies current default selection of
the filler.

Patch survives make check -k -j10 RUNTESTFLAGS="i386.exp".

Ready to install?
Thanks,
Martin


gcc/ChangeLog:

2018-01-18  Martin Liska  <mliska@suse.cz>

	* config/i386/i386.c (indirect_thunk_name): Document that also
	lfence is emitted.
	(output_indirect_thunk): Document why both instructions
	(pause and lfence) are generated.

gcc/testsuite/ChangeLog:

2018-01-18  Martin Liska  <mliska@suse.cz>

	* gcc.target/i386/indirect-thunk-3.c: Remove duplicate options.
	* gcc.target/i386/indirect-thunk-4.c: Likewise.
	* gcc.target/i386/indirect-thunk-6.c: Likewise.
	* gcc.target/i386/indirect-thunk-bnd-4.c: Likewise.
	* gcc.target/i386/ret-thunk-10.c: Likewise.
	* gcc.target/i386/ret-thunk-11.c: Likewise.
	* gcc.target/i386/ret-thunk-12.c: Likewise.
	* gcc.target/i386/ret-thunk-15.c: Likewise.
	* gcc.target/i386/ret-thunk-9.c: Likewise.
---
 gcc/config/i386/i386.c                               | 5 ++++-
 gcc/testsuite/gcc.target/i386/indirect-thunk-3.c     | 2 +-
 gcc/testsuite/gcc.target/i386/indirect-thunk-4.c     | 2 +-
 gcc/testsuite/gcc.target/i386/indirect-thunk-6.c     | 2 +-
 gcc/testsuite/gcc.target/i386/indirect-thunk-bnd-4.c | 2 +-
 gcc/testsuite/gcc.target/i386/ret-thunk-10.c         | 2 +-
 gcc/testsuite/gcc.target/i386/ret-thunk-11.c         | 2 +-
 gcc/testsuite/gcc.target/i386/ret-thunk-12.c         | 2 +-
 gcc/testsuite/gcc.target/i386/ret-thunk-15.c         | 2 +-
 gcc/testsuite/gcc.target/i386/ret-thunk-9.c          | 2 +-
 10 files changed, 13 insertions(+), 10 deletions(-)

Comments

Jan Hubicka Jan. 18, 2018, 12:52 p.m. | #1
> Hello.

> 

> The patch is small clean-up of retpoline stuff. I know that H.J. is planning

> to introduce an option driving which retpoline loop filler is selected.

> Hopefully the suggested patch clarifies current default selection of

> the filler.

> 

> Patch survives make check -k -j10 RUNTESTFLAGS="i386.exp".

> 

> Ready to install?

> Thanks,

> Martin

> 

> 

> gcc/ChangeLog:

> 

> 2018-01-18  Martin Liska  <mliska@suse.cz>

> 

> 	* config/i386/i386.c (indirect_thunk_name): Document that also

> 	lfence is emitted.

> 	(output_indirect_thunk): Document why both instructions

> 	(pause and lfence) are generated.


OK,
thanks!
Honza
> 

> gcc/testsuite/ChangeLog:

> 

> 2018-01-18  Martin Liska  <mliska@suse.cz>

> 

> 	* gcc.target/i386/indirect-thunk-3.c: Remove duplicate options.

> 	* gcc.target/i386/indirect-thunk-4.c: Likewise.

> 	* gcc.target/i386/indirect-thunk-6.c: Likewise.

> 	* gcc.target/i386/indirect-thunk-bnd-4.c: Likewise.

> 	* gcc.target/i386/ret-thunk-10.c: Likewise.

> 	* gcc.target/i386/ret-thunk-11.c: Likewise.

> 	* gcc.target/i386/ret-thunk-12.c: Likewise.

> 	* gcc.target/i386/ret-thunk-15.c: Likewise.

> 	* gcc.target/i386/ret-thunk-9.c: Likewise.

> ---

>  gcc/config/i386/i386.c                               | 5 ++++-

>  gcc/testsuite/gcc.target/i386/indirect-thunk-3.c     | 2 +-

>  gcc/testsuite/gcc.target/i386/indirect-thunk-4.c     | 2 +-

>  gcc/testsuite/gcc.target/i386/indirect-thunk-6.c     | 2 +-

>  gcc/testsuite/gcc.target/i386/indirect-thunk-bnd-4.c | 2 +-

>  gcc/testsuite/gcc.target/i386/ret-thunk-10.c         | 2 +-

>  gcc/testsuite/gcc.target/i386/ret-thunk-11.c         | 2 +-

>  gcc/testsuite/gcc.target/i386/ret-thunk-12.c         | 2 +-

>  gcc/testsuite/gcc.target/i386/ret-thunk-15.c         | 2 +-

>  gcc/testsuite/gcc.target/i386/ret-thunk-9.c          | 2 +-

>  10 files changed, 13 insertions(+), 10 deletions(-)

> 

> 


> diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c

> index cb0f4ed5e6a..72d25ae4f72 100644

> --- a/gcc/config/i386/i386.c

> +++ b/gcc/config/i386/i386.c

> @@ -10826,6 +10826,7 @@ indirect_thunk_name (char name[32], unsigned int regno,

>  	call	L2

>     L1:

>  	pause

> +	lfence

>  	jmp	L1

>     L2:

>  	mov	%REG, (%sp)

> @@ -10837,6 +10838,7 @@ indirect_thunk_name (char name[32], unsigned int regno,

>  	call L2

>    L1:

>  	pause

> +	lfence

>  	jmp L1

>    L2:

>  	lea WORD_SIZE(%sp), %sp

> @@ -10864,7 +10866,8 @@ output_indirect_thunk (bool need_bnd_p, unsigned int regno)

>  

>    ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, indirectlabel1);

>  

> -  /* Pause + lfence.  */

> +  /* AMD and Intel CPUs prefer each a different instruction as loop filler.

> +     Usage of both pause + lfence is compromise solution.  */

>    fprintf (asm_out_file, "\tpause\n\tlfence\n");

>  

>    /* Jump.  */

> diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-3.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-3.c

> index 9e24a385387..dab7ac2ef25 100644

> --- a/gcc/testsuite/gcc.target/i386/indirect-thunk-3.c

> +++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-3.c

> @@ -1,5 +1,5 @@

>  /* { dg-do compile } */

> -/* { dg-options "-O2 -mno-indirect-branch-register -mno-indirect-branch-register -mno-indirect-branch-register -mfunction-return=keep -mindirect-branch=thunk -fno-pic" } */

> +/* { dg-options "-O2 -mno-indirect-branch-register -mfunction-return=keep -mindirect-branch=thunk -fno-pic" } */

>  

>  typedef void (*dispatch_t)(long offset);

>  

> diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-4.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-4.c

> index 127b5d94523..44cc5f52f45 100644

> --- a/gcc/testsuite/gcc.target/i386/indirect-thunk-4.c

> +++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-4.c

> @@ -1,5 +1,5 @@

>  /* { dg-do compile } */

> -/* { dg-options "-O2 -mno-indirect-branch-register -mno-indirect-branch-register -mno-indirect-branch-register -mfunction-return=keep -mindirect-branch=thunk -fno-pic" } */

> +/* { dg-options "-O2 -mno-indirect-branch-register -mfunction-return=keep -mindirect-branch=thunk -fno-pic" } */

>  

>  typedef void (*dispatch_t)(long offset);

>  

> diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-6.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-6.c

> index e4649283d10..1490f5336ca 100644

> --- a/gcc/testsuite/gcc.target/i386/indirect-thunk-6.c

> +++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-6.c

> @@ -1,5 +1,5 @@

>  /* { dg-do compile { target *-*-linux* } } */

> -/* { dg-options "-O2 -mno-indirect-branch-register -mno-indirect-branch-register -mno-indirect-branch-register -mfunction-return=keep -fpic -fno-plt -mindirect-branch=thunk" } */

> +/* { dg-options "-O2 -mno-indirect-branch-register -mfunction-return=keep -fpic -fno-plt -mindirect-branch=thunk" } */

>  

>  extern void bar (void);

>  

> diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-bnd-4.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-bnd-4.c

> index 0e19830de4d..a5fc4a23351 100644

> --- a/gcc/testsuite/gcc.target/i386/indirect-thunk-bnd-4.c

> +++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-bnd-4.c

> @@ -1,5 +1,5 @@

>  /* { dg-do compile { target { *-*-linux* && { ! x32 } } } } */

> -/* { dg-options "-O2 -mno-indirect-branch-register -mno-indirect-branch-register -mfunction-return=keep -mindirect-branch=thunk -fcheck-pointer-bounds -mmpx -fpic -fno-plt" } */

> +/* { dg-options "-O2 -mno-indirect-branch-register -mfunction-return=keep -mindirect-branch=thunk -fcheck-pointer-bounds -mmpx -fpic -fno-plt" } */

>  

>  void bar (char *);

>  char buf[10];

> diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-10.c b/gcc/testsuite/gcc.target/i386/ret-thunk-10.c

> index e6fea84a4d9..6de9b8c9f4f 100644

> --- a/gcc/testsuite/gcc.target/i386/ret-thunk-10.c

> +++ b/gcc/testsuite/gcc.target/i386/ret-thunk-10.c

> @@ -1,5 +1,5 @@

>  /* { dg-do compile } */

> -/* { dg-options "-O2 -mno-indirect-branch-register -mno-indirect-branch-register -mfunction-return=thunk-inline -mindirect-branch=thunk -fno-pic" } */

> +/* { dg-options "-O2 -mno-indirect-branch-register -mfunction-return=thunk-inline -mindirect-branch=thunk -fno-pic" } */

>  

>  extern void (*bar) (void);

>  

> diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-11.c b/gcc/testsuite/gcc.target/i386/ret-thunk-11.c

> index e239ec4542f..36598037541 100644

> --- a/gcc/testsuite/gcc.target/i386/ret-thunk-11.c

> +++ b/gcc/testsuite/gcc.target/i386/ret-thunk-11.c

> @@ -1,5 +1,5 @@

>  /* { dg-do compile } */

> -/* { dg-options "-O2 -mno-indirect-branch-register -mno-indirect-branch-register -mno-indirect-branch-register -mno-indirect-branch-register -mfunction-return=thunk-extern -mindirect-branch=thunk -fno-pic" } */

> +/* { dg-options "-O2 -mno-indirect-branch-register -mfunction-return=thunk-extern -mindirect-branch=thunk -fno-pic" } */

>  

>  extern void (*bar) (void);

>  

> diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-12.c b/gcc/testsuite/gcc.target/i386/ret-thunk-12.c

> index fa3181303c9..5fb1a4de776 100644

> --- a/gcc/testsuite/gcc.target/i386/ret-thunk-12.c

> +++ b/gcc/testsuite/gcc.target/i386/ret-thunk-12.c

> @@ -1,5 +1,5 @@

>  /* { dg-do compile } */

> -/* { dg-options "-O2 -mno-indirect-branch-register -mno-indirect-branch-register -mno-indirect-branch-register -mno-indirect-branch-register -mfunction-return=keep -mindirect-branch=thunk -fno-pic" } */

> +/* { dg-options "-O2 -mno-indirect-branch-register -mfunction-return=keep -mindirect-branch=thunk -fno-pic" } */

>  

>  extern void (*bar) (void);

>  

> diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-15.c b/gcc/testsuite/gcc.target/i386/ret-thunk-15.c

> index 75e45e226b8..2038644aa59 100644

> --- a/gcc/testsuite/gcc.target/i386/ret-thunk-15.c

> +++ b/gcc/testsuite/gcc.target/i386/ret-thunk-15.c

> @@ -1,5 +1,5 @@

>  /* { dg-do compile } */

> -/* { dg-options "-O2 -mno-indirect-branch-register -mno-indirect-branch-register -mno-indirect-branch-register -mno-indirect-branch-register -mfunction-return=keep -mindirect-branch=keep -fno-pic" } */

> +/* { dg-options "-O2 -mno-indirect-branch-register -mfunction-return=keep -mindirect-branch=keep -fno-pic" } */

>  

>  extern void (*bar) (void);

>  

> diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-9.c b/gcc/testsuite/gcc.target/i386/ret-thunk-9.c

> index d1db41cc128..d34dd4e6dc7 100644

> --- a/gcc/testsuite/gcc.target/i386/ret-thunk-9.c

> +++ b/gcc/testsuite/gcc.target/i386/ret-thunk-9.c

> @@ -1,5 +1,5 @@

>  /* { dg-do compile } */

> -/* { dg-options "-O2 -mno-indirect-branch-register -mno-indirect-branch-register -mfunction-return=thunk -mindirect-branch=thunk -fno-pic" } */

> +/* { dg-options "-O2 -mno-indirect-branch-register -mfunction-return=thunk -mindirect-branch=thunk -fno-pic" } */

>  

>  extern void (*bar) (void);

>  

>

Patch

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index cb0f4ed5e6a..72d25ae4f72 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -10826,6 +10826,7 @@  indirect_thunk_name (char name[32], unsigned int regno,
 	call	L2
    L1:
 	pause
+	lfence
 	jmp	L1
    L2:
 	mov	%REG, (%sp)
@@ -10837,6 +10838,7 @@  indirect_thunk_name (char name[32], unsigned int regno,
 	call L2
   L1:
 	pause
+	lfence
 	jmp L1
   L2:
 	lea WORD_SIZE(%sp), %sp
@@ -10864,7 +10866,8 @@  output_indirect_thunk (bool need_bnd_p, unsigned int regno)
 
   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, indirectlabel1);
 
-  /* Pause + lfence.  */
+  /* AMD and Intel CPUs prefer each a different instruction as loop filler.
+     Usage of both pause + lfence is compromise solution.  */
   fprintf (asm_out_file, "\tpause\n\tlfence\n");
 
   /* Jump.  */
diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-3.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-3.c
index 9e24a385387..dab7ac2ef25 100644
--- a/gcc/testsuite/gcc.target/i386/indirect-thunk-3.c
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-3.c
@@ -1,5 +1,5 @@ 
 /* { dg-do compile } */
-/* { dg-options "-O2 -mno-indirect-branch-register -mno-indirect-branch-register -mno-indirect-branch-register -mfunction-return=keep -mindirect-branch=thunk -fno-pic" } */
+/* { dg-options "-O2 -mno-indirect-branch-register -mfunction-return=keep -mindirect-branch=thunk -fno-pic" } */
 
 typedef void (*dispatch_t)(long offset);
 
diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-4.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-4.c
index 127b5d94523..44cc5f52f45 100644
--- a/gcc/testsuite/gcc.target/i386/indirect-thunk-4.c
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-4.c
@@ -1,5 +1,5 @@ 
 /* { dg-do compile } */
-/* { dg-options "-O2 -mno-indirect-branch-register -mno-indirect-branch-register -mno-indirect-branch-register -mfunction-return=keep -mindirect-branch=thunk -fno-pic" } */
+/* { dg-options "-O2 -mno-indirect-branch-register -mfunction-return=keep -mindirect-branch=thunk -fno-pic" } */
 
 typedef void (*dispatch_t)(long offset);
 
diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-6.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-6.c
index e4649283d10..1490f5336ca 100644
--- a/gcc/testsuite/gcc.target/i386/indirect-thunk-6.c
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-6.c
@@ -1,5 +1,5 @@ 
 /* { dg-do compile { target *-*-linux* } } */
-/* { dg-options "-O2 -mno-indirect-branch-register -mno-indirect-branch-register -mno-indirect-branch-register -mfunction-return=keep -fpic -fno-plt -mindirect-branch=thunk" } */
+/* { dg-options "-O2 -mno-indirect-branch-register -mfunction-return=keep -fpic -fno-plt -mindirect-branch=thunk" } */
 
 extern void bar (void);
 
diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-bnd-4.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-bnd-4.c
index 0e19830de4d..a5fc4a23351 100644
--- a/gcc/testsuite/gcc.target/i386/indirect-thunk-bnd-4.c
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-bnd-4.c
@@ -1,5 +1,5 @@ 
 /* { dg-do compile { target { *-*-linux* && { ! x32 } } } } */
-/* { dg-options "-O2 -mno-indirect-branch-register -mno-indirect-branch-register -mfunction-return=keep -mindirect-branch=thunk -fcheck-pointer-bounds -mmpx -fpic -fno-plt" } */
+/* { dg-options "-O2 -mno-indirect-branch-register -mfunction-return=keep -mindirect-branch=thunk -fcheck-pointer-bounds -mmpx -fpic -fno-plt" } */
 
 void bar (char *);
 char buf[10];
diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-10.c b/gcc/testsuite/gcc.target/i386/ret-thunk-10.c
index e6fea84a4d9..6de9b8c9f4f 100644
--- a/gcc/testsuite/gcc.target/i386/ret-thunk-10.c
+++ b/gcc/testsuite/gcc.target/i386/ret-thunk-10.c
@@ -1,5 +1,5 @@ 
 /* { dg-do compile } */
-/* { dg-options "-O2 -mno-indirect-branch-register -mno-indirect-branch-register -mfunction-return=thunk-inline -mindirect-branch=thunk -fno-pic" } */
+/* { dg-options "-O2 -mno-indirect-branch-register -mfunction-return=thunk-inline -mindirect-branch=thunk -fno-pic" } */
 
 extern void (*bar) (void);
 
diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-11.c b/gcc/testsuite/gcc.target/i386/ret-thunk-11.c
index e239ec4542f..36598037541 100644
--- a/gcc/testsuite/gcc.target/i386/ret-thunk-11.c
+++ b/gcc/testsuite/gcc.target/i386/ret-thunk-11.c
@@ -1,5 +1,5 @@ 
 /* { dg-do compile } */
-/* { dg-options "-O2 -mno-indirect-branch-register -mno-indirect-branch-register -mno-indirect-branch-register -mno-indirect-branch-register -mfunction-return=thunk-extern -mindirect-branch=thunk -fno-pic" } */
+/* { dg-options "-O2 -mno-indirect-branch-register -mfunction-return=thunk-extern -mindirect-branch=thunk -fno-pic" } */
 
 extern void (*bar) (void);
 
diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-12.c b/gcc/testsuite/gcc.target/i386/ret-thunk-12.c
index fa3181303c9..5fb1a4de776 100644
--- a/gcc/testsuite/gcc.target/i386/ret-thunk-12.c
+++ b/gcc/testsuite/gcc.target/i386/ret-thunk-12.c
@@ -1,5 +1,5 @@ 
 /* { dg-do compile } */
-/* { dg-options "-O2 -mno-indirect-branch-register -mno-indirect-branch-register -mno-indirect-branch-register -mno-indirect-branch-register -mfunction-return=keep -mindirect-branch=thunk -fno-pic" } */
+/* { dg-options "-O2 -mno-indirect-branch-register -mfunction-return=keep -mindirect-branch=thunk -fno-pic" } */
 
 extern void (*bar) (void);
 
diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-15.c b/gcc/testsuite/gcc.target/i386/ret-thunk-15.c
index 75e45e226b8..2038644aa59 100644
--- a/gcc/testsuite/gcc.target/i386/ret-thunk-15.c
+++ b/gcc/testsuite/gcc.target/i386/ret-thunk-15.c
@@ -1,5 +1,5 @@ 
 /* { dg-do compile } */
-/* { dg-options "-O2 -mno-indirect-branch-register -mno-indirect-branch-register -mno-indirect-branch-register -mno-indirect-branch-register -mfunction-return=keep -mindirect-branch=keep -fno-pic" } */
+/* { dg-options "-O2 -mno-indirect-branch-register -mfunction-return=keep -mindirect-branch=keep -fno-pic" } */
 
 extern void (*bar) (void);
 
diff --git a/gcc/testsuite/gcc.target/i386/ret-thunk-9.c b/gcc/testsuite/gcc.target/i386/ret-thunk-9.c
index d1db41cc128..d34dd4e6dc7 100644
--- a/gcc/testsuite/gcc.target/i386/ret-thunk-9.c
+++ b/gcc/testsuite/gcc.target/i386/ret-thunk-9.c
@@ -1,5 +1,5 @@ 
 /* { dg-do compile } */
-/* { dg-options "-O2 -mno-indirect-branch-register -mno-indirect-branch-register -mfunction-return=thunk -mindirect-branch=thunk -fno-pic" } */
+/* { dg-options "-O2 -mno-indirect-branch-register -mfunction-return=thunk -mindirect-branch=thunk -fno-pic" } */
 
 extern void (*bar) (void);