programming-language.rst 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. .. _programming_language:
  2. Programming Language
  3. ====================
  4. The Linux kernel is written in the C programming language [c-language]_.
  5. More precisely, it is typically compiled with ``gcc`` [gcc]_
  6. under ``-std=gnu11`` [gcc-c-dialect-options]_: the GNU dialect of ISO C11.
  7. ``clang`` [clang]_ is also supported; see documentation on
  8. :ref:`Building Linux with Clang/LLVM <kbuild_llvm>`.
  9. This dialect contains many extensions to the language [gnu-extensions]_,
  10. and many of them are used within the kernel as a matter of course.
  11. Attributes
  12. ----------
  13. One of the common extensions used throughout the kernel are attributes
  14. [gcc-attribute-syntax]_. Attributes allow to introduce
  15. implementation-defined semantics to language entities (like variables,
  16. functions or types) without having to make significant syntactic changes
  17. to the language (e.g. adding a new keyword) [n2049]_.
  18. In some cases, attributes are optional (i.e. a compiler not supporting them
  19. should still produce proper code, even if it is slower or does not perform
  20. as many compile-time checks/diagnostics).
  21. The kernel defines pseudo-keywords (e.g. ``__pure``) instead of using
  22. directly the GNU attribute syntax (e.g. ``__attribute__((__pure__))``)
  23. in order to feature detect which ones can be used and/or to shorten the code.
  24. Please refer to ``include/linux/compiler_attributes.h`` for more information.
  25. Rust
  26. ----
  27. The kernel has support for the Rust programming language
  28. [rust-language]_ under ``CONFIG_RUST``. It is compiled with ``rustc`` [rustc]_
  29. under ``--edition=2021`` [rust-editions]_. Editions are a way to introduce
  30. small changes to the language that are not backwards compatible.
  31. On top of that, some unstable features [rust-unstable-features]_ are used in
  32. the kernel. Unstable features may change in the future, thus it is an important
  33. goal to reach a point where only stable features are used.
  34. Please refer to Documentation/rust/index.rst for more information.
  35. .. [c-language] http://www.open-std.org/jtc1/sc22/wg14/www/standards
  36. .. [gcc] https://gcc.gnu.org
  37. .. [clang] https://clang.llvm.org
  38. .. [gcc-c-dialect-options] https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html
  39. .. [gnu-extensions] https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html
  40. .. [gcc-attribute-syntax] https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html
  41. .. [n2049] http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2049.pdf
  42. .. [rust-language] https://www.rust-lang.org
  43. .. [rustc] https://doc.rust-lang.org/rustc/
  44. .. [rust-editions] https://doc.rust-lang.org/edition-guide/editions/
  45. .. [rust-unstable-features] https://github.com/Rust-for-Linux/linux/issues/2