gcc-plugins.txt 2.9 KB

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