Support instrumenting returns of instrumented functions
authorAndi Kleen <ak@linux.intel.com>
Thu, 29 Nov 2018 23:11:47 +0000 (23:11 +0000)
committerAndi Kleen <ak@gcc.gnu.org>
Thu, 29 Nov 2018 23:11:47 +0000 (23:11 +0000)
commit3b31afe1a56cfb7b92f563b53686b378bdbead54
tree4a9b821db915c6d93e7d73e2d80b79bb5637517e
parent856f4c6a9cfac1471c323b1783130879e2bbc15f
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
gcc/ChangeLog
gcc/config/i386/i386-opts.h
gcc/config/i386/i386.c
gcc/config/i386/i386.opt
gcc/doc/invoke.texi
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/i386/returninst1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/returninst2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/returninst3.c [new file with mode: 0644]