gcc-plugins.txt 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. =========================
  2. GCC plugin infrastructure
  3. =========================
  4. Introduction
  5. ============
  6. GCC plugins are loadable modules that provide extra features to the
  7. compiler [1]_. They are useful for runtime instrumentation and static analysis.
  8. We can analyse, change and add further code during compilation via
  9. callbacks [2]_, GIMPLE [3]_, IPA [4]_ and RTL passes [5]_.
  10. The GCC plugin infrastructure of the kernel supports all gcc versions from
  11. 4.5 to 6.0, building out-of-tree modules, cross-compilation and building in a
  12. separate directory.
  13. Plugin source files have to be compilable by both a C and a C++ compiler as well
  14. because gcc versions 4.5 and 4.6 are compiled by a C compiler,
  15. gcc-4.7 can be compiled by a C or a C++ compiler,
  16. and versions 4.8+ can only be compiled by a C++ compiler.
  17. Currently the GCC plugin infrastructure supports only the x86, arm, arm64 and
  18. powerpc architectures.
  19. This infrastructure was ported from grsecurity [6]_ and PaX [7]_.
  20. --
  21. .. [1] https://gcc.gnu.org/onlinedocs/gccint/Plugins.html
  22. .. [2] https://gcc.gnu.org/onlinedocs/gccint/Plugin-API.html#Plugin-API
  23. .. [3] https://gcc.gnu.org/onlinedocs/gccint/GIMPLE.html
  24. .. [4] https://gcc.gnu.org/onlinedocs/gccint/IPA.html
  25. .. [5] https://gcc.gnu.org/onlinedocs/gccint/RTL.html
  26. .. [6] https://grsecurity.net/
  27. .. [7] https://pax.grsecurity.net/
  28. Files
  29. =====
  30. **$(src)/scripts/gcc-plugins**
  31. This is the directory of the GCC plugins.
  32. **$(src)/scripts/gcc-plugins/gcc-common.h**
  33. This is a compatibility header for GCC plugins.
  34. It should be always included instead of individual gcc headers.
  35. **$(src)/scripts/gcc-plugin.sh**
  36. This script checks the availability of the included headers in
  37. gcc-common.h and chooses the proper host compiler to build the plugins
  38. (gcc-4.7 can be built by either gcc or g++).
  39. **$(src)/scripts/gcc-plugins/gcc-generate-gimple-pass.h,
  40. $(src)/scripts/gcc-plugins/gcc-generate-ipa-pass.h,
  41. $(src)/scripts/gcc-plugins/gcc-generate-simple_ipa-pass.h,
  42. $(src)/scripts/gcc-plugins/gcc-generate-rtl-pass.h**
  43. These headers automatically generate the registration structures for
  44. GIMPLE, SIMPLE_IPA, IPA and RTL passes. They support all gcc versions
  45. from 4.5 to 6.0.
  46. They should be preferred to creating the structures by hand.
  47. Usage
  48. =====
  49. You must install the gcc plugin headers for your gcc version,
  50. e.g., on Ubuntu for gcc-4.9::
  51. apt-get install gcc-4.9-plugin-dev
  52. Enable a GCC plugin based feature in the kernel config::
  53. CONFIG_GCC_PLUGIN_CYC_COMPLEXITY = y
  54. To compile only the plugin(s)::
  55. make gcc-plugins
  56. or just run the kernel make and compile the whole kernel with
  57. the cyclomatic complexity GCC plugin.
  58. 4. How to add a new GCC plugin
  59. ==============================
  60. The GCC plugins are in $(src)/scripts/gcc-plugins/. You can use a file or a directory
  61. here. It must be added to $(src)/scripts/gcc-plugins/Makefile,
  62. $(src)/scripts/Makefile.gcc-plugins and $(src)/arch/Kconfig.
  63. See the cyc_complexity_plugin.c (CONFIG_GCC_PLUGIN_CYC_COMPLEXITY) GCC plugin.