Go to file
Andi Kleen ecc81e3312 Add direct support for Linux kernel __fentry__ patching
The Linux kernel dynamically patches in __fentry__ calls in and
out at runtime. This allows using function tracing for debugging
in production kernels without (significant) performance penalty.

For this it needs a table pointing to each __fentry__ call.

The way it is currently implemented is that a special
perl script scans the object file, generates the table in a special
section. When the kernel boots up it nops the calls, and
then later patches in the calls again as needed.

The recordmcount.pl script in the kernel works, but it seems
cleaner and faster to support the code generation of the patch table
directly in gcc.

This also allows to nop the calls directly at code generation
time, which allows to skip a patching step at kernel boot.
I also expect that a patchable production tracing facility is also useful
for other applications.

For example it could be used in ftracer
(https://github.com/andikleen/ftracer)

Having a nop area at the beginning of each function can be also
also useful for other things. For example it can be used to patch
functions at runtime to point to different functions, to do
binary updates without restarting the program (like ksplice or
similar)

This patch implements two new options for the i386 target:

-mrecord-mcount
Generate a __mcount_loc section entry for each __fentry__ or mcount
call. The section is compatible with the kernel convention
and the data is put into a section loaded at runtime.

-mnop-mcount
Generate the mcount/__fentry__ call as 5 byte nop that can be
patched in later. The nop is generated as a single instruction,
as the Linux kernel run time patching relies on this.

Limitations:
- I didn't implement -mnop-mcount for -fPIC. This
would need a good single instruction 6 byte NOP and it seems a
bit pointless, as the patching would prevent text sharing.
- I didn't implement noping for targets that pass a variable
to mcount.
- The facility could be useful on architectures too. Currently
the mcount code is target specific, so I made it a i386 option.

gcc/:

2014-09-25  Andi Kleen  <ak@linux.intel.com>

	* config/i386/i386.c (x86_print_call_or_nop): New function.
	(x86_function_profiler): Support -mnop-mcount and
	-mrecord-mcount.
	* config/i386/i386.opt (-mnop-mcount, -mrecord-mcount): Add
	* doc/invoke.texi: Document -mnop-mcount, -mrecord-mcount.

gcc/testsuite:

2014-09-25  Andi Kleen  <ak@linux.intel.com>

	* gcc.target/i386/nop-mcount.c: New file.
	* gcc.target/i386/record-mcount.c: New file.

From-SVN: r215629
2014-09-26 04:06:40 +00:00
boehm-gc
config
contrib Add --inline option to contrib/mklog 2014-09-22 12:53:12 +00:00
fixincludes
gcc Add direct support for Linux kernel __fentry__ patching 2014-09-26 04:06:40 +00:00
gnattools
include demangle.h (DMGL_DLANG): New macro. 2014-09-23 18:36:14 +00:00
INSTALL
intl
libada
libatomic
libbacktrace
libcilkrts
libcpp re PR c/61405 (Not emitting "enumeration value not handled in switch" warning for bit-field enums) 2014-09-24 17:23:56 +00:00
libdecnumber
libffi
libgcc Remove LIBGCC2_LONG_DOUBLE_TYPE_SIZE target macro. 2014-09-23 01:48:46 +01:00
libgfortran check.c (check_co_collective): Renamed from 2014-09-25 08:07:15 +02:00
libgo runtime: Mark runtime_goexit function as noinline. 2014-09-22 21:14:43 +00:00
libgomp
libiberty demangle.h (DMGL_DLANG): New macro. 2014-09-23 18:36:14 +00:00
libitm
libjava
libobjc
libquadmath
libsanitizer [libsanitizer merge from upstream r218156] 2014-09-23 17:59:53 +00:00
libssp
libstdc++-v3 DR 1339 2014-09-25 16:27:18 +01:00
libvtv
lto-plugin
maintainer-scripts
zlib
.dir-locals.el
.gitignore
ABOUT-NLS
ChangeLog
ChangeLog.tree-ssa
compile
config-ml.in
config.guess
config.rpath
config.sub
configure
configure.ac
COPYING
COPYING3
COPYING3.LIB
COPYING.LIB
COPYING.RUNTIME
depcomp
install-sh
libtool-ldflags
libtool.m4
lt~obsolete.m4
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
MAINTAINERS
Makefile.def
Makefile.in
Makefile.tpl
missing
mkdep
mkinstalldirs
move-if-change
README
symlink-tree
ylwrap

This directory contains the GNU Compiler Collection (GCC).

The GNU Compiler Collection is free software.  See the files whose
names start with COPYING for copying permission.  The manuals, and
some of the runtime libraries, are under different terms; see the
individual source files for details.

The directory INSTALL contains copies of the installation information
as HTML and plain text.  The source of this information is
gcc/doc/install.texi.  The installation information includes details
of what is included in the GCC sources and what files GCC installs.

See the file gcc/doc/gcc.texi (together with other files that it
includes) for usage and porting information.  An online readable
version of the manual is in the files gcc/doc/gcc.info*.

See http://gcc.gnu.org/bugs/ for how to report bugs usefully.

Copyright years on GCC source files may be listed using range
notation, e.g., 1987-2012, indicating that every year in the range,
inclusive, is a copyrightable year that could otherwise be listed
individually.