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
INSTALL README: Also refer to the online installation instructions. 2012-08-25 20:48:20 +00:00
boehm-gc Enable Java on Cygwin-64 2014-05-13 16:23:11 +00:00
config Support slim LTO bootstrap 2014-09-01 16:41:28 +00:00
contrib Add --inline option to contrib/mklog 2014-09-22 12:53:12 +00:00
fixincludes inclhack.def (complier_h_tradcpp): Remove. 2014-08-12 11:05:24 +00:00
gcc Add direct support for Linux kernel __fentry__ patching 2014-09-26 04:06:40 +00:00
gnattools Makefile.in (TOOLS_FLAGS_TO_PASS_CROSS): Robustify. 2014-02-23 16:30:11 +00:00
include demangle.h (DMGL_DLANG): New macro. 2014-09-23 18:36:14 +00:00
intl Fix unportable shell quoting. 2010-09-27 20:19:41 +00:00
libada Makefile.in: Add CFLAGS_FOR_TARGET to GNATLIBCFLAGS_FOR_C. 2014-08-12 19:47:09 +00:00
libatomic configure.tgt: Add cygwin to supported targets. 2014-08-19 16:55:37 +02:00
libbacktrace mmap.c (backtrace_free): If freeing a large aligned block of memory, call munmap rather than holding onto it. 2014-05-09 05:01:08 +00:00
libcilkrts configure.ac: Move pthread affinity test to the place where '-pthread' passed to CFLAGS. 2014-08-12 11:06:44 +00:00
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 re PR c/59871 (No unused value warning for comma expression) 2014-01-23 19:04:29 +00:00
libffi linux64.S: Emit .note.GNU-stack even when POWERPC64 is not defined. 2014-09-11 11:03:49 +02:00
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 re PR c++/63248 (Crash when OpenMP target's array section handling is used with templates) 2014-09-18 18:43:28 +02:00
libiberty demangle.h (DMGL_DLANG): New macro. 2014-09-23 18:36:14 +00:00
libitm libitm: Improve aarch64 _ITM_beginTransaction 2014-07-24 19:58:06 -07:00
libjava libffi.exp (load_gcc_lib): Register loaded libs. 2014-05-20 08:20:06 +00:00
libobjc re PR libobjc/61920 (libobjc has undefined symbols on powerpc*-linux-gnu) 2014-07-27 13:15:17 +00:00
libquadmath gnat_ugn.texi: Bump @copying's copyright year. 2014-01-02 22:25:41 +01:00
libsanitizer [libsanitizer merge from upstream r218156] 2014-09-23 17:59:53 +00:00
libssp * ssp.c (fail): Avoid -Wformat-security warning. 2013-12-07 09:10:02 +01:00
libstdc++-v3 DR 1339 2014-09-25 16:27:18 +01:00
libvtv Fix up ChangeLog entries (name, e-mail, formatting, otherwise). 2013-10-23 21:30:54 +00:00
lto-plugin Properly set gcc_build_dir for in-tree build 2014-08-26 07:47:15 -07:00
maintainer-scripts crontab: Change trunk snapshots from 4.10 to 5. 2014-08-14 13:58:16 +00:00
zlib Add --enable-host-shared configuration option 2013-10-15 20:33:55 +00:00
.dir-locals.el * .dir-locals.el: Add. 2013-10-16 18:25:31 +00:00
.gitignore Ignore gcc_update output 2014-06-18 17:47:18 -07:00
ABOUT-NLS
COPYING
COPYING.LIB
COPYING.RUNTIME
COPYING3
COPYING3.LIB
ChangeLog Fix mistake in commit 215237 2014-09-13 19:00:28 +00:00
ChangeLog.tree-ssa
MAINTAINERS * MAINTAINERS: Move myself to reviewers (Fortran). 2014-09-13 12:52:23 +00:00
Makefile.def Non-host system configuration for linker plugins. 2014-06-13 16:32:16 +02:00
Makefile.in Support slim LTO bootstrap 2014-09-01 16:41:28 +00:00
Makefile.tpl Support slim LTO bootstrap 2014-09-01 16:41:28 +00:00
README * README: Document use of ranges of years in copyright notices. 2012-07-16 15:01:34 +01:00
compile Update automake-provided files in the toplevel. 2009-08-22 11:47:16 +00:00
config-ml.in * config-ml.in: Robustify ac_configure_args parsing. 2014-06-13 16:32:29 +02:00
config.guess * config.sub, config.guess: Import from upstream. 2014-05-01 20:51:11 +00:00
config.rpath Remove freebsd1 from libtool.m4 macros and config.rpath. 2011-02-13 11:45:53 +00:00
config.sub Import config.sub from upstream. No changes to config.guess. 2014-07-28 17:53:25 +00:00
configure check functionality of isl version 0.12 2014-08-28 16:43:55 +00:00
configure.ac check functionality of isl version 0.12 2014-08-28 16:43:55 +00:00
depcomp Update automake-provided files in the toplevel. 2009-08-22 11:47:16 +00:00
install-sh Update automake-provided files in the toplevel. 2009-08-22 11:47:16 +00:00
libtool-ldflags re PR sanitizer/56781 (boostrap-asan failure: fixincl fails to link (missing -lasan)) 2014-04-17 14:23:28 +02:00
libtool.m4 libtool.m4 (_LT_ENABLE_LOCK <ld -m flags>): Remove non-canonical ppc host match. 2013-09-20 19:17:52 +09:30
ltgcc.m4
ltmain.sh Ensure libgcc_s unwinder is always used on 64-bit Solaris 10+/x86 (PR target/59788) 2014-02-04 09:31:38 +00:00
ltoptions.m4 Sync from git Libtool and regenerate. 2009-12-05 17:18:53 +00:00
ltsugar.m4
ltversion.m4 Sync from git Libtool and regenerate. 2009-12-05 17:18:53 +00:00
lt~obsolete.m4 Sync from git Libtool and regenerate. 2009-12-05 17:18:53 +00:00
missing Update automake-provided files in the toplevel. 2009-08-22 11:47:16 +00:00
mkdep
mkinstalldirs Update automake-provided files in the toplevel. 2009-08-22 11:47:16 +00:00
move-if-change Import move-if-change script from gnulib. 2011-02-12 15:48:30 +00:00
symlink-tree
ylwrap Update automake-provided files in the toplevel. 2009-08-22 11:47:16 +00:00

README

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.