Re: [PATCH v12] add -fpatchable-function-entry=N,M option

2017-08-01 Thread Andreas Schwab
On Aug 01 2017, Maxim Kuvyrkov  wrote:

> Do you know a reliable way of checking whether target can issue nops in 
> simple code?

Try inspecting one of the rtl dumps.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


Re: [PATCH v12] add -fpatchable-function-entry=N,M option

2017-08-01 Thread Maxim Kuvyrkov
> On Aug 1, 2017, at 1:52 PM, Andreas Schwab  wrote:
> 
> On Aug 01 2017, Gerald Pfeifer  wrote:
> 
>> On Mon, 31 Jul 2017, Maxim Kuvyrkov wrote:
>>> I don't see an easy way to correctly differentiate between "attribute" 
>>> nops and "bundle" nops, so XFAILing these tests on ia64 seems like a 
>>> valid approach.
>> 
>> Make sense, given that the use of Itanium has gone done drastically.
> 
> You can get the same failure with any target, for example if there are
> delay slots to be filled.

Andreas,

Do you know a reliable way of checking whether target can issue nops in simple 
code?

One alternative would be to apply testcase only to white-listed architectures, 
which is, imo, less preferable.

Regards,

--
Maxim Kuvyrkov
www.linaro.org


Re: [PATCH v12] add -fpatchable-function-entry=N,M option

2017-08-01 Thread Andreas Schwab
On Aug 01 2017, Gerald Pfeifer  wrote:

> On Mon, 31 Jul 2017, Maxim Kuvyrkov wrote:
>> I don't see an easy way to correctly differentiate between "attribute" 
>> nops and "bundle" nops, so XFAILing these tests on ia64 seems like a 
>> valid approach.
>
> Make sense, given that the use of Itanium has gone done drastically.

You can get the same failure with any target, for example if there are
delay slots to be filled.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


Re: [PATCH v12] add -fpatchable-function-entry=N,M option

2017-08-01 Thread Gerald Pfeifer
On Mon, 31 Jul 2017, Maxim Kuvyrkov wrote:
> I don't see an easy way to correctly differentiate between "attribute" 
> nops and "bundle" nops, so XFAILing these tests on ia64 seems like a 
> valid approach.

Make sense, given that the use of Itanium has gone done drastically.

Gerald


Re: [PATCH v12] add -fpatchable-function-entry=N,M option

2017-07-31 Thread Maxim Kuvyrkov
On Jul 26, 2017, at 5:33 PM, Andreas Schwab  wrote:
> 
> On Jul 26 2017, Torsten Duwe  wrote:
> 
>> On Wed, Jul 26, 2017 at 04:16:25PM +0200, Andreas Schwab wrote:
>>> On Jul 07 2017, Torsten Duwe  wrote:
>>> 
 diff --git a/gcc/testsuite/c-c++-common/patchable_function_entry-decl.c 
 b/gcc/testsuite/c-c++-common/patchable_function_entry-decl.c
 new file mode 100644
 index 000..8514b10e820
 --- /dev/null
 +++ b/gcc/testsuite/c-c++-common/patchable_function_entry-decl.c
 @@ -0,0 +1,16 @@
 +/* { dg-do compile } */
 +/* { dg-options "-O2 -fpatchable-function-entry=3,1" } */
 +/* { dg-final { scan-assembler-times "nop" 2 } } */
>>> 
>>> This fails on ia64.
>> 
>> The solution is fairly obvious: on architectures where the nop is not called
>> "nop" provide a custom, cpu-specific test, or document the failure.
> 
> But on ia64, a nop _is_ called nop.

The problem here is that ia64 backend emits "nop" instructions to pad IA64 
bundles.  The 2 nops at the beginning are [as expected] from the patchable 
attribute, but [unexpected] nops after ld8.mov and before "add r8" are 
generated by ia64 bundle packing.

nop 0
nop 0
.prologue
.body
.mmi
addl r14 = @ltoffx(a#), r1
;;
ld8.mov r14 = [r14], a#
nop 0
;;
.mmi
ld4 r14 = [r14]
;;
shladd r8 = r14, 2, r0
nop 0
;;
.mib
nop 0
add r8 = r8, r14
br.ret.sptk.many b0

I don't see an easy way to correctly differentiate between "attribute" nops and 
"bundle" nops, so XFAILing these tests on ia64 seems like a valid approach.

I speculate that other tests fail on ia64 for the same reason, but I didn't 
check.

--
Maxim Kuvyrkov
www.linaro.org





Re: [PATCH v12] add -fpatchable-function-entry=N,M option

2017-07-26 Thread Andreas Schwab
On Jul 26 2017, Torsten Duwe  wrote:

> On Wed, Jul 26, 2017 at 04:16:25PM +0200, Andreas Schwab wrote:
>> On Jul 07 2017, Torsten Duwe  wrote:
>> 
>> > diff --git a/gcc/testsuite/c-c++-common/patchable_function_entry-decl.c 
>> > b/gcc/testsuite/c-c++-common/patchable_function_entry-decl.c
>> > new file mode 100644
>> > index 000..8514b10e820
>> > --- /dev/null
>> > +++ b/gcc/testsuite/c-c++-common/patchable_function_entry-decl.c
>> > @@ -0,0 +1,16 @@
>> > +/* { dg-do compile } */
>> > +/* { dg-options "-O2 -fpatchable-function-entry=3,1" } */
>> > +/* { dg-final { scan-assembler-times "nop" 2 } } */
>> 
>> This fails on ia64.
>
> The solution is fairly obvious: on architectures where the nop is not called
> "nop" provide a custom, cpu-specific test, or document the failure.

But on ia64, a nop _is_ called nop.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


Re: [PATCH v12] add -fpatchable-function-entry=N,M option

2017-07-26 Thread Torsten Duwe
On Wed, Jul 26, 2017 at 04:16:25PM +0200, Andreas Schwab wrote:
> On Jul 07 2017, Torsten Duwe  wrote:
> 
> > diff --git a/gcc/testsuite/c-c++-common/patchable_function_entry-decl.c 
> > b/gcc/testsuite/c-c++-common/patchable_function_entry-decl.c
> > new file mode 100644
> > index 000..8514b10e820
> > --- /dev/null
> > +++ b/gcc/testsuite/c-c++-common/patchable_function_entry-decl.c
> > @@ -0,0 +1,16 @@
> > +/* { dg-do compile } */
> > +/* { dg-options "-O2 -fpatchable-function-entry=3,1" } */
> > +/* { dg-final { scan-assembler-times "nop" 2 } } */
> 
> This fails on ia64.

The solution is fairly obvious: on architectures where the nop is not called
"nop" provide a custom, cpu-specific test, or document the failure.

Torsten



Re: [PATCH v12] add -fpatchable-function-entry=N,M option

2017-07-26 Thread Andreas Schwab
On Jul 07 2017, Torsten Duwe  wrote:

> diff --git a/gcc/testsuite/c-c++-common/patchable_function_entry-decl.c 
> b/gcc/testsuite/c-c++-common/patchable_function_entry-decl.c
> new file mode 100644
> index 000..8514b10e820
> --- /dev/null
> +++ b/gcc/testsuite/c-c++-common/patchable_function_entry-decl.c
> @@ -0,0 +1,16 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fpatchable-function-entry=3,1" } */
> +/* { dg-final { scan-assembler-times "nop" 2 } } */

This fails on ia64.

> diff --git a/gcc/testsuite/c-c++-common/patchable_function_entry-default.c 
> b/gcc/testsuite/c-c++-common/patchable_function_entry-default.c
> new file mode 100644
> index 000..0dcf1181dde
> --- /dev/null
> +++ b/gcc/testsuite/c-c++-common/patchable_function_entry-default.c
> @@ -0,0 +1,16 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fpatchable-function-entry=3,1" } */
> +/* { dg-final { scan-assembler-times "nop" 3 } } */

Likewise.

> diff --git a/gcc/testsuite/c-c++-common/patchable_function_entry-definition.c 
> b/gcc/testsuite/c-c++-common/patchable_function_entry-definition.c
> new file mode 100644
> index 000..a007867dcb0
> --- /dev/null
> +++ b/gcc/testsuite/c-c++-common/patchable_function_entry-definition.c
> @@ -0,0 +1,16 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fpatchable-function-entry=3,1" } */
> +/* { dg-final { scan-assembler-times "nop" 1 } } */

Likewise.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


Re: [PATCH v12] add -fpatchable-function-entry=N,M option

2017-07-25 Thread Torsten Duwe
On Tue, Jul 25, 2017 at 10:12:00AM +0300, Maxim Kuvyrkov wrote:
> > 
> > SuSe/Novell choose to do its assignments per engineer, not for the whole 
> > company, so I don't think you are covered as is.
> 
> Torsten, any update on which way you are going to handle copyright assignment 
> -- apply for a new one or have one of your SuSe colleagues commit under 
> theirs?

I have checked with our GCC guys and the code is covered by our
company assignment. So it's safe to commit.

Torsten



Re: [PATCH v12] add -fpatchable-function-entry=N,M option

2017-07-25 Thread Torsten Duwe
On Tue, Jul 25, 2017 at 10:12:00AM +0300, Maxim Kuvyrkov wrote:
> 
> I confirmed that bootstrap and reg test on x86_64-linux-gnu and 
> aarch64-linux-gnu are OK.

Thanks a lot!

> Torsten, any update on which way you are going to handle copyright assignment 
> -- apply for a new one or have one of your SuSe colleagues commit under 
> theirs?

AFAIU all this code is "Copyright (C) 2016,2017 SUSE Linux GmbH", just
exactly like e.g. Richard B.'s code, but IANAL. I'll find out the details.
Thanks so far!

Torsten



Re: [PATCH v12] add -fpatchable-function-entry=N,M option

2017-07-25 Thread Maxim Kuvyrkov
> On Jul 20, 2017, at 4:12 PM, Maxim Kuvyrkov  wrote:
> 
>> On Jul 20, 2017, at 3:06 PM, Torsten Duwe  wrote:
>> 
>> On Thu, Jul 20, 2017 at 01:58:06PM +0300, Maxim Kuvyrkov wrote:
 On Jul 17, 2017, at 3:10 PM, Torsten Duwe  wrote:
 
 What is the next step now? Is anybody going to commit that patch?
>>> 
>>> Torsten, if you prefer I can commit your patch (after bootstrap and a 
>>> regtest on aarch64-linux-gnu and x86_64-linux-gnu).
>> 
>> Ok, who is going to do that?
> 
> I'll do that, np.

I confirmed that bootstrap and reg test on x86_64-linux-gnu and 
aarch64-linux-gnu are OK.

> 
>> 
>>> There is one last hurdle to sort out with the FSF copyright assignment.  
>>> Looking at FSF's list I don't see SuSe's copyright assignment for your 
>>> contributions to FSF projects, of which GCC is one.  You can either request 
>>> SuSe to file a copyright assignment for you, or, probably simpler, ask one 
>>> of your SuSe colleagues (Richard B., Jan H.) to commit under their 
>>> assignment.
>> 
>> From my understanding, it should not make a difference, as the copyright
>> owner is identical (SUSE). But I'm not going to argue on legal issues here.
>> Let's first see what the test outcome is. Thanks so far!
> 
> SuSe/Novell choose to do its assignments per engineer, not for the whole 
> company, so I don't think you are covered as is.

Torsten, any update on which way you are going to handle copyright assignment 
-- apply for a new one or have one of your SuSe colleagues commit under theirs?

--
Maxim Kuvyrkov
www.linaro.org




Re: [PATCH v12] add -fpatchable-function-entry=N,M option

2017-07-20 Thread Maxim Kuvyrkov
> On Jul 20, 2017, at 3:06 PM, Torsten Duwe  wrote:
> 
> On Thu, Jul 20, 2017 at 01:58:06PM +0300, Maxim Kuvyrkov wrote:
>>> On Jul 17, 2017, at 3:10 PM, Torsten Duwe  wrote:
>>> 
>>> What is the next step now? Is anybody going to commit that patch?
>> 
>> Torsten, if you prefer I can commit your patch (after bootstrap and a 
>> regtest on aarch64-linux-gnu and x86_64-linux-gnu).
> 
> Ok, who is going to do that?

I'll do that, np.

> 
>> There is one last hurdle to sort out with the FSF copyright assignment.  
>> Looking at FSF's list I don't see SuSe's copyright assignment for your 
>> contributions to FSF projects, of which GCC is one.  You can either request 
>> SuSe to file a copyright assignment for you, or, probably simpler, ask one 
>> of your SuSe colleagues (Richard B., Jan H.) to commit under their 
>> assignment.
> 
> From my understanding, it should not make a difference, as the copyright
> owner is identical (SUSE). But I'm not going to argue on legal issues here.
> Let's first see what the test outcome is. Thanks so far!

SuSe/Novell choose to do its assignments per engineer, not for the whole 
company, so I don't think you are covered as is.

--
Maxim Kuvyrkov
www.linaro.org



Re: [PATCH v12] add -fpatchable-function-entry=N,M option

2017-07-20 Thread Torsten Duwe
On Thu, Jul 20, 2017 at 01:58:06PM +0300, Maxim Kuvyrkov wrote:
> > On Jul 17, 2017, at 3:10 PM, Torsten Duwe  wrote:
> > 
> > What is the next step now? Is anybody going to commit that patch?
> 
> Torsten, if you prefer I can commit your patch (after bootstrap and a regtest 
> on aarch64-linux-gnu and x86_64-linux-gnu).

Ok, who is going to do that?

> There is one last hurdle to sort out with the FSF copyright assignment.  
> Looking at FSF's list I don't see SuSe's copyright assignment for your 
> contributions to FSF projects, of which GCC is one.  You can either request 
> SuSe to file a copyright assignment for you, or, probably simpler, ask one of 
> your SuSe colleagues (Richard B., Jan H.) to commit under their assignment.

>From my understanding, it should not make a difference, as the copyright
owner is identical (SUSE). But I'm not going to argue on legal issues here.
Let's first see what the test outcome is. Thanks so far!

Torsten



Re: [PATCH v12] add -fpatchable-function-entry=N,M option

2017-07-20 Thread Maxim Kuvyrkov
> On Jul 17, 2017, at 3:10 PM, Torsten Duwe  wrote:
> 
> What is the next step now? Is anybody going to commit that patch?
> 
>   Torsten
> 
> On Fri, Jul 07, 2017 at 02:57:55PM +0100, Richard Earnshaw (lists) wrote:
>> On 06/07/17 15:03, Torsten Duwe wrote:
>> +#if TARGET_HAVE_NAMED_SECTIONS
> 
> No, this is a hook.  You need to test targetm_common.have_named_sections.
> 
> OK with that change.

Torsten, if you prefer I can commit your patch (after bootstrap and a regtest 
on aarch64-linux-gnu and x86_64-linux-gnu).

There is one last hurdle to sort out with the FSF copyright assignment.  
Looking at FSF's list I don't see SuSe's copyright assignment for your 
contributions to FSF projects, of which GCC is one.  You can either request 
SuSe to file a copyright assignment for you, or, probably simpler, ask one of 
your SuSe colleagues (Richard B., Jan H.) to commit under their assignment.

--
Maxim Kuvyrkov
www.linaro.org


> 
> R.
> 
> On Fri, Jul 07, 2017 at 09:30:28PM +0200, Torsten Duwe wrote:
>> Change since v11:
>> 
>> < +#if TARGET_HAVE_NAMED_SECTIONS
>> 
>>> +  if (record_p && targetm_common.have_named_sections)
>> 
>> (plus > +#include "common/common-target.h" )
>> 
>>  Torsten
>> 
>> 
>> gcc/c-family/ChangeLog
>> 2017-07-07  Torsten Duwe  
>> 
>>  * c-attribs.c (c_common_attribute_table): Add entry for
>>  "patchable_function_entry".
>> 
>> gcc/lto/ChangeLog
>> 2017-07-07  Torsten Duwe  
>> 
>>  * lto-lang.c (lto_attribute_table): Add entry for
>>  "patchable_function_entry".
>> 
>> gcc/ChangeLog
>> 2017-07-07  Torsten Duwe  
>> 
>>  * common.opt: Introduce -fpatchable-function-entry
>>  command line option, and its variables function_entry_patch_area_size
>>  and function_entry_patch_area_start.
>>  * opts.c (common_handle_option): Add -fpatchable_function_entry_ case,
>>  including a two-value parser.
>>  * target.def (print_patchable_function_entry): New target hook.
>>  * targhooks.h (default_print_patchable_function_entry): New function.
>>  * targhooks.c (default_print_patchable_function_entry): Likewise.
>>  * toplev.c (process_options): Switch off IPA-RA if
>>  patchable function entries are being generated.
>>  * varasm.c (assemble_start_function): Look at the
>>  patchable-function-entry command line switch and current
>>  function attributes and maybe generate NOP instructions by
>>  calling the print_patchable_function_entry hook.
>>  * doc/extend.texi: Document patchable_function_entry attribute.
>>  * doc/invoke.texi: Document -fpatchable_function_entry
>>  command line option.
>>  * doc/tm.texi.in (TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY):
>>  New target hook.
>>  * doc/tm.texi: Likewise.
>> 
>> gcc/testsuite/ChangeLog
>> 2017-07-07  Torsten Duwe  
>> 
>>  * c-c++-common/patchable_function_entry-default.c: New test.
>>  * c-c++-common/patchable_function_entry-decl.c: Likewise.
>>  * c-c++-common/patchable_function_entry-definition.c: Likewise.
>> 
>> diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
>> index 626ffa1cde7..ecb00c1d5b9 100644
>> --- a/gcc/c-family/c-attribs.c
>> +++ b/gcc/c-family/c-attribs.c
>> @@ -142,6 +142,8 @@ static tree handle_bnd_variable_size_attribute (tree *, 
>> tree, tree, int, bool *)
>> static tree handle_bnd_legacy (tree *, tree, tree, int, bool *);
>> static tree handle_bnd_instrument (tree *, tree, tree, int, bool *);
>> static tree handle_fallthrough_attribute (tree *, tree, tree, int, bool *);
>> +static tree handle_patchable_function_entry_attribute (tree *, tree, tree,
>> +   int, bool *);
>> 
>> /* Table of machine-independent attributes common to all C-like languages.
>> 
>> @@ -351,6 +353,9 @@ const struct attribute_spec c_common_attribute_table[] =
>>handle_bnd_instrument, false },
>>   { "fallthrough", 0, 0, false, false, false,
>>handle_fallthrough_attribute, false },
>> +  { "patchable_function_entry", 1, 2, true, false, false,
>> +  handle_patchable_function_entry_attribute,
>> +  false },
>>   { NULL, 0, 0, false, false, false, NULL, false }
>> };
>> 
>> @@ -3260,3 +3265,10 @@ handle_fallthrough_attribute (tree *, tree name, 
>> tree, int,
>>   *no_add_attrs = true;
>>   return NULL_TREE;
>> }
>> +
>> +static tree
>> +handle_patchable_function_entry_attribute (tree *, tree, tree, int, bool *)
>> +{
>> +  /* Nothing to be done here.  */
>> +  return NULL_TREE;
>> +}
>> diff --git a/gcc/common.opt b/gcc/common.opt
>> index e81165c488b..78cfa568a95 100644
>> --- a/gcc/common.opt
>> +++ b/gcc/common.opt
>> @@ -163,6 +163,13 @@ bool flag_stack_usage_info = false
>> Variable
>> int flag_debug_asm
>> 
>> +; How many NOP insns to place at each function entry by 

Re: [PATCH v12] add -fpatchable-function-entry=N,M option

2017-07-17 Thread Torsten Duwe
What is the next step now? Is anybody going to commit that patch?

Torsten

On Fri, Jul 07, 2017 at 02:57:55PM +0100, Richard Earnshaw (lists) wrote:
> On 06/07/17 15:03, Torsten Duwe wrote:
> +#if TARGET_HAVE_NAMED_SECTIONS

No, this is a hook.  You need to test targetm_common.have_named_sections.

OK with that change.

R.

On Fri, Jul 07, 2017 at 09:30:28PM +0200, Torsten Duwe wrote:
> Change since v11:
> 
> < +#if TARGET_HAVE_NAMED_SECTIONS
> 
> > +  if (record_p && targetm_common.have_named_sections)
> 
> (plus > +#include "common/common-target.h" )
> 
>   Torsten
> 
> 
> gcc/c-family/ChangeLog
> 2017-07-07  Torsten Duwe  
> 
>   * c-attribs.c (c_common_attribute_table): Add entry for
>   "patchable_function_entry".
> 
> gcc/lto/ChangeLog
> 2017-07-07  Torsten Duwe  
> 
>   * lto-lang.c (lto_attribute_table): Add entry for
>   "patchable_function_entry".
> 
> gcc/ChangeLog
> 2017-07-07  Torsten Duwe  
> 
>   * common.opt: Introduce -fpatchable-function-entry
>   command line option, and its variables function_entry_patch_area_size
>   and function_entry_patch_area_start.
>   * opts.c (common_handle_option): Add -fpatchable_function_entry_ case,
>   including a two-value parser.
>   * target.def (print_patchable_function_entry): New target hook.
>   * targhooks.h (default_print_patchable_function_entry): New function.
>   * targhooks.c (default_print_patchable_function_entry): Likewise.
>   * toplev.c (process_options): Switch off IPA-RA if
>   patchable function entries are being generated.
>   * varasm.c (assemble_start_function): Look at the
>   patchable-function-entry command line switch and current
>   function attributes and maybe generate NOP instructions by
>   calling the print_patchable_function_entry hook.
>   * doc/extend.texi: Document patchable_function_entry attribute.
>   * doc/invoke.texi: Document -fpatchable_function_entry
>   command line option.
>   * doc/tm.texi.in (TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY):
>   New target hook.
>   * doc/tm.texi: Likewise.
> 
> gcc/testsuite/ChangeLog
> 2017-07-07  Torsten Duwe  
> 
>   * c-c++-common/patchable_function_entry-default.c: New test.
>   * c-c++-common/patchable_function_entry-decl.c: Likewise.
>   * c-c++-common/patchable_function_entry-definition.c: Likewise.
> 
> diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
> index 626ffa1cde7..ecb00c1d5b9 100644
> --- a/gcc/c-family/c-attribs.c
> +++ b/gcc/c-family/c-attribs.c
> @@ -142,6 +142,8 @@ static tree handle_bnd_variable_size_attribute (tree *, 
> tree, tree, int, bool *)
>  static tree handle_bnd_legacy (tree *, tree, tree, int, bool *);
>  static tree handle_bnd_instrument (tree *, tree, tree, int, bool *);
>  static tree handle_fallthrough_attribute (tree *, tree, tree, int, bool *);
> +static tree handle_patchable_function_entry_attribute (tree *, tree, tree,
> +int, bool *);
>  
>  /* Table of machine-independent attributes common to all C-like languages.
>  
> @@ -351,6 +353,9 @@ const struct attribute_spec c_common_attribute_table[] =
> handle_bnd_instrument, false },
>{ "fallthrough", 0, 0, false, false, false,
> handle_fallthrough_attribute, false },
> +  { "patchable_function_entry",  1, 2, true, false, false,
> +   handle_patchable_function_entry_attribute,
> +   false },
>{ NULL, 0, 0, false, false, false, NULL, false }
>  };
>  
> @@ -3260,3 +3265,10 @@ handle_fallthrough_attribute (tree *, tree name, tree, 
> int,
>*no_add_attrs = true;
>return NULL_TREE;
>  }
> +
> +static tree
> +handle_patchable_function_entry_attribute (tree *, tree, tree, int, bool *)
> +{
> +  /* Nothing to be done here.  */
> +  return NULL_TREE;
> +}
> diff --git a/gcc/common.opt b/gcc/common.opt
> index e81165c488b..78cfa568a95 100644
> --- a/gcc/common.opt
> +++ b/gcc/common.opt
> @@ -163,6 +163,13 @@ bool flag_stack_usage_info = false
>  Variable
>  int flag_debug_asm
>  
> +; How many NOP insns to place at each function entry by default
> +Variable
> +HOST_WIDE_INT function_entry_patch_area_size
> +
> +; And how far the real asm entry point is into this area
> +Variable
> +HOST_WIDE_INT function_entry_patch_area_start
>  
>  ; Balance between GNAT encodings and standard DWARF to emit.
>  Variable
> @@ -2030,6 +2037,10 @@ fprofile-reorder-functions
>  Common Report Var(flag_profile_reorder_functions)
>  Enable function reordering that improves code placement.
>  
> +fpatchable-function-entry=
> +Common Joined Optimization
> +Insert NOP instructions at each function entry.
> +
>  frandom-seed
>  Common Var(common_deferred_options) Defer
>  
> diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
> 

[PATCH v12] add -fpatchable-function-entry=N,M option

2017-07-07 Thread Torsten Duwe
Change since v11:

< +#if TARGET_HAVE_NAMED_SECTIONS

> +  if (record_p && targetm_common.have_named_sections)

(plus > +#include "common/common-target.h" )

Torsten


gcc/c-family/ChangeLog
2017-07-07  Torsten Duwe  

* c-attribs.c (c_common_attribute_table): Add entry for
"patchable_function_entry".

gcc/lto/ChangeLog
2017-07-07  Torsten Duwe  

* lto-lang.c (lto_attribute_table): Add entry for
"patchable_function_entry".

gcc/ChangeLog
2017-07-07  Torsten Duwe  

* common.opt: Introduce -fpatchable-function-entry
command line option, and its variables function_entry_patch_area_size
and function_entry_patch_area_start.
* opts.c (common_handle_option): Add -fpatchable_function_entry_ case,
including a two-value parser.
* target.def (print_patchable_function_entry): New target hook.
* targhooks.h (default_print_patchable_function_entry): New function.
* targhooks.c (default_print_patchable_function_entry): Likewise.
* toplev.c (process_options): Switch off IPA-RA if
patchable function entries are being generated.
* varasm.c (assemble_start_function): Look at the
patchable-function-entry command line switch and current
function attributes and maybe generate NOP instructions by
calling the print_patchable_function_entry hook.
* doc/extend.texi: Document patchable_function_entry attribute.
* doc/invoke.texi: Document -fpatchable_function_entry
command line option.
* doc/tm.texi.in (TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY):
New target hook.
* doc/tm.texi: Likewise.

gcc/testsuite/ChangeLog
2017-07-07  Torsten Duwe  

* c-c++-common/patchable_function_entry-default.c: New test.
* c-c++-common/patchable_function_entry-decl.c: Likewise.
* c-c++-common/patchable_function_entry-definition.c: Likewise.

diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
index 626ffa1cde7..ecb00c1d5b9 100644
--- a/gcc/c-family/c-attribs.c
+++ b/gcc/c-family/c-attribs.c
@@ -142,6 +142,8 @@ static tree handle_bnd_variable_size_attribute (tree *, 
tree, tree, int, bool *)
 static tree handle_bnd_legacy (tree *, tree, tree, int, bool *);
 static tree handle_bnd_instrument (tree *, tree, tree, int, bool *);
 static tree handle_fallthrough_attribute (tree *, tree, tree, int, bool *);
+static tree handle_patchable_function_entry_attribute (tree *, tree, tree,
+  int, bool *);
 
 /* Table of machine-independent attributes common to all C-like languages.
 
@@ -351,6 +353,9 @@ const struct attribute_spec c_common_attribute_table[] =
  handle_bnd_instrument, false },
   { "fallthrough",   0, 0, false, false, false,
  handle_fallthrough_attribute, false },
+  { "patchable_function_entry",1, 2, true, false, false,
+ handle_patchable_function_entry_attribute,
+ false },
   { NULL, 0, 0, false, false, false, NULL, false }
 };
 
@@ -3260,3 +3265,10 @@ handle_fallthrough_attribute (tree *, tree name, tree, 
int,
   *no_add_attrs = true;
   return NULL_TREE;
 }
+
+static tree
+handle_patchable_function_entry_attribute (tree *, tree, tree, int, bool *)
+{
+  /* Nothing to be done here.  */
+  return NULL_TREE;
+}
diff --git a/gcc/common.opt b/gcc/common.opt
index e81165c488b..78cfa568a95 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -163,6 +163,13 @@ bool flag_stack_usage_info = false
 Variable
 int flag_debug_asm
 
+; How many NOP insns to place at each function entry by default
+Variable
+HOST_WIDE_INT function_entry_patch_area_size
+
+; And how far the real asm entry point is into this area
+Variable
+HOST_WIDE_INT function_entry_patch_area_start
 
 ; Balance between GNAT encodings and standard DWARF to emit.
 Variable
@@ -2030,6 +2037,10 @@ fprofile-reorder-functions
 Common Report Var(flag_profile_reorder_functions)
 Enable function reordering that improves code placement.
 
+fpatchable-function-entry=
+Common Joined Optimization
+Insert NOP instructions at each function entry.
+
 frandom-seed
 Common Var(common_deferred_options) Defer
 
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 5cb512fe575..9c171abc121 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -3105,6 +3105,27 @@ that affect more than one function.
 This attribute should be used for debugging purposes only.  It is not
 suitable in production code.
 
+@item patchable_function_entry
+@cindex @code{patchable_function_entry} function attribute
+@cindex extra NOP instructions at the function entry point
+In case the target's text segment can be made writable at run time by
+any means, padding the function entry with a number of NOPs can be
+used to provide a universal