On Sun, Jan 14, 2018 at 2:48 AM, Jan Hubicka <hubi...@ucw.cz> wrote: >> Add -mfunction-return= option to convert function return to call and >> return thunks. The default is 'keep', which keeps function return >> unmodified. 'thunk' converts function return to call and return thunk. >> 'thunk-inline' converts function return to inlined call and return thunk. >> 'thunk-extern' converts function return to external call and return >> thunk provided in a separate object file. You can control this behavior >> for a specific function by using the function attribute function_return. >> >> Function return thunk is the same as memory thunk for -mindirect-branch= >> where the return address is at the top of the stack: >> >> __x86_return_thunk: >> call L2 >> L1: >> pause >> jmp L1 >> L2: >> lea 8(%rsp), %rsp|lea 4(%esp), %esp >> ret >> >> and function return becomes >> >> jmp __x86_return_thunk >> >> -mindirect-branch= tests are updated with -mfunction-return=keep to >> avoid false test failures when -mfunction-return=thunk is added to >> RUNTESTFLAGS for "make check". >> >> gcc/ >> >> * config/i386/i386-protos.h (ix86_output_function_return): New. >> * config/i386/i386.c (ix86_set_indirect_branch_type): Also >> set function_return_type. >> (indirect_thunk_name): Add ret_p to indicate thunk for function >> return. >> (output_indirect_thunk_function): Pass false to >> indirect_thunk_name. >> (ix86_output_indirect_branch): Likewise. >> (output_indirect_thunk_function): Create alias for function >> return thunk if regno < 0. >> (ix86_output_function_return): New function. >> (ix86_handle_fndecl_attribute): Handle function_return. >> (ix86_attribute_table): Add function_return. >> * config/i386/i386.h (machine_function): Add >> function_return_type. >> * config/i386/i386.md (simple_return_internal): Use >> ix86_output_function_return. >> (simple_return_internal_long): Likewise. >> * config/i386/i386.opt (mfunction-return=): New option. >> (indirect_branch): Mention -mfunction-return=. >> * doc/extend.texi: Document function_return function attribute. >> * doc/invoke.texi: Document -mfunction-return= option. > > The implementation is reasonable, but I still do not quite understand > if we really need this change. Celarly killing every return is going > to have significant impact and it is apparently not used by Linux kernel. > What is the main motivation for it? > > Honza
See: https://gcc.gnu.org/ml/gcc-patches/2018-01/msg00540.html I will check it in. -- H.J.