← Documents Documentation/process/programming-language.rst GitHub 원문 ↗

Linux 6.18.37 · 개발 절차

Linux 커널의 programming language

GNU C11 dialect, compiler attribute pseudo-keyword와 CONFIG_RUST의 Rust 2021 edition 사용을 설명합니다.

Source pathDocumentation/process/programming-language.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

GNU dialect of ISO C11

programming-language.rst:1-13

Linux kernel은 C로 작성한다. 더 정확히는 보통 GCC의 -std=gnu11 option으로 compile하는 ISO C11의 GNU dialect를 사용한다. Clang도 공식 지원한다.

gcc -std=gnu11 ...
# Clang build는 Documentation/kbuild/llvm.rst 참고

GNU dialect에는 표준 C에 없는 여러 extension이 있고 kernel code는 이 기능을 일상적으로 사용한다. 따라서 user-space의 strictly conforming ISO C만 알고 있다면 statement expression, typeof, attribute 등 GNU extension도 함께 이해해야 한다.

Compiler attribute

programming-language.rst:15-34

Attribute는 새 keyword를 language grammar에 직접 추가하지 않고 variable, function, type에 implementation-defined semantics를 부여한다.

일부 attribute는 optional이다. Compiler가 지원하지 않아도 올바른 code를 생성해야 하지만 최적화가 약하거나 compile-time check와 diagnostic이 줄어들 수 있다.

/* 직접 GNU syntax를 쓰기보다 */
__attribute__((__pure__))

/* kernel pseudo-keyword를 사용한다. */
__pure

Kernel은 GNU attribute syntax를 직접 반복하지 않고 __pure 같은 pseudo-keyword를 정의한다. Compiler별 feature detection을 적용하고 source를 짧게 유지하기 위해서다. 실제 mapping은 include/linux/compiler_attributes.h에서 확인한다.

Rust support

programming-language.rst:36-49

CONFIG_RUST를 enable하면 kernel은 experimental Rust support를 제공한다. rustc의 --edition=2021로 compile하며 edition은 작은 비호환 language 변경을 묶어 도입하는 단위다.

Kernel은 일부 unstable Rust feature도 사용한다. Unstable feature는 향후 바뀔 수 있으므로 장기 목표는 stable feature만으로 kernel Rust code를 build하는 것이다.

Toolchain, abstraction와 coding rule의 자세한 내용은 Documentation/rust/index.rst에서 확인한다.

원문 reference

programming-language.rst:51-61

원문은 ISO C 표준, GCC와 Clang, GCC dialect·extension·attribute 문서, C attribute 제안 N2049, Rust language·rustc·edition guide와 Rust-for-Linux unstable-feature tracker를 reference로 연결한다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

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

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

C programming language

1-13

Kernel은 C programming language로 작성된다. 더 정확히는 일반적으로 gcc에서 -std=gnu11을 사용해 compile한다. 이는 ISO C11의 GNU dialect다. clang도 지원하며 자세한 내용은 Building Linux with Clang/LLVM 문서를 참조한다.

이 dialect에는 여러 GNU language extension이 포함되어 있으며, kernel은 그중 많은 기능을 일상적으로 사용한다.

Attribute

15-32

Kernel 전반에서 흔히 사용하는 extension 가운데 하나가 attribute다. Attribute를 사용하면 새 keyword를 추가하는 것처럼 language syntax를 크게 바꾸지 않고도 variable, function, type 같은 language entity에 implementation-defined semantics를 부여할 수 있다.

일부 attribute는 선택 사항이다. Compiler가 이를 지원하지 않더라도 더 느리거나 compile-time check와 diagnostic이 줄어들 수는 있지만, 올바른 code를 만들어야 한다.

Kernel은 GNU attribute syntax를 직접 사용하는 대신 __pure 같은 pseudo-keyword를 정의한다. 이를 통해 사용할 수 있는 attribute를 feature detection하고 code를 더 짧게 쓸 수 있다. 자세한 내용은 include/linux/compiler_attributes.h를 참조한다.

Rust

34-58

Kernel은 CONFIG_RUST 아래에서 Rust programming language를 실험적으로 지원한다. rustc와 --edition=2021을 사용해 compile한다. Edition은 backward compatibility가 없는 작은 language 변경을 도입하는 방법이다.

Kernel은 일부 unstable feature도 사용한다. Unstable feature는 앞으로 변경될 수 있으므로 stable feature만 사용하는 단계에 도달하는 것이 중요한 목표다. 자세한 내용은 Documentation/rust/index.rst를 참조한다.

C 표준, GCC, Clang, GNU extension과 attribute syntax, N2049, Rust, rustc, Rust edition 및 Rust-for-Linux unstable feature의 원문 reference URL은 영어 원문의 각 footnote에 보존되어 있다.