]> git.ipfire.org Git - thirdparty/gcc.git/commit
Support instrumenting returns of instrumented functions
authorak <ak@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 29 Nov 2018 23:11:47 +0000 (23:11 +0000)
committerak <ak@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 29 Nov 2018 23:11:47 +0000 (23:11 +0000)
commitaccf2ab873f17ed97d487e7cdb0ee60d80d25651
tree4a9b821db915c6d93e7d73e2d80b79bb5637517e
parent2f4ed79a65930998cbbf203d56d88fd0d94cd737
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@266652 138bc75d-0d04-0410-961f-82ee72b054a4
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]