- Learning Embedded Linux Using the Yocto Project
- Alexandru Vaduva
- 1468字
- 2021-07-16 13:49:32
Delving into C libraries
The first library that we'll discuss here is the glibc
library, which is designed for performance, compliance of standards, and portability. It was developed by the Free Software Foundation for the GNU/Linux operating system and is still present today on all GNU/Linux host systems that are actively maintained. It was released under the GNU Lesser General Public License.
The glibc
library was initially written by Roland McGrath in the 1980s and it continued to grow until the 1990s when the Linux kernel forked glibc
, calling it Linux libc
. It was maintained separately until January 1997 when the Free Software Foundation released glibc 2.0
. The glibc 2.0
contained so many features that it did not make any sense to continue the development of Linux libc
, so they discontinued their fork and returned to using glibc
. There are changes that are made in Linux libc
that were not merged into glibc
because of problems with the authorship of the code.
The glibc
library is quite large in terms of its dimensions and isn't a suitable fit for small embedded systems, but it provides the functionality required by the Single UNIX Specification (SUS), POSIX, ISO C11, ISO C99, Berkeley Unix interfaces, System V Interface Definition, and the X/Open Portability Guide, Issue 4.2, with all its extensions common with X/Open System Interface compliant systems along with X/Open UNIX extensions. In addition to this, GLIBC also provides extensions that have been deemed useful or necessary while developing GNU.
The next C library that I'm going to discuss here is the one that resides as the main C library used by the Yocto Project until version 1.7. Here, I'm referring to the eglibc
library. This is a version of glibc
optimized for the usage of embedded devices and is, at the same time, able to preserve the compatibility standards.
Since 2009, Debian and a number of its derivations chose to move from the GNU C Library to eglibc
. This might be because there is a difference in licensing between GNU LGPL and eglibc
, and this permits them to accept patches that glibc
developers my reject. Since 2014, the official eglibc
homepage states that the development of eglibc
was discontinued because glibc
had also moved to the same licensing, and also, the release of Debian Jessie meant that it had moved back to glibc
. This also happened in the case of Yocto support when they also decided to make glibc
their primary library support option.
The newlib
library is another C library developed with the intention of being used in embedded systems. It is a conglomerate of library components under free software licenses. Developed by Cygnus Support and maintained by Red Hat, it is one of the preferred versions of the C library used for non-Linux embedded systems.
The newlib
system calls describe the usage of the C library across multiple operation systems, and also on embedded systems that do not require an operating system. It is included in commercial GCC distributions, such as Red Hat, CodeSourcery, Attolic, KPIT and others. It also supported by architecture vendors that include ARM, Renesas, or Unix-like environments, such as Cygwin, and even proprietary operating systems of the Amiga personal computer.
By 2007, it also got support from the toolchain maintainers of Nintendo DS, PlayStation, portable SDK Game Boy Advance systems, Wii, and GameCube development platforms. Another addition was made to this list in 2013 when Google Native Client SDK included newlib
as their primary C library.
Bionic is a derivate of the BSD C library developed by Google for Android based on the Linux kernel. Its development is independent of Android code development. It is licensed as 3-clause BSD license and its goals are publically available. These include the following:
- Small size: Bionic is smaller in size compared to
glibc
- Speed: This has designed CPUs that work at low frequencies
- BSD license: Google wished to isolate Android apps from GPL and LGPL licenses, and this is the reason it moved to a non-copyleft license which are as follows:
- Android is based on a Linux kernel which is based on a GPLv2 license
glibc
is based on LGPL, which permits the linking of dynamic proprietary libraries but not with static linking
It also has a list of restrictions compared to glibc
, as follows:
- It does not include C++ exception handling, mainly because most the code used for Android is written in Java.
- It does not have wide character support.
- It does not include a Standard Template library, although it can be included manually.
- It functions within Bionic POSIX and even system call headers are wrappers or stubs for Android -specific functions. This may lead to odd behavior sometimes.
- When Android 4.2 released, it included support for
glibc
FORTIFY_SOURCE
features. These features are very often used in Yocto, and embedded systems in general, but are only present in thegcc
version for Android devices with ARM processors.
The next C library that will be discussed is musl
. It is a C library intended for use with Linux operating systems for embedded and mobile systems. It has a MIT license and was developed with the idea of having a clean, standard-compliant libc
, which is time efficient, since it's been developed from scratch. As a C library, it is optimized for the linking of static libraries. It is compatible with C99 standard and POSIX 2008, and implements Linux, glibc
, and BSD non-standard functions.
Next, we'll discuss uClibc
, which is a C standard library designed for Linux embedded systems and mobile devices. Although initially developed for μClinux and designed for microcontrollers, it gathered track and became the weapon of choice for anyone who's has limited space on their device. This has become popular due to the following reasons:
- It focuses on size rather than performance
- It has a GNU Lesser General Public License (LGPL) free license
- It is much smaller the glibc and reduces compilation time
- It has high configurability due to the fact that many of its features can be enabled using a
menuconfig
interface similar to the one available on packages, such as Linux kernel, U-Boot, or even BusyBox
The uClibc
library also has another quality that makes it quite useful. It introduces a new ideology and, because of this, the C library does not try to support as many standards as possible. However, it focuses on embedded Linux and consists of the features necessary for developers who face the limitation of available space. Due to this reason, this library was written from scratch, and even though it has its fair share of limitations, uClibc
is an important alternative to glibc
. If we take into consideration the fact that most of the features used from C libraries are present in it, the final size is four times smaller, and WindRiver, MontaVista, and TimeSys are active maintainers of it.
The dietlibc
library is a standard C library that was developed by Felix von Leitner and released under the GNU GPL v2 license. Although it also contains some commercial licensed components, its design was based on the same idea as uClibc
: the possibility of compiling and linking software while having the smallest size possible. It has another resemblance to uClibc
; it was developed from scratch and has only implemented the most used and known standard functions. Its primary usage is mainly in the embedded devices market.
The last in the C libraries list is the klibc
standard C library. It was developed by H. Peter Anvin and it was developed to be used as part of the early user space during the Linux startup process. It is used by the components that run the the kernel startup process but aren't used in the kernel mode and, hence, they do not have access to the standard C library.
The development of klibc
started in 2002 as an initiative to remove the Linux initialization code outside a kernel. Its design makes it suitable for usage in embedded devices. It also has another advantage: it is optimized for small size and correctness of data. The klibc
library is loaded during the Linux startup process from initramfs (a temporary Ram filesystem) and is incorporated by default into initramfs using the mkinitramfs
script for Debian and Ubuntu-based filesystems. It also has access to a small set of utilities, such as mount
, mkdir
, dash
, mknod
, fstype
, nfsmount
, run-init
and so on, which are very useful in the early init stage.
Note
More information on initramfs can be found using the kernel documentation at https://www.kernel.org/doc/Documentation/filesystems/ramfs-rootfs-initramfs.txt.
The klibc
library is licensed under GNU GPL since it uses some components from the Linux kernel, so, as a whole, it is visible as a GPL licensed software, limiting its applicability in commercial embedded software. However, most of the source code of libraries is written under the BSD license.
- 大學計算機基礎(第二版)
- Cocos2D-X權威指南(第2版)
- TypeScript入門與實戰
- Mastering JavaScript Object-Oriented Programming
- Effective C#:改善C#代碼的50個有效方法(原書第3版)
- Java程序設計
- FPGA Verilog開發實戰指南:基于Intel Cyclone IV(進階篇)
- PHP編程基礎與實例教程
- Web性能實戰
- Scala編程(第5版)
- TypeScript 2.x By Example
- Practical Microservices
- 金融商業數據分析:基于Python和SAS
- 透視C#核心技術:系統架構及移動端開發
- Learning Alfresco Web Scripts