Part 1
요약·해설
Module과 SDK-bundled variant, source build용 toolchain Kconfig, stdio 기반 출력, C17 math, TLS와 z_libc_partition, 공통 heap 연결을 다룹니다.
Module · Toolchain · Source
stdio · Math · TLS
Partition · malloc · Heap
Part 2
접을 수 있는 영어 원문 전체
영어 원문 전체 펼치기
5D569C6CB2F93898AC0CB03C2F3CF0C448B9707012114168AD3F0E0771C4DE80
.. _c_library_picolibc:
Picolibc
########
`Picolibc`_ is a complete C library implementation written for the
embedded systems, targeting `C17 (ISO/IEC 9899:2018)`_ and `POSIX 2018
(IEEE Std 1003.1-2017)`_ standards. Picolibc is an external open
source project which is provided for Zephyr as a module, and included
as part of the :ref:`toolchain_zephyr_sdk` in precompiled form for
each supported architecture (:file:`libc.a`).
.. note::
Picolibc is also available for other 3rd-party toolchains, such as
:ref:`toolchain_gnuarmemb`.
Zephyr implements the “API hook” functions that are invoked by the C
standard library functions in the Picolibc. These hook functions are
implemented in :file:`lib/libc/picolibc/libc-hooks.c` and translate
the library internal system calls to the equivalent Zephyr API calls.
.. _`Picolibc`: https://github.com/picolibc/picolibc
.. _`C17 (ISO/IEC 9899:2018)`: https://www.iso.org/standard/74528.html
.. _`POSIX 2018 (IEEE Std 1003.1-2017)`: https://pubs.opengroup.org/onlinepubs/9699919799/functions/printf.html
.. _c_library_picolibc_module:
Picolibc Module
===============
When built as a Zephyr module, there are several configuration knobs
available to adjust the feature set in the library, balancing what the
library supports versus the code size of the resulting
functions. Because the standard C++ library must be compiled for the
target C library, the Picolibc module cannot be used with applications
which use the standard C++ library. Building the Picolibc module will
increase the time it takes to compile the application.
The Picolibc module can be enabled by selecting
:kconfig:option:`CONFIG_PICOLIBC_USE_MODULE` in the application
configuration file.
When updating the Picolibc module to a newer version, the
:ref:`toolchain-bundled Picolibc in the Zephyr SDK
<c_library_picolibc_toolchain>` must also be updated to the same version.
.. _c_library_picolibc_toolchain:
Toolchain Picolibc
==================
Starting with version 0.16, the Zephyr SDK includes precompiled
versions of Picolibc for every target architecture, along with
precompiled versions of libstdc++.
The toolchain version of Picolibc can be enabled by de-selecting
:kconfig:option:`CONFIG_PICOLIBC_USE_MODULE` in the application
configuration file.
For every release of Zephyr, the toolchain-bundled Picolibc and the
:ref:`Picolibc module <c_library_picolibc_module>` are guaranteed to be in
sync when using the
:ref:`recommended version of Zephyr SDK <toolchain_zephyr_sdk_compatibility>`.
Building Without Toolchain bundled Picolibc
-------------------------------------------
For toolchain where there is no bundled Picolibc, it is still
possible to use Picolibc by building it from source. Note that
any restrictions mentioned in :ref:`c_library_picolibc_module`
still apply.
To build without toolchain bundled Picolibc, the toolchain must
enable :kconfig:option:`CONFIG_PICOLIBC_SUPPORTED`. For example,
this needs to be added to the toolchain Kconfig file:
.. code-block:: kconfig
config TOOLCHAIN_<name>_PICOLIBC_SUPPORTED
def_bool y
select PICOLIBC_SUPPORTED
By enabling :kconfig:option:`CONFIG_PICOLIBC_SUPPORTED`, the build
system would automatically build Picolibc from source with its module
when there is no toolchain bundled Picolibc.
Formatted Output
****************
Picolibc supports all standard C formatted input and output functions,
including :c:func:`printf`, :c:func:`fprintf`, :c:func:`sprintf` and
:c:func:`sscanf`.
Picolibc formatted input and output function implementation supports
all format specifiers defined by the C17 and POSIX 2018 standards with
the following exceptions:
* Floating point format specifiers (e.g. ``%f``) require
:kconfig:option:`CONFIG_PICOLIBC_IO_FLOAT`.
* Long long format specifiers (e.g. ``%lld``) require
:kconfig:option:`CONFIG_PICOLIBC_IO_LONG_LONG`. This option is
automatically enabled with :kconfig:option:`CONFIG_PICOLIBC_IO_FLOAT`.
Printk, cbprintf and friends
****************************
When using Picolibc, Zephyr formatted output functions are
implemented in terms of stdio calls. This includes:
* printk, snprintk and vsnprintk
* cbprintf and cbvprintf
* fprintfcb, vfprintfcb, printfcb, vprintfcb, snprintfcb and vsnprintfcb
When using tagged args
(:kconfig:option:`CONFIG_CBPRINTF_PACKAGE_SUPPORT_TAGGED_ARGUMENTS` and
:c:macro:`CBPRINTF_PACKAGE_ARGS_ARE_TAGGED`), calls to cbpprintf will
not use Picolibc, so formatting of output using those code will differ
from Picolibc results as the cbprintf functions are not completely
C/POSIX compliant.
Math Functions
**************
Picolibc provides full C17/`IEEE STD 754-2019`_ support for float,
double and long double math operations, except for long double
versions of the Bessel functions.
.. _`IEEE STD 754-2019`: https://ieeexplore.ieee.org/document/8766229
Thread Local Storage
********************
Picolibc uses Thread Local Storage (TLS) (where supported) for data
which is supposed to remain local to each thread, like
:c:var:`errno`. This means that TLS support is enabled when using
Picolibc. As all TLS variables are allocated out of the thread stack
area, this can affect stack size requirements by a few bytes.
C Library Local Variables
*************************
Picolibc uses a few internal variables for things like heap
management. These are collected in a dedicated memory partition called
:c:var:`z_libc_partition`. Applications using
:kconfig:option:`CONFIG_USERSPACE` and memory domains must ensure that
this partition is included in any domain active during Picolibc calls.
Dynamic Memory Management
*************************
Picolibc uses the malloc api family implementation provided by the
:ref:`common C library <c_library_common>`, which itself is built upon the
:ref:`kernel memory heap API <heap_v2>`.
Part 3
한국어 전문 번역
Picolibc
Picolibc는 embedded system용 완전한 C library 구현이며 C17(ISO/IEC 9899:2018)과 POSIX 2018(IEEE Std 1003.1-2017) standard를 target으로 합니다. 외부 open-source project로서 Zephyr module로 제공되며, Zephyr SDK에도 지원 architecture별 precompiled libc.a 형태로 포함됩니다.
Zephyr는 Picolibc의 C standard library function이 호출하는 API hook function을 구현합니다. lib/libc/picolibc/libc-hooks.c에 있는 이 hook은 library 내부 system call을 동등한 Zephyr API call로 변환합니다.
Picolibc module
Zephyr module로 build하면 library가 지원하는 기능과 생성 function의 code size 사이에서 균형을 조정할 수 있는 여러 configuration option을 제공합니다. Standard C++ library는 target C library에 맞춰 compile해야 하므로 standard C++ library를 사용하는 application에서는 Picolibc module을 사용할 수 없습니다. Module을 build하면 application compile 시간도 늘어납니다.
Application configuration file에서 CONFIG_PICOLIBC_USE_MODULE을 선택하면 Picolibc module을 활성화합니다.
Picolibc module을 새 version으로 갱신할 때는 Zephyr SDK의 toolchain-bundled Picolibc도 같은 version으로 갱신해야 합니다.
Toolchain Picolibc
Zephyr SDK version 0.16부터 모든 target architecture용 precompiled Picolibc와 precompiled libstdc++를 포함합니다.
Application configuration file에서 CONFIG_PICOLIBC_USE_MODULE 선택을 해제하면 toolchain version Picolibc를 활성화합니다.
Zephyr release마다 권장 Zephyr SDK version을 사용하면 toolchain-bundled Picolibc와 Picolibc module의 version이 서로 일치하도록 보장합니다.
Toolchain-bundled Picolibc 없이 build
Picolibc가 bundle되지 않은 toolchain에서도 source에서 build해 사용할 수 있습니다. 이 경우에도 Picolibc module 절의 모든 제한 사항이 적용됩니다.
Bundled Picolibc 없이 build하려면 toolchain이 CONFIG_PICOLIBC_SUPPORTED를 활성화해야 합니다. 예를 들어 toolchain Kconfig file에 다음 내용을 추가합니다.
config TOOLCHAIN_<name>_PICOLIBC_SUPPORTED
def_bool y
select PICOLIBC_SUPPORTEDCONFIG_PICOLIBC_SUPPORTED를 활성화하면 bundled Picolibc가 없을 때 build system이 module source로 Picolibc를 자동 build합니다.
Formatted output
Picolibc는 printf(), fprintf(), sprintf(), sscanf()을 포함한 모든 standard C formatted input·output function을 지원합니다.
Formatted input·output 구현은 다음 예외를 제외하고 C17과 POSIX 2018이 정의한 모든 format specifier를 지원합니다.
- Floating-point format specifier(예:
%f)를 사용하려면CONFIG_PICOLIBC_IO_FLOAT가 필요합니다. - Long long format specifier(예:
%lld)를 사용하려면CONFIG_PICOLIBC_IO_LONG_LONG가 필요합니다.CONFIG_PICOLIBC_IO_FLOAT를 활성화하면 이 option도 자동으로 활성화됩니다.
Printk, cbprintf와 관련 function
Picolibc를 사용할 때 Zephyr formatted output function은 stdio call을 이용해 구현됩니다. 포함되는 function:
printk,snprintk,vsnprintkcbprintf,cbvprintffprintfcb,vfprintfcb,printfcb,vprintfcb,snprintfcb,vsnprintfcb
Tagged argument(CONFIG_CBPRINTF_PACKAGE_SUPPORT_TAGGED_ARGUMENTS와 CBPRINTF_PACKAGE_ARGS_ARE_TAGGED)를 사용할 때 cbpprintf call은 Picolibc를 사용하지 않습니다. cbprintf function은 C/POSIX를 완전히 준수하지 않으므로 이 code의 output formatting 결과는 Picolibc 결과와 다를 수 있습니다.
수학 function
Picolibc는 Bessel function의 long double version을 제외하고 float·double·long double 수학 operation에 대해 C17과 IEEE STD 754-2019를 완전히 지원합니다.
Thread Local Storage
Picolibc는 errno처럼 thread마다 local 상태를 유지해야 하는 data에 지원 가능한 경우 Thread Local Storage(TLS)를 사용합니다. 따라서 Picolibc를 사용하면 TLS 지원이 활성화됩니다. 모든 TLS variable은 thread stack 영역에서 할당되므로 stack size requirement가 몇 byte 늘어날 수 있습니다.
C library local variable
Picolibc는 heap 관리 같은 용도로 몇 가지 내부 variable을 사용합니다. 이 variable은 z_libc_partition 전용 memory partition에 모입니다. CONFIG_USERSPACE와 memory domain을 사용하는 application은 Picolibc call이 실행되는 동안 active인 모든 domain에 이 partition이 포함되도록 해야 합니다.
동적 memory 관리
Picolibc는 공통 C library가 제공하는 malloc API family 구현을 사용하며, 이 구현은 다시 kernel memory heap API를 기반으로 합니다.
Source
출처
영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.