gcc-plugins.rst 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 building out-of-tree
  11. modules, cross-compilation and building in a separate directory.
  12. Plugin source files have to be compilable by a C++ compiler.
  13. Currently the GCC plugin infrastructure supports only some architectures.
  14. Grep "select HAVE_GCC_PLUGINS" to find out which architectures support
  15. GCC plugins.
  16. This infrastructure was ported from grsecurity [6]_ and PaX [7]_.
  17. --
  18. .. [1] https://gcc.gnu.org/onlinedocs/gccint/Plugins.html
  19. .. [2] https://gcc.gnu.org/onlinedocs/gccint/Plugin-API.html#Plugin-API
  20. .. [3] https://gcc.gnu.org/onlinedocs/gccint/GIMPLE.html
  21. .. [4] https://gcc.gnu.org/onlinedocs/gccint/IPA.html
  22. .. [5] https://gcc.gnu.org/onlinedocs/gccint/RTL.html
  23. .. [6] https://grsecurity.net/
  24. .. [7] https://pax.grsecurity.net/
  25. Files
  26. =====
  27. **$(src)/scripts/gcc-plugins**
  28. This is the directory of the GCC plugins.
  29. **$(src)/scripts/gcc-plugins/gcc-common.h**
  30. This is a compatibility header for GCC plugins.
  31. It should be always included instead of individual gcc headers.
  32. **$(src)/scripts/gcc-plugins/gcc-generate-gimple-pass.h,
  33. $(src)/scripts/gcc-plugins/gcc-generate-ipa-pass.h,
  34. $(src)/scripts/gcc-plugins/gcc-generate-simple_ipa-pass.h,
  35. $(src)/scripts/gcc-plugins/gcc-generate-rtl-pass.h**
  36. These headers automatically generate the registration structures for
  37. GIMPLE, SIMPLE_IPA, IPA and RTL passes.
  38. They should be preferred to creating the structures by hand.
  39. Usage
  40. =====
  41. You must install the gcc plugin headers for your gcc version,
  42. e.g., on Ubuntu for gcc-10::
  43. apt-get install gcc-10-plugin-dev
  44. Or on Fedora::
  45. dnf install gcc-plugin-devel
  46. Enable the GCC plugin infrastructure and some plugin(s) you want to use
  47. in the kernel config::
  48. CONFIG_GCC_PLUGINS=y
  49. CONFIG_GCC_PLUGIN_CYC_COMPLEXITY=y
  50. CONFIG_GCC_PLUGIN_LATENT_ENTROPY=y
  51. ...
  52. To compile the minimum tool set including the plugin(s)::
  53. make scripts
  54. or just run the kernel make and compile the whole kernel with
  55. the cyclomatic complexity GCC plugin.
  56. 4. How to add a new GCC plugin
  57. ==============================
  58. The GCC plugins are in scripts/gcc-plugins/. You need to put plugin source files
  59. right under scripts/gcc-plugins/. Creating subdirectories is not supported.
  60. It must be added to scripts/gcc-plugins/Makefile, scripts/Makefile.gcc-plugins
  61. and a relevant Kconfig file.
  62. See the cyc_complexity_plugin.c (CONFIG_GCC_PLUGIN_CYC_COMPLEXITY) GCC plugin.