[X86] Disable mfentry for Darwin and amend testing.

Message ID A35336A4-D561-4D07-B7E1-02890F40D05F@sandoe.co.uk
State New
Headers show
Series
  • [X86] Disable mfentry for Darwin and amend testing.
Related show

Commit Message

Iain Sandoe May 22, 2019, 11:09 p.m.
Although this is a Darwin-specific change, I need to touch
target-supports.exp and several tests in i386.exp.

tested on x86_64-darwin and x86_64-linux-gnu
doc change tested with “make pdf”,

OK for trunk?
backports? (where the tests fail).

gcc/

	* config/i386/darwin.h: Reject -mfentry*.
	* doc/sourcebuild.texi: Document mfentry target support.

gcc/testsuite/

	* lib/target-supports.exp (check_effective_target_mfentry): New.
	* gcc.target/i386/fentry-override.c: Require effective target mfentry,
	* gcc/testsuite/gcc.target/i386/fentry.c: Likewise
	* gcc.target/i386/fentryname1.c: Likewise
	* gcc.target/i386/fentryname2.c: Likewise
	* gcc.target/i386/fentryname3.c: Likewise
	* gcc.target/i386/nop-mcount.c: Likewise
	* gcc.target/i386/pr82699-2.c: Likewise
	* gcc.target/i386/pr82699-4.c: Likewise
	* gcc.target/i386/pr82699-5.c: Likewise
	* gcc.target/i386/pr82699-6.c: Likewise
	* gcc.target/i386/returninst1.c: Likewise
	* gcc.target/i386/returninst2.c: Likewise
	* gcc.target/i386/returninst3.c : Likewise

Comments

Uros Bizjak May 23, 2019, 6:33 a.m. | #1
On Thu, May 23, 2019 at 1:09 AM Iain Sandoe <iain@sandoe.co.uk> wrote:
>

> Although this is a Darwin-specific change, I need to touch

> target-supports.exp and several tests in i386.exp.

>

> tested on x86_64-darwin and x86_64-linux-gnu

> doc change tested with “make pdf”,

>

> OK for trunk?

> backports? (where the tests fail).

>

> gcc/

>

>         * config/i386/darwin.h: Reject -mfentry*.

>         * doc/sourcebuild.texi: Document mfentry target support.

>

> gcc/testsuite/

>

>         * lib/target-supports.exp (check_effective_target_mfentry): New.


This procedure is written in a wrong way. You should either fix it as
suggested below, or write it in a way, similar to e.g.
check_effective_target_cet.

Uros.

>         * gcc.target/i386/fentry-override.c: Require effective target mfentry,

>         * gcc/testsuite/gcc.target/i386/fentry.c: Likewise

>         * gcc.target/i386/fentryname1.c: Likewise

>         * gcc.target/i386/fentryname2.c: Likewise

>         * gcc.target/i386/fentryname3.c: Likewise

>         * gcc.target/i386/nop-mcount.c: Likewise

>         * gcc.target/i386/pr82699-2.c: Likewise

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

>         * gcc.target/i386/pr82699-5.c: Likewise

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

>         * gcc.target/i386/returninst1.c: Likewise

>         * gcc.target/i386/returninst2.c: Likewise

>         * gcc.target/i386/returninst3.c : Likewise

>

> diff --git a/gcc/config/i386/darwin.h b/gcc/config/i386/darwin.h

> index fe11ec9..1128428 100644

> --- a/gcc/config/i386/darwin.h

> +++ b/gcc/config/i386/darwin.h

> @@ -132,7 +132,8 @@ extern int darwin_emit_branch_islands;

>  #define CC1_SPEC "%(cc1_cpu) \

>    %{!mkernel:%{!static:%{!mdynamic-no-pic:-fPIC}}} \

>    %{g: %{!fno-eliminate-unused-debug-symbols: -feliminate-unused-debug-symbols }} \

> -  %{mx32:%eDarwin is not an mx32 platform}" \

> +  %{mx32:%eDarwin is not an mx32 platform} \

> +  %{mfentry*:%eDarwin does not support -mfentry or associated options}" \

>    DARWIN_CC1_SPEC

>

>  #undef ASM_SPEC

> diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi

> index cf12d74..546af7f 100644

> --- a/gcc/doc/sourcebuild.texi

> +++ b/gcc/doc/sourcebuild.texi

> @@ -2382,6 +2382,10 @@ Target supports compiling @code{aes} instructions.

>  @item fma4

>  Target supports compiling @code{fma4} instructions.

>

> +@item mfentry

> +Target supports the @code{-mfentry} option that alters the

> +position of profiling calls such that they precede the prologue.

> +

>  @item ms_hook_prologue

>  Target supports attribute @code{ms_hook_prologue}.

>

> diff --git a/gcc/testsuite/gcc.target/i386/fentry-override.c b/gcc/testsuite/gcc.target/i386/fentry-override.c

> index 7bc5fc4..efba1bf 100644

> --- a/gcc/testsuite/gcc.target/i386/fentry-override.c

> +++ b/gcc/testsuite/gcc.target/i386/fentry-override.c

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

>  /* Test -mfentry override */

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

> +/* { dg-require-effective-target mfentry } */

>  /* { dg-options "-mfentry" } */

>  /* { dg-final { scan-assembler-not "__fentry__" } } */

>  /* Origin: Andi Kleen */

> diff --git a/gcc/testsuite/gcc.target/i386/fentry.c b/gcc/testsuite/gcc.target/i386/fentry.c

> index 2449e75..28edd10 100644

> --- a/gcc/testsuite/gcc.target/i386/fentry.c

> +++ b/gcc/testsuite/gcc.target/i386/fentry.c

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

>  /* Test -mfentry */

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

> +/* { dg-require-effective-target mfentry } */

>  /* { dg-options "-fprofile -mfentry" } */

>  /* { dg-final { scan-assembler "__fentry__" } } */

>  /* Origin: Andi Kleen */

> diff --git a/gcc/testsuite/gcc.target/i386/fentryname1.c b/gcc/testsuite/gcc.target/i386/fentryname1.c

> index 6d2e76d..1265342 100644

> --- a/gcc/testsuite/gcc.target/i386/fentryname1.c

> +++ b/gcc/testsuite/gcc.target/i386/fentryname1.c

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

>  /* { dg-do compile } */

> +/* { dg-require-effective-target mfentry } */

>  /* { dg-options "-pg -mfentry -mfentry-name=foo" } */

>  /* { dg-final { scan-assembler "call.*foo" } } */

>  /* { dg-final { scan-assembler "call.*bar" } } */

> diff --git a/gcc/testsuite/gcc.target/i386/fentryname2.c b/gcc/testsuite/gcc.target/i386/fentryname2.c

> index 7d102bf..c51c5d1 100644

> --- a/gcc/testsuite/gcc.target/i386/fentryname2.c

> +++ b/gcc/testsuite/gcc.target/i386/fentryname2.c

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

>  /* { dg-do compile } */

> +/* { dg-require-effective-target mfentry } */

>  /* { dg-options "-pg -mfentry -mrecord-mcount -mfentry-section=foo" } */

>  /* { dg-final { scan-assembler "section.*foo" } } */

>  /* { dg-final { scan-assembler "section.*bar" } } */

> diff --git a/gcc/testsuite/gcc.target/i386/fentryname3.c b/gcc/testsuite/gcc.target/i386/fentryname3.c

> index 777f4e4..5688109 100644

> --- a/gcc/testsuite/gcc.target/i386/fentryname3.c

> +++ b/gcc/testsuite/gcc.target/i386/fentryname3.c

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

>  /* { dg-do compile } */

> +/* { dg-require-effective-target mfentry } */

>  /* { dg-options "-pg -mfentry"  } */

>  /* { dg-final { scan-assembler "section.*__entry_loc" } } */

>  /* { dg-final { scan-assembler "0x0f, 0x1f, 0x44, 0x00, 0x00" } } */

> diff --git a/gcc/testsuite/gcc.target/i386/nop-mcount.c b/gcc/testsuite/gcc.target/i386/nop-mcount.c

> index a8e14bc..a5f8d27 100644

> --- a/gcc/testsuite/gcc.target/i386/nop-mcount.c

> +++ b/gcc/testsuite/gcc.target/i386/nop-mcount.c

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

>  /* Test -mnop-mcount */

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

> +/* { dg-require-effective-target mfentry } */

>  /* { dg-options "-pg -mfentry -mrecord-mcount -mnop-mcount" } */

>  /* { dg-final { scan-assembler-not "__fentry__" } } */

>  /* Origin: Andi Kleen */

> diff --git a/gcc/testsuite/gcc.target/i386/pr82699-2.c b/gcc/testsuite/gcc.target/i386/pr82699-2.c

> index 07a4ccb..c43cf44 100644

> --- a/gcc/testsuite/gcc.target/i386/pr82699-2.c

> +++ b/gcc/testsuite/gcc.target/i386/pr82699-2.c

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

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

> +/* { dg-require-effective-target mfentry } */

>  /* { dg-options "-O2 -fno-pic -fcf-protection -pg -mfentry -fasynchronous-unwind-tables" } */

>  /* { dg-final { scan-assembler-times {\t\.cfi_startproc\n\tendbr} 1 } } */

>

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

> index 3cc03db..719566b 100644

> --- a/gcc/testsuite/gcc.target/i386/pr82699-4.c

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

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

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

> +/* { dg-require-effective-target mfentry } */

>  /* { dg-options "-O2 -fpic -fcf-protection -pg -mfentry -fasynchronous-unwind-tables" } */

>  /* { dg-final { scan-assembler-times {\t\.cfi_startproc\n\tendbr} 1 } } */

>

> diff --git a/gcc/testsuite/gcc.target/i386/pr82699-5.c b/gcc/testsuite/gcc.target/i386/pr82699-5.c

> index 0c547e2..ac3c1ae 100644

> --- a/gcc/testsuite/gcc.target/i386/pr82699-5.c

> +++ b/gcc/testsuite/gcc.target/i386/pr82699-5.c

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

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

> +/* { dg-require-effective-target mfentry } */

>  /* { dg-options "-O2 -fcf-protection -mfentry -fasynchronous-unwind-tables" } */

>  /* { dg-additional-options "-fno-pic" { target ia32 } } */

>  /* { dg-final { scan-assembler-times {\t\.cfi_startproc\n\tendbr} 1 } } */

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

> index ff6bae7..0b595f4 100644

> --- a/gcc/testsuite/gcc.target/i386/pr82699-6.c

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

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

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

> +/* { dg-require-effective-target mfentry } */

>  /* { dg-options "-fno-pic -O2 -fcf-protection -pg -mfentry -mrecord-mcount -mnop-mcount -fasynchronous-unwind-tables" } */

>  /* { dg-final { scan-assembler-times {\t\.cfi_startproc\n\tendbr} 1 } } */

>

> diff --git a/gcc/testsuite/gcc.target/i386/returninst1.c b/gcc/testsuite/gcc.target/i386/returninst1.c

> index d7ecc41..133fdee 100644

> --- a/gcc/testsuite/gcc.target/i386/returninst1.c

> +++ b/gcc/testsuite/gcc.target/i386/returninst1.c

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

>  /* { dg-do compile { target { ! ia32 } } } */

> +/* { dg-require-effective-target mfentry } */

>  /* { dg-options "-pg -mfentry -minstrument-return=call -mrecord-return" } */

>  /* { dg-final { scan-assembler "call.*__return__" } } */

>  /* { dg-final { scan-assembler "section.*return_loc" } } */

> diff --git a/gcc/testsuite/gcc.target/i386/returninst2.c b/gcc/testsuite/gcc.target/i386/returninst2.c

> index 4724b40..3629310 100644

> --- a/gcc/testsuite/gcc.target/i386/returninst2.c

> +++ b/gcc/testsuite/gcc.target/i386/returninst2.c

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

>  /* { dg-do compile { target { ! ia32 } } } */

> +/* { dg-require-effective-target mfentry } */

>  /* { dg-options "-pg -mfentry -minstrument-return=nop5 -mrecord-return" } */

>  /* { dg-final { scan-assembler-times "0x0f, 0x1f, 0x44, 0x00, 0x00" 3 } } */

>  /* { dg-final { scan-assembler "section.*return_loc" } } */

> diff --git a/gcc/testsuite/gcc.target/i386/returninst3.c b/gcc/testsuite/gcc.target/i386/returninst3.c

> index 14b4445..b84cc77 100644

> --- a/gcc/testsuite/gcc.target/i386/returninst3.c

> +++ b/gcc/testsuite/gcc.target/i386/returninst3.c

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

>  /* { dg-do compile { target { ! ia32 } } } */

> +/* { dg-require-effective-target mfentry } */

>  /* { dg-options "-pg -mfentry -minstrument-return=call" } */

>  /* { dg-final { scan-assembler-not "call.*__return__" } } */

>

> diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp

> index 3bd6e81..a153366 100644

> --- a/gcc/testsuite/lib/target-supports.exp

> +++ b/gcc/testsuite/lib/target-supports.exp

> @@ -9359,3 +9359,17 @@ proc check_effective_target_llvm_binutils { } {

>               expr { [istarget amdgcn*-*-*]

>                      || [check_effective_target_offload_gcn] }}]

>  }

> +

> +# Return 1 if the compiler supports '-mfentry'.

> +

> +proc check_effective_target_mfentry { } {

> +    return [check_cached_effective_target mentry_available {

> +        if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {

> +           return 0


expr 0

> +        } else {

> +            return [check_no_compiler_messages mfentry object {


no "return" here.

> +               void foo (void) { }

> +            } "-mfentry"]

> +        }

> +    }]

> +}

>
Iain Sandoe May 23, 2019, 9:34 a.m. | #2
Hi Uros,

> On 23 May 2019, at 07:33, Uros Bizjak <ubizjak@gmail.com> wrote:

> 

> On Thu, May 23, 2019 at 1:09 AM Iain Sandoe <iain@sandoe.co.uk> wrote:

>> 

>> Although this is a Darwin-specific change, I need to touch

>> target-supports.exp and several tests in i386.exp.

>> 

>> tested on x86_64-darwin and x86_64-linux-gnu

>> doc change tested with “make pdf”,

>> 

>> OK for trunk?

>> backports? (where the tests fail).

>> 

>> gcc/

>> 

>>        * config/i386/darwin.h: Reject -mfentry*.

>>        * doc/sourcebuild.texi: Document mfentry target support.

>> 

>> gcc/testsuite/

>> 

>>        * lib/target-supports.exp (check_effective_target_mfentry): New.

> 

> This procedure is written in a wrong way. You should either fix it as

> suggested below, or write it in a way, similar to e.g.

> check_effective_target_cet.


ah, the dangers of cut & paste, I had over-complicated the test.

So, as below (no other changes) assuming that retesting passes?

Iain

# Return 1 if the compiler supports '-mfentry'.

proc check_effective_target_mfentry { } {
    if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
        return 0
    }
    return [check_no_compiler_messages mfentry object {
	        void foo (void) { }
    } "-mfentry"]
}

> 

> Uros.

> 

>>        * gcc.target/i386/fentry-override.c: Require effective target mfentry,

>>        * gcc/testsuite/gcc.target/i386/fentry.c: Likewise

>>        * gcc.target/i386/fentryname1.c: Likewise

>>        * gcc.target/i386/fentryname2.c: Likewise

>>        * gcc.target/i386/fentryname3.c: Likewise

>>        * gcc.target/i386/nop-mcount.c: Likewise

>>        * gcc.target/i386/pr82699-2.c: Likewise

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

>>        * gcc.target/i386/pr82699-5.c: Likewise

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

>>        * gcc.target/i386/returninst1.c: Likewise

>>        * gcc.target/i386/returninst2.c: Likewise

>>        * gcc.target/i386/returninst3.c : Likewise

>> 

>> diff --git a/gcc/config/i386/darwin.h b/gcc/config/i386/darwin.h

>> index fe11ec9..1128428 100644

>> --- a/gcc/config/i386/darwin.h

>> +++ b/gcc/config/i386/darwin.h

>> @@ -132,7 +132,8 @@ extern int darwin_emit_branch_islands;

>> #define CC1_SPEC "%(cc1_cpu) \

>>   %{!mkernel:%{!static:%{!mdynamic-no-pic:-fPIC}}} \

>>   %{g: %{!fno-eliminate-unused-debug-symbols: -feliminate-unused-debug-symbols }} \

>> -  %{mx32:%eDarwin is not an mx32 platform}" \

>> +  %{mx32:%eDarwin is not an mx32 platform} \

>> +  %{mfentry*:%eDarwin does not support -mfentry or associated options}" \

>>   DARWIN_CC1_SPEC

>> 

>> #undef ASM_SPEC

>> diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi

>> index cf12d74..546af7f 100644

>> --- a/gcc/doc/sourcebuild.texi

>> +++ b/gcc/doc/sourcebuild.texi

>> @@ -2382,6 +2382,10 @@ Target supports compiling @code{aes} instructions.

>> @item fma4

>> Target supports compiling @code{fma4} instructions.

>> 

>> +@item mfentry

>> +Target supports the @code{-mfentry} option that alters the

>> +position of profiling calls such that they precede the prologue.

>> +

>> @item ms_hook_prologue

>> Target supports attribute @code{ms_hook_prologue}.

>> 

>> diff --git a/gcc/testsuite/gcc.target/i386/fentry-override.c b/gcc/testsuite/gcc.target/i386/fentry-override.c

>> index 7bc5fc4..efba1bf 100644

>> --- a/gcc/testsuite/gcc.target/i386/fentry-override.c

>> +++ b/gcc/testsuite/gcc.target/i386/fentry-override.c

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

>> /* Test -mfentry override */

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

>> +/* { dg-require-effective-target mfentry } */

>> /* { dg-options "-mfentry" } */

>> /* { dg-final { scan-assembler-not "__fentry__" } } */

>> /* Origin: Andi Kleen */

>> diff --git a/gcc/testsuite/gcc.target/i386/fentry.c b/gcc/testsuite/gcc.target/i386/fentry.c

>> index 2449e75..28edd10 100644

>> --- a/gcc/testsuite/gcc.target/i386/fentry.c

>> +++ b/gcc/testsuite/gcc.target/i386/fentry.c

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

>> /* Test -mfentry */

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

>> +/* { dg-require-effective-target mfentry } */

>> /* { dg-options "-fprofile -mfentry" } */

>> /* { dg-final { scan-assembler "__fentry__" } } */

>> /* Origin: Andi Kleen */

>> diff --git a/gcc/testsuite/gcc.target/i386/fentryname1.c b/gcc/testsuite/gcc.target/i386/fentryname1.c

>> index 6d2e76d..1265342 100644

>> --- a/gcc/testsuite/gcc.target/i386/fentryname1.c

>> +++ b/gcc/testsuite/gcc.target/i386/fentryname1.c

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

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

>> +/* { dg-require-effective-target mfentry } */

>> /* { dg-options "-pg -mfentry -mfentry-name=foo" } */

>> /* { dg-final { scan-assembler "call.*foo" } } */

>> /* { dg-final { scan-assembler "call.*bar" } } */

>> diff --git a/gcc/testsuite/gcc.target/i386/fentryname2.c b/gcc/testsuite/gcc.target/i386/fentryname2.c

>> index 7d102bf..c51c5d1 100644

>> --- a/gcc/testsuite/gcc.target/i386/fentryname2.c

>> +++ b/gcc/testsuite/gcc.target/i386/fentryname2.c

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

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

>> +/* { dg-require-effective-target mfentry } */

>> /* { dg-options "-pg -mfentry -mrecord-mcount -mfentry-section=foo" } */

>> /* { dg-final { scan-assembler "section.*foo" } } */

>> /* { dg-final { scan-assembler "section.*bar" } } */

>> diff --git a/gcc/testsuite/gcc.target/i386/fentryname3.c b/gcc/testsuite/gcc.target/i386/fentryname3.c

>> index 777f4e4..5688109 100644

>> --- a/gcc/testsuite/gcc.target/i386/fentryname3.c

>> +++ b/gcc/testsuite/gcc.target/i386/fentryname3.c

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

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

>> +/* { dg-require-effective-target mfentry } */

>> /* { dg-options "-pg -mfentry"  } */

>> /* { dg-final { scan-assembler "section.*__entry_loc" } } */

>> /* { dg-final { scan-assembler "0x0f, 0x1f, 0x44, 0x00, 0x00" } } */

>> diff --git a/gcc/testsuite/gcc.target/i386/nop-mcount.c b/gcc/testsuite/gcc.target/i386/nop-mcount.c

>> index a8e14bc..a5f8d27 100644

>> --- a/gcc/testsuite/gcc.target/i386/nop-mcount.c

>> +++ b/gcc/testsuite/gcc.target/i386/nop-mcount.c

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

>> /* Test -mnop-mcount */

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

>> +/* { dg-require-effective-target mfentry } */

>> /* { dg-options "-pg -mfentry -mrecord-mcount -mnop-mcount" } */

>> /* { dg-final { scan-assembler-not "__fentry__" } } */

>> /* Origin: Andi Kleen */

>> diff --git a/gcc/testsuite/gcc.target/i386/pr82699-2.c b/gcc/testsuite/gcc.target/i386/pr82699-2.c

>> index 07a4ccb..c43cf44 100644

>> --- a/gcc/testsuite/gcc.target/i386/pr82699-2.c

>> +++ b/gcc/testsuite/gcc.target/i386/pr82699-2.c

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

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

>> +/* { dg-require-effective-target mfentry } */

>> /* { dg-options "-O2 -fno-pic -fcf-protection -pg -mfentry -fasynchronous-unwind-tables" } */

>> /* { dg-final { scan-assembler-times {\t\.cfi_startproc\n\tendbr} 1 } } */

>> 

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

>> index 3cc03db..719566b 100644

>> --- a/gcc/testsuite/gcc.target/i386/pr82699-4.c

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

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

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

>> +/* { dg-require-effective-target mfentry } */

>> /* { dg-options "-O2 -fpic -fcf-protection -pg -mfentry -fasynchronous-unwind-tables" } */

>> /* { dg-final { scan-assembler-times {\t\.cfi_startproc\n\tendbr} 1 } } */

>> 

>> diff --git a/gcc/testsuite/gcc.target/i386/pr82699-5.c b/gcc/testsuite/gcc.target/i386/pr82699-5.c

>> index 0c547e2..ac3c1ae 100644

>> --- a/gcc/testsuite/gcc.target/i386/pr82699-5.c

>> +++ b/gcc/testsuite/gcc.target/i386/pr82699-5.c

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

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

>> +/* { dg-require-effective-target mfentry } */

>> /* { dg-options "-O2 -fcf-protection -mfentry -fasynchronous-unwind-tables" } */

>> /* { dg-additional-options "-fno-pic" { target ia32 } } */

>> /* { dg-final { scan-assembler-times {\t\.cfi_startproc\n\tendbr} 1 } } */

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

>> index ff6bae7..0b595f4 100644

>> --- a/gcc/testsuite/gcc.target/i386/pr82699-6.c

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

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

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

>> +/* { dg-require-effective-target mfentry } */

>> /* { dg-options "-fno-pic -O2 -fcf-protection -pg -mfentry -mrecord-mcount -mnop-mcount -fasynchronous-unwind-tables" } */

>> /* { dg-final { scan-assembler-times {\t\.cfi_startproc\n\tendbr} 1 } } */

>> 

>> diff --git a/gcc/testsuite/gcc.target/i386/returninst1.c b/gcc/testsuite/gcc.target/i386/returninst1.c

>> index d7ecc41..133fdee 100644

>> --- a/gcc/testsuite/gcc.target/i386/returninst1.c

>> +++ b/gcc/testsuite/gcc.target/i386/returninst1.c

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

>> /* { dg-do compile { target { ! ia32 } } } */

>> +/* { dg-require-effective-target mfentry } */

>> /* { dg-options "-pg -mfentry -minstrument-return=call -mrecord-return" } */

>> /* { dg-final { scan-assembler "call.*__return__" } } */

>> /* { dg-final { scan-assembler "section.*return_loc" } } */

>> diff --git a/gcc/testsuite/gcc.target/i386/returninst2.c b/gcc/testsuite/gcc.target/i386/returninst2.c

>> index 4724b40..3629310 100644

>> --- a/gcc/testsuite/gcc.target/i386/returninst2.c

>> +++ b/gcc/testsuite/gcc.target/i386/returninst2.c

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

>> /* { dg-do compile { target { ! ia32 } } } */

>> +/* { dg-require-effective-target mfentry } */

>> /* { dg-options "-pg -mfentry -minstrument-return=nop5 -mrecord-return" } */

>> /* { dg-final { scan-assembler-times "0x0f, 0x1f, 0x44, 0x00, 0x00" 3 } } */

>> /* { dg-final { scan-assembler "section.*return_loc" } } */

>> diff --git a/gcc/testsuite/gcc.target/i386/returninst3.c b/gcc/testsuite/gcc.target/i386/returninst3.c

>> index 14b4445..b84cc77 100644

>> --- a/gcc/testsuite/gcc.target/i386/returninst3.c

>> +++ b/gcc/testsuite/gcc.target/i386/returninst3.c

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

>> /* { dg-do compile { target { ! ia32 } } } */

>> +/* { dg-require-effective-target mfentry } */

>> /* { dg-options "-pg -mfentry -minstrument-return=call" } */

>> /* { dg-final { scan-assembler-not "call.*__return__" } } */

>> 

>> diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp

>> index 3bd6e81..a153366 100644

>> --- a/gcc/testsuite/lib/target-supports.exp

>> +++ b/gcc/testsuite/lib/target-supports.exp

>> @@ -9359,3 +9359,17 @@ proc check_effective_target_llvm_binutils { } {

>>              expr { [istarget amdgcn*-*-*]

>>                     || [check_effective_target_offload_gcn] }}]

>> }

>> +

>> +# Return 1 if the compiler supports '-mfentry'.

>> +

>> +proc check_effective_target_mfentry { } {

>> +    return [check_cached_effective_target mentry_available {

>> +        if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {

>> +           return 0

> 

> expr 0

> 

>> +        } else {

>> +            return [check_no_compiler_messages mfentry object {

> 

> no "return" here.

> 

>> +               void foo (void) { }

>> +            } "-mfentry"]

>> +        }

>> +    }]

>> +}
Uros Bizjak May 23, 2019, 10:55 a.m. | #3
On Thu, May 23, 2019 at 11:34 AM Iain Sandoe <iain@sandoe.co.uk> wrote:
>

> Hi Uros,

>

> > On 23 May 2019, at 07:33, Uros Bizjak <ubizjak@gmail.com> wrote:

> >

> > On Thu, May 23, 2019 at 1:09 AM Iain Sandoe <iain@sandoe.co.uk> wrote:

> >>

> >> Although this is a Darwin-specific change, I need to touch

> >> target-supports.exp and several tests in i386.exp.

> >>

> >> tested on x86_64-darwin and x86_64-linux-gnu

> >> doc change tested with “make pdf”,

> >>

> >> OK for trunk?

> >> backports? (where the tests fail).

> >>

> >> gcc/

> >>

> >>        * config/i386/darwin.h: Reject -mfentry*.

> >>        * doc/sourcebuild.texi: Document mfentry target support.

> >>

> >> gcc/testsuite/

> >>

> >>        * lib/target-supports.exp (check_effective_target_mfentry): New.

> >

> > This procedure is written in a wrong way. You should either fix it as

> > suggested below, or write it in a way, similar to e.g.

> > check_effective_target_cet.

>

> ah, the dangers of cut & paste, I had over-complicated the test.

>

> So, as below (no other changes) assuming that retesting passes?

>

> Iain

>

> # Return 1 if the compiler supports '-mfentry'.

>

> proc check_effective_target_mfentry { } {

>     if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {

>         return 0

>     }

>     return [check_no_compiler_messages mfentry object {

>                 void foo (void) { }

>     } "-mfentry"]

> }


OK for trunk and backports.

Thanks,
Uros.

>

> >

> > Uros.

> >

> >>        * gcc.target/i386/fentry-override.c: Require effective target mfentry,

> >>        * gcc/testsuite/gcc.target/i386/fentry.c: Likewise

> >>        * gcc.target/i386/fentryname1.c: Likewise

> >>        * gcc.target/i386/fentryname2.c: Likewise

> >>        * gcc.target/i386/fentryname3.c: Likewise

> >>        * gcc.target/i386/nop-mcount.c: Likewise

> >>        * gcc.target/i386/pr82699-2.c: Likewise

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

> >>        * gcc.target/i386/pr82699-5.c: Likewise

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

> >>        * gcc.target/i386/returninst1.c: Likewise

> >>        * gcc.target/i386/returninst2.c: Likewise

> >>        * gcc.target/i386/returninst3.c : Likewise

> >>

> >> diff --git a/gcc/config/i386/darwin.h b/gcc/config/i386/darwin.h

> >> index fe11ec9..1128428 100644

> >> --- a/gcc/config/i386/darwin.h

> >> +++ b/gcc/config/i386/darwin.h

> >> @@ -132,7 +132,8 @@ extern int darwin_emit_branch_islands;

> >> #define CC1_SPEC "%(cc1_cpu) \

> >>   %{!mkernel:%{!static:%{!mdynamic-no-pic:-fPIC}}} \

> >>   %{g: %{!fno-eliminate-unused-debug-symbols: -feliminate-unused-debug-symbols }} \

> >> -  %{mx32:%eDarwin is not an mx32 platform}" \

> >> +  %{mx32:%eDarwin is not an mx32 platform} \

> >> +  %{mfentry*:%eDarwin does not support -mfentry or associated options}" \

> >>   DARWIN_CC1_SPEC

> >>

> >> #undef ASM_SPEC

> >> diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi

> >> index cf12d74..546af7f 100644

> >> --- a/gcc/doc/sourcebuild.texi

> >> +++ b/gcc/doc/sourcebuild.texi

> >> @@ -2382,6 +2382,10 @@ Target supports compiling @code{aes} instructions.

> >> @item fma4

> >> Target supports compiling @code{fma4} instructions.

> >>

> >> +@item mfentry

> >> +Target supports the @code{-mfentry} option that alters the

> >> +position of profiling calls such that they precede the prologue.

> >> +

> >> @item ms_hook_prologue

> >> Target supports attribute @code{ms_hook_prologue}.

> >>

> >> diff --git a/gcc/testsuite/gcc.target/i386/fentry-override.c b/gcc/testsuite/gcc.target/i386/fentry-override.c

> >> index 7bc5fc4..efba1bf 100644

> >> --- a/gcc/testsuite/gcc.target/i386/fentry-override.c

> >> +++ b/gcc/testsuite/gcc.target/i386/fentry-override.c

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

> >> /* Test -mfentry override */

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

> >> +/* { dg-require-effective-target mfentry } */

> >> /* { dg-options "-mfentry" } */

> >> /* { dg-final { scan-assembler-not "__fentry__" } } */

> >> /* Origin: Andi Kleen */

> >> diff --git a/gcc/testsuite/gcc.target/i386/fentry.c b/gcc/testsuite/gcc.target/i386/fentry.c

> >> index 2449e75..28edd10 100644

> >> --- a/gcc/testsuite/gcc.target/i386/fentry.c

> >> +++ b/gcc/testsuite/gcc.target/i386/fentry.c

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

> >> /* Test -mfentry */

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

> >> +/* { dg-require-effective-target mfentry } */

> >> /* { dg-options "-fprofile -mfentry" } */

> >> /* { dg-final { scan-assembler "__fentry__" } } */

> >> /* Origin: Andi Kleen */

> >> diff --git a/gcc/testsuite/gcc.target/i386/fentryname1.c b/gcc/testsuite/gcc.target/i386/fentryname1.c

> >> index 6d2e76d..1265342 100644

> >> --- a/gcc/testsuite/gcc.target/i386/fentryname1.c

> >> +++ b/gcc/testsuite/gcc.target/i386/fentryname1.c

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

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

> >> +/* { dg-require-effective-target mfentry } */

> >> /* { dg-options "-pg -mfentry -mfentry-name=foo" } */

> >> /* { dg-final { scan-assembler "call.*foo" } } */

> >> /* { dg-final { scan-assembler "call.*bar" } } */

> >> diff --git a/gcc/testsuite/gcc.target/i386/fentryname2.c b/gcc/testsuite/gcc.target/i386/fentryname2.c

> >> index 7d102bf..c51c5d1 100644

> >> --- a/gcc/testsuite/gcc.target/i386/fentryname2.c

> >> +++ b/gcc/testsuite/gcc.target/i386/fentryname2.c

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

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

> >> +/* { dg-require-effective-target mfentry } */

> >> /* { dg-options "-pg -mfentry -mrecord-mcount -mfentry-section=foo" } */

> >> /* { dg-final { scan-assembler "section.*foo" } } */

> >> /* { dg-final { scan-assembler "section.*bar" } } */

> >> diff --git a/gcc/testsuite/gcc.target/i386/fentryname3.c b/gcc/testsuite/gcc.target/i386/fentryname3.c

> >> index 777f4e4..5688109 100644

> >> --- a/gcc/testsuite/gcc.target/i386/fentryname3.c

> >> +++ b/gcc/testsuite/gcc.target/i386/fentryname3.c

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

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

> >> +/* { dg-require-effective-target mfentry } */

> >> /* { dg-options "-pg -mfentry"  } */

> >> /* { dg-final { scan-assembler "section.*__entry_loc" } } */

> >> /* { dg-final { scan-assembler "0x0f, 0x1f, 0x44, 0x00, 0x00" } } */

> >> diff --git a/gcc/testsuite/gcc.target/i386/nop-mcount.c b/gcc/testsuite/gcc.target/i386/nop-mcount.c

> >> index a8e14bc..a5f8d27 100644

> >> --- a/gcc/testsuite/gcc.target/i386/nop-mcount.c

> >> +++ b/gcc/testsuite/gcc.target/i386/nop-mcount.c

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

> >> /* Test -mnop-mcount */

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

> >> +/* { dg-require-effective-target mfentry } */

> >> /* { dg-options "-pg -mfentry -mrecord-mcount -mnop-mcount" } */

> >> /* { dg-final { scan-assembler-not "__fentry__" } } */

> >> /* Origin: Andi Kleen */

> >> diff --git a/gcc/testsuite/gcc.target/i386/pr82699-2.c b/gcc/testsuite/gcc.target/i386/pr82699-2.c

> >> index 07a4ccb..c43cf44 100644

> >> --- a/gcc/testsuite/gcc.target/i386/pr82699-2.c

> >> +++ b/gcc/testsuite/gcc.target/i386/pr82699-2.c

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

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

> >> +/* { dg-require-effective-target mfentry } */

> >> /* { dg-options "-O2 -fno-pic -fcf-protection -pg -mfentry -fasynchronous-unwind-tables" } */

> >> /* { dg-final { scan-assembler-times {\t\.cfi_startproc\n\tendbr} 1 } } */

> >>

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

> >> index 3cc03db..719566b 100644

> >> --- a/gcc/testsuite/gcc.target/i386/pr82699-4.c

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

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

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

> >> +/* { dg-require-effective-target mfentry } */

> >> /* { dg-options "-O2 -fpic -fcf-protection -pg -mfentry -fasynchronous-unwind-tables" } */

> >> /* { dg-final { scan-assembler-times {\t\.cfi_startproc\n\tendbr} 1 } } */

> >>

> >> diff --git a/gcc/testsuite/gcc.target/i386/pr82699-5.c b/gcc/testsuite/gcc.target/i386/pr82699-5.c

> >> index 0c547e2..ac3c1ae 100644

> >> --- a/gcc/testsuite/gcc.target/i386/pr82699-5.c

> >> +++ b/gcc/testsuite/gcc.target/i386/pr82699-5.c

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

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

> >> +/* { dg-require-effective-target mfentry } */

> >> /* { dg-options "-O2 -fcf-protection -mfentry -fasynchronous-unwind-tables" } */

> >> /* { dg-additional-options "-fno-pic" { target ia32 } } */

> >> /* { dg-final { scan-assembler-times {\t\.cfi_startproc\n\tendbr} 1 } } */

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

> >> index ff6bae7..0b595f4 100644

> >> --- a/gcc/testsuite/gcc.target/i386/pr82699-6.c

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

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

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

> >> +/* { dg-require-effective-target mfentry } */

> >> /* { dg-options "-fno-pic -O2 -fcf-protection -pg -mfentry -mrecord-mcount -mnop-mcount -fasynchronous-unwind-tables" } */

> >> /* { dg-final { scan-assembler-times {\t\.cfi_startproc\n\tendbr} 1 } } */

> >>

> >> diff --git a/gcc/testsuite/gcc.target/i386/returninst1.c b/gcc/testsuite/gcc.target/i386/returninst1.c

> >> index d7ecc41..133fdee 100644

> >> --- a/gcc/testsuite/gcc.target/i386/returninst1.c

> >> +++ b/gcc/testsuite/gcc.target/i386/returninst1.c

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

> >> /* { dg-do compile { target { ! ia32 } } } */

> >> +/* { dg-require-effective-target mfentry } */

> >> /* { dg-options "-pg -mfentry -minstrument-return=call -mrecord-return" } */

> >> /* { dg-final { scan-assembler "call.*__return__" } } */

> >> /* { dg-final { scan-assembler "section.*return_loc" } } */

> >> diff --git a/gcc/testsuite/gcc.target/i386/returninst2.c b/gcc/testsuite/gcc.target/i386/returninst2.c

> >> index 4724b40..3629310 100644

> >> --- a/gcc/testsuite/gcc.target/i386/returninst2.c

> >> +++ b/gcc/testsuite/gcc.target/i386/returninst2.c

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

> >> /* { dg-do compile { target { ! ia32 } } } */

> >> +/* { dg-require-effective-target mfentry } */

> >> /* { dg-options "-pg -mfentry -minstrument-return=nop5 -mrecord-return" } */

> >> /* { dg-final { scan-assembler-times "0x0f, 0x1f, 0x44, 0x00, 0x00" 3 } } */

> >> /* { dg-final { scan-assembler "section.*return_loc" } } */

> >> diff --git a/gcc/testsuite/gcc.target/i386/returninst3.c b/gcc/testsuite/gcc.target/i386/returninst3.c

> >> index 14b4445..b84cc77 100644

> >> --- a/gcc/testsuite/gcc.target/i386/returninst3.c

> >> +++ b/gcc/testsuite/gcc.target/i386/returninst3.c

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

> >> /* { dg-do compile { target { ! ia32 } } } */

> >> +/* { dg-require-effective-target mfentry } */

> >> /* { dg-options "-pg -mfentry -minstrument-return=call" } */

> >> /* { dg-final { scan-assembler-not "call.*__return__" } } */

> >>

> >> diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp

> >> index 3bd6e81..a153366 100644

> >> --- a/gcc/testsuite/lib/target-supports.exp

> >> +++ b/gcc/testsuite/lib/target-supports.exp

> >> @@ -9359,3 +9359,17 @@ proc check_effective_target_llvm_binutils { } {

> >>              expr { [istarget amdgcn*-*-*]

> >>                     || [check_effective_target_offload_gcn] }}]

> >> }

> >> +

> >> +# Return 1 if the compiler supports '-mfentry'.

> >> +

> >> +proc check_effective_target_mfentry { } {

> >> +    return [check_cached_effective_target mentry_available {

> >> +        if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {

> >> +           return 0

> >

> > expr 0

> >

> >> +        } else {

> >> +            return [check_no_compiler_messages mfentry object {

> >

> > no "return" here.

> >

> >> +               void foo (void) { }

> >> +            } "-mfentry"]

> >> +        }

> >> +    }]

> >> +}

>

Patch

diff --git a/gcc/config/i386/darwin.h b/gcc/config/i386/darwin.h
index fe11ec9..1128428 100644
--- a/gcc/config/i386/darwin.h
+++ b/gcc/config/i386/darwin.h
@@ -132,7 +132,8 @@  extern int darwin_emit_branch_islands;
 #define CC1_SPEC "%(cc1_cpu) \
   %{!mkernel:%{!static:%{!mdynamic-no-pic:-fPIC}}} \
   %{g: %{!fno-eliminate-unused-debug-symbols: -feliminate-unused-debug-symbols }} \
-  %{mx32:%eDarwin is not an mx32 platform}" \
+  %{mx32:%eDarwin is not an mx32 platform} \
+  %{mfentry*:%eDarwin does not support -mfentry or associated options}" \
   DARWIN_CC1_SPEC
 
 #undef ASM_SPEC
diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index cf12d74..546af7f 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -2382,6 +2382,10 @@  Target supports compiling @code{aes} instructions.
 @item fma4
 Target supports compiling @code{fma4} instructions.
 
+@item mfentry
+Target supports the @code{-mfentry} option that alters the
+position of profiling calls such that they precede the prologue.
+
 @item ms_hook_prologue
 Target supports attribute @code{ms_hook_prologue}.
 
diff --git a/gcc/testsuite/gcc.target/i386/fentry-override.c b/gcc/testsuite/gcc.target/i386/fentry-override.c
index 7bc5fc4..efba1bf 100644
--- a/gcc/testsuite/gcc.target/i386/fentry-override.c
+++ b/gcc/testsuite/gcc.target/i386/fentry-override.c
@@ -1,5 +1,6 @@ 
 /* Test -mfentry override */
 /* { dg-do compile { target { *-*-linux* && { ! ia32 } } } } */
+/* { dg-require-effective-target mfentry } */
 /* { dg-options "-mfentry" } */
 /* { dg-final { scan-assembler-not "__fentry__" } } */
 /* Origin: Andi Kleen */
diff --git a/gcc/testsuite/gcc.target/i386/fentry.c b/gcc/testsuite/gcc.target/i386/fentry.c
index 2449e75..28edd10 100644
--- a/gcc/testsuite/gcc.target/i386/fentry.c
+++ b/gcc/testsuite/gcc.target/i386/fentry.c
@@ -1,5 +1,6 @@ 
 /* Test -mfentry */
 /* { dg-do compile { target { *-*-linux* && { ! ia32 } } } } */
+/* { dg-require-effective-target mfentry } */
 /* { dg-options "-fprofile -mfentry" } */
 /* { dg-final { scan-assembler "__fentry__" } } */
 /* Origin: Andi Kleen */
diff --git a/gcc/testsuite/gcc.target/i386/fentryname1.c b/gcc/testsuite/gcc.target/i386/fentryname1.c
index 6d2e76d..1265342 100644
--- a/gcc/testsuite/gcc.target/i386/fentryname1.c
+++ b/gcc/testsuite/gcc.target/i386/fentryname1.c
@@ -1,4 +1,5 @@ 
 /* { dg-do compile } */
+/* { dg-require-effective-target mfentry } */
 /* { dg-options "-pg -mfentry -mfentry-name=foo" } */
 /* { dg-final { scan-assembler "call.*foo" } } */
 /* { dg-final { scan-assembler "call.*bar" } } */
diff --git a/gcc/testsuite/gcc.target/i386/fentryname2.c b/gcc/testsuite/gcc.target/i386/fentryname2.c
index 7d102bf..c51c5d1 100644
--- a/gcc/testsuite/gcc.target/i386/fentryname2.c
+++ b/gcc/testsuite/gcc.target/i386/fentryname2.c
@@ -1,4 +1,5 @@ 
 /* { dg-do compile } */
+/* { dg-require-effective-target mfentry } */
 /* { dg-options "-pg -mfentry -mrecord-mcount -mfentry-section=foo" } */
 /* { dg-final { scan-assembler "section.*foo" } } */
 /* { dg-final { scan-assembler "section.*bar" } } */
diff --git a/gcc/testsuite/gcc.target/i386/fentryname3.c b/gcc/testsuite/gcc.target/i386/fentryname3.c
index 777f4e4..5688109 100644
--- a/gcc/testsuite/gcc.target/i386/fentryname3.c
+++ b/gcc/testsuite/gcc.target/i386/fentryname3.c
@@ -1,4 +1,5 @@ 
 /* { dg-do compile } */
+/* { dg-require-effective-target mfentry } */
 /* { dg-options "-pg -mfentry"  } */
 /* { dg-final { scan-assembler "section.*__entry_loc" } } */
 /* { dg-final { scan-assembler "0x0f, 0x1f, 0x44, 0x00, 0x00" } } */
diff --git a/gcc/testsuite/gcc.target/i386/nop-mcount.c b/gcc/testsuite/gcc.target/i386/nop-mcount.c
index a8e14bc..a5f8d27 100644
--- a/gcc/testsuite/gcc.target/i386/nop-mcount.c
+++ b/gcc/testsuite/gcc.target/i386/nop-mcount.c
@@ -1,5 +1,6 @@ 
 /* Test -mnop-mcount */
 /* { dg-do compile { target { *-*-linux* && nonpic } } } */
+/* { dg-require-effective-target mfentry } */
 /* { dg-options "-pg -mfentry -mrecord-mcount -mnop-mcount" } */
 /* { dg-final { scan-assembler-not "__fentry__" } } */
 /* Origin: Andi Kleen */
diff --git a/gcc/testsuite/gcc.target/i386/pr82699-2.c b/gcc/testsuite/gcc.target/i386/pr82699-2.c
index 07a4ccb..c43cf44 100644
--- a/gcc/testsuite/gcc.target/i386/pr82699-2.c
+++ b/gcc/testsuite/gcc.target/i386/pr82699-2.c
@@ -1,4 +1,5 @@ 
 /* { dg-do compile { target *-*-linux* } } */
+/* { dg-require-effective-target mfentry } */
 /* { dg-options "-O2 -fno-pic -fcf-protection -pg -mfentry -fasynchronous-unwind-tables" } */
 /* { dg-final { scan-assembler-times {\t\.cfi_startproc\n\tendbr} 1 } } */
 
diff --git a/gcc/testsuite/gcc.target/i386/pr82699-4.c b/gcc/testsuite/gcc.target/i386/pr82699-4.c
index 3cc03db..719566b 100644
--- a/gcc/testsuite/gcc.target/i386/pr82699-4.c
+++ b/gcc/testsuite/gcc.target/i386/pr82699-4.c
@@ -1,4 +1,5 @@ 
 /* { dg-do compile { target { *-*-linux* && { ! ia32 } } } } */
+/* { dg-require-effective-target mfentry } */
 /* { dg-options "-O2 -fpic -fcf-protection -pg -mfentry -fasynchronous-unwind-tables" } */
 /* { dg-final { scan-assembler-times {\t\.cfi_startproc\n\tendbr} 1 } } */
 
diff --git a/gcc/testsuite/gcc.target/i386/pr82699-5.c b/gcc/testsuite/gcc.target/i386/pr82699-5.c
index 0c547e2..ac3c1ae 100644
--- a/gcc/testsuite/gcc.target/i386/pr82699-5.c
+++ b/gcc/testsuite/gcc.target/i386/pr82699-5.c
@@ -1,4 +1,5 @@ 
 /* { dg-do compile { target *-*-linux* } } */
+/* { dg-require-effective-target mfentry } */
 /* { dg-options "-O2 -fcf-protection -mfentry -fasynchronous-unwind-tables" } */
 /* { dg-additional-options "-fno-pic" { target ia32 } } */
 /* { dg-final { scan-assembler-times {\t\.cfi_startproc\n\tendbr} 1 } } */
diff --git a/gcc/testsuite/gcc.target/i386/pr82699-6.c b/gcc/testsuite/gcc.target/i386/pr82699-6.c
index ff6bae7..0b595f4 100644
--- a/gcc/testsuite/gcc.target/i386/pr82699-6.c
+++ b/gcc/testsuite/gcc.target/i386/pr82699-6.c
@@ -1,4 +1,5 @@ 
 /* { dg-do compile { target *-*-linux* } } */
+/* { dg-require-effective-target mfentry } */
 /* { dg-options "-fno-pic -O2 -fcf-protection -pg -mfentry -mrecord-mcount -mnop-mcount -fasynchronous-unwind-tables" } */
 /* { dg-final { scan-assembler-times {\t\.cfi_startproc\n\tendbr} 1 } } */
 
diff --git a/gcc/testsuite/gcc.target/i386/returninst1.c b/gcc/testsuite/gcc.target/i386/returninst1.c
index d7ecc41..133fdee 100644
--- a/gcc/testsuite/gcc.target/i386/returninst1.c
+++ b/gcc/testsuite/gcc.target/i386/returninst1.c
@@ -1,4 +1,5 @@ 
 /* { dg-do compile { target { ! ia32 } } } */
+/* { dg-require-effective-target mfentry } */
 /* { dg-options "-pg -mfentry -minstrument-return=call -mrecord-return" } */
 /* { dg-final { scan-assembler "call.*__return__" } } */
 /* { dg-final { scan-assembler "section.*return_loc" } } */
diff --git a/gcc/testsuite/gcc.target/i386/returninst2.c b/gcc/testsuite/gcc.target/i386/returninst2.c
index 4724b40..3629310 100644
--- a/gcc/testsuite/gcc.target/i386/returninst2.c
+++ b/gcc/testsuite/gcc.target/i386/returninst2.c
@@ -1,4 +1,5 @@ 
 /* { dg-do compile { target { ! ia32 } } } */
+/* { dg-require-effective-target mfentry } */
 /* { dg-options "-pg -mfentry -minstrument-return=nop5 -mrecord-return" } */
 /* { dg-final { scan-assembler-times "0x0f, 0x1f, 0x44, 0x00, 0x00" 3 } } */
 /* { dg-final { scan-assembler "section.*return_loc" } } */
diff --git a/gcc/testsuite/gcc.target/i386/returninst3.c b/gcc/testsuite/gcc.target/i386/returninst3.c
index 14b4445..b84cc77 100644
--- a/gcc/testsuite/gcc.target/i386/returninst3.c
+++ b/gcc/testsuite/gcc.target/i386/returninst3.c
@@ -1,4 +1,5 @@ 
 /* { dg-do compile { target { ! ia32 } } } */
+/* { dg-require-effective-target mfentry } */
 /* { dg-options "-pg -mfentry -minstrument-return=call" } */
 /* { dg-final { scan-assembler-not "call.*__return__" } } */
 
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index 3bd6e81..a153366 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -9359,3 +9359,17 @@  proc check_effective_target_llvm_binutils { } {
 	      expr { [istarget amdgcn*-*-*]
 		     || [check_effective_target_offload_gcn] }}]
 }
+
+# Return 1 if the compiler supports '-mfentry'.
+
+proc check_effective_target_mfentry { } {
+    return [check_cached_effective_target mentry_available {
+        if { !([istarget i?86-*-*] || [istarget x86_64-*-*]) } {
+	    return 0
+        } else {
+            return [check_no_compiler_messages mfentry object {
+	        void foo (void) { }
+            } "-mfentry"]
+        }
+    }]
+}