• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# musl libc
2
3## Overview
4The C standard library (libc) provides standard header files and common library implementations (such as input/output processing and string handling) in C language programming.
5
6OpenHarmony uses musl as the libc. musl is a lightweight, fast, simple, and free open-source libc. For details, see [musl libc Reference Manual](http://musl.libc.org/manual.html).
7
8For details about the differences between musl and glibc, see [Functional differences from glibc](https://wiki.musl-libc.org/functional-differences-from-glibc.html).
9
10## libc Components
11
12C11 is implemented by [libc, libm, and libdl](https://en.cppreference.com/w/c/header).
13
14- libc: provides thread-related interfaces and a majority of standard interfaces.
15
16- libm: provides mathematical library interfaces. Currently, OpenHarmony provides a link to libm, and the interfaces are defined in libc.
17
18- libdl: provides dynamic linker interfaces such as dlopen. Currently, OpenHarmony provides a link to libdl, and the interfaces are defined in libc.
19
20## musl Version
21
22- 1.2.0
23
24- 1.2.3 since OpenHarmony 4.0
25
26- 1.2.5 since OpenHarmony 5.0
27
28## Supported Capabilities
29OpenHarmony provides header files and library interfaces that align with C99, C11, and POSIX standards, though not fully compliant. It supports Armv7-A, Arm64, and x86_64 architectures.
30
31To better accommodate the basic features of OpenHarmony devices, such as high performance, low memory usage, high security, lightweight design, and multi-device adaptability, the musl library has been optimized and enhanced, with interfaces unsuitable for embedded devices removed according.
32
33### New Capabilities
341. The dynamic loader supports isolation by namespace. The dynamic libraries that can be loaded by **dlopen()** are restricted by the system namespace. For example, the system dynamic libraries cannot be opened.
352. **dlclose()** can be used to unload a dynamic library. This capability is not supported by musl.
363. The symbol-versioning is supported.
374. **dlopen()** can directly load uncompressed files in a .zip package.
38
39### Debugging Capabilities
40The libc provides dynamic enabling of debug logging (disabled by default). The debug logs help you learn about exceptions of the libc. With this function, you only need to set **param**, which eliminates the need for rebuilding the libc. However, you are advised not to enable debug logging in official versions because it affects the running performance.
41
42#### musl.log
43Set **musl.log.enable** to **true** to enable printing of musl debug logs. You need to enable musl.log before printing other logs.
44```
45param set musl.log.enable true
46```
47
48#### Loader Logging
49The loader starts applications and invokes **dlopen** and **dlclose** in the libc. To view exceptions during the loading process, you need to enable the loader logging function. The following describes common operations.
50* Enable the loader logging for all applications. Exercise caution when enabling this function because a large number of logs will be generated.
51```
52param set musl.log.ld.app true
53```
54* Enable the loader logging for an application specified by {app_name}.
55```
56param set musl.log.ld.all false
57param set musl.log.ld.app.{app_name} true
58```
59* Enable the loader logging for all applications except the specified application.
60```
61param set musl.log.ld.all true
62param set musl.log.ld.app.{app_name} false
63```
64## musl API Difference
65
66| API         | Description                                                                                        |
67|:--               |    :--                                                                                       |
68| epoll_create     | In OpenHarmony 5.0, this API uses the same logic as in musl 1.2.3. Specifically, the API does not verify input parameters or process them if the input parameter value is less than or equal to **0**. In the next version, this API will adopt the logic from musl 1.2.5, which includes input parameter verification. If the input parameter value is less than or equal to **0**, the error code EINVAL will be returned.|
69
70## Character Encoding Formats Supported by iconv
71
72The following lists the character encoding formats and aliases supported by musl.
73> **NOTE**
74>
75> The character conversion can be successful only when the source character encoding format is correct and the target character encoding format is supported.
76> musl does not support the following target encoding formats: gb18030, gbk, gb2312, big5, and euckr.
77
78| Encoding Format| Alias                  | Supported by musl|
79|:--      |    :--                   |  :--:  |
80|utf8     |                          |  Yes  |
81|wchart   |                          |  Yes  |
82|ucs2be   |                          |  Yes  |
83|ucs2le   |                          |  Yes  |
84|utf16be  |                          |  Yes  |
85|utf16le  |                          |  Yes  |
86|ucs4be   |utf32be                   |  Yes  |
87|ucs4le   |utf32le                   |  Yes  |
88|ascii    |usascii, iso646, iso646us |  Yes  |
89|utf16    |                          |  Yes  |
90|ucs4     |utf32                     |  Yes  |
91|ucs2     |                          |  Yes  |
92|eucjp    |                          |  Yes  |
93|shiftjis |sjis, cp932               |  Yes  |
94|iso2022jp|                          |  Yes  |
95|gb18030  |                          |  Yes  |
96|gbk      |                          |  Yes  |
97|gb2312   |                          |  Yes  |
98|big5     |bigfive, cp950, big5hkscs |  Yes  |
99|euckr    |ksc5601, ksx1001, cp949   |  Yes  |
100|iso88591 |latin1                    |  Yes  |
101|iso88592 |                          |  Yes  |
102|iso88593 |                          |  Yes  |
103|iso88594 |                          |  Yes  |
104|iso88595 |                          |  Yes  |
105|iso88596 |                          |  Yes  |
106|iso88597 |                          |  Yes  |
107|iso88598 |                          |  Yes  |
108|iso88599 |                          |  Yes  |
109|iso885910|                          |  Yes  |
110|iso885911|tis620                    |  Yes  |
111|iso885913|                          |  Yes  |
112|iso885914|                          |  Yes  |
113|iso885915|latin9                    |  Yes  |
114|iso885916|                          |  Yes  |
115|cp1250   |windows1250               |  Yes  |
116|cp1251   |windows1251               |  Yes  |
117|cp1252   |windows1252               |  Yes  |
118|cp1253   |windows1253               |  Yes  |
119|cp1254   |windows1254               |  Yes  |
120|cp1255   |windows1255               |  Yes  |
121|cp1256   |windows1256               |  Yes  |
122|cp1257   |windows1257               |  Yes  |
123|cp1258   |windows1258               |  Yes  |
124|koi8r    |                          |  Yes  |
125|koi8u    |                          |  Yes  |
126|cp437    |                          |  Yes  |
127|cp850    |                          |  Yes  |
128|cp866    |                          |  Yes  |
129|cp1047   |ibm1047                   |  Yes  |
130
131## musl APIs Not Supported
132
133[Native API Symbols Not Exported](musl-peculiar-symbol.md)
134
135[NDK-Related musl libc Interface Usage Restrictions](guidance-on-ndk-libc-interfaces-affected-by-permissions.md)
136
137[NDK musl-libc Supplementary APIs](https://gitee.com/openharmony/third_party_musl/tree/master/docs)
138<!--no_check-->
139