Support instrumenting returns of instrumented functions
When instrumenting programs using __fentry__ it is often useful
to instrument the function return too. Traditionally this
has been done by patching the return address on the stack
frame on entry. However this is fairly complicated (trace
function has to emulate a stack) and also slow because
it causes a branch misprediction on every return.
Add an option to generate call or nop instrumentation for
every return instead, including patch sections.
This will increase the program size slightly, but can be a
lot faster and simpler.
This version only instruments true returns, not sibling
calls or tail recursion. This matches the semantics of the
original stack.
gcc/:
2018-11-29 Andi Kleen <ak@linux.intel.com>
* config/i386/i386-opts.h (enum instrument_return): Add.
* config/i386/i386.c (output_return_instrumentation): Add.
(ix86_output_function_return): Call output_return_instrumentation.
(ix86_output_call_insn): Call output_return_instrumentation.
* config/i386/i386.opt: Add -minstrument-return=.
* doc/invoke.texi (-minstrument-return): Document.
gcc/testsuite/:
2018-11-29 Andi Kleen <ak@linux.intel.com>
* gcc.target/i386/returninst1.c: New test.
* gcc.target/i386/returninst2.c: New test.
* gcc.target/i386/returninst3.c: New test.
From-SVN: r266652