HOME

TheInfoList



OR:

Bionic is an implementation of the
C standard library The C standard library, sometimes referred to as libc, is the standard library for the C (programming language), C programming language, as specified in the ISO C standard.International Organization for Standardization, ISO/International Electrote ...
, developed by
Google Google LLC (, ) is an American multinational corporation and technology company focusing on online advertising, search engine technology, cloud computing, computer software, quantum computing, e-commerce, consumer electronics, and artificial ...
for its Android
operating system An operating system (OS) is system software that manages computer hardware and software resources, and provides common daemon (computing), services for computer programs. Time-sharing operating systems scheduler (computing), schedule tasks for ...
. It differs from the GNU C Library (glibc) in being designed for devices with less memory and processor power than a typical
Linux Linux ( ) is a family of open source Unix-like operating systems based on the Linux kernel, an kernel (operating system), operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically package manager, pac ...
system. It is a combination of new code and code from
FreeBSD FreeBSD is a free-software Unix-like operating system descended from the Berkeley Software Distribution (BSD). The first version was released in 1993 developed from 386BSD, one of the first fully functional and free Unix clones on affordable ...
,
NetBSD NetBSD is a free and open-source Unix-like operating system based on the Berkeley Software Distribution (BSD). It was the first open-source BSD descendant officially released after 386BSD was fork (software development), forked. It continues to ...
, and
OpenBSD OpenBSD is a security-focused operating system, security-focused, free software, Unix-like operating system based on the Berkeley Software Distribution (BSD). Theo de Raadt created OpenBSD in 1995 by fork (software development), forking NetBSD ...
released under a
BSD license BSD licenses are a family of permissive free software licenses, imposing minimal restrictions on the use and distribution of covered software. This is in contrast to copyleft licenses, which have share-alike requirements. The original BSD lic ...
, rather than glibc, which uses the
GNU Lesser General Public License The GNU Lesser General Public License (LGPL) is a free-software license published by the Free Software Foundation (FSF). The license allows developers and companies to use and integrate a software component released under the LGPL into their own ...
. This difference was important in the early days of Android, when static linking was common, and since Bionic has its own
application binary interface An application binary interface (ABI) is an interface exposed by software that is defined for in-process machine code access. Often, the exposing software is a library, and the consumer is a program. An ABI is at a relatively low-level of a ...
, it cannot be replaced by a different libc without breaking all existing apps. Bionic is a C library for use with the
Linux kernel The Linux kernel is a Free and open-source software, free and open source Unix-like kernel (operating system), kernel that is used in many computer systems worldwide. The kernel was created by Linus Torvalds in 1991 and was soon adopted as the k ...
, and provides
libc The C standard library, sometimes referred to as libc, is the standard library for the C programming language, as specified in the ISO C standard.ISO/ IEC (2018). '' ISO/IEC 9899:2018(E): Programming Languages - C §7'' Starting from the origina ...
, libdl, and libm ( libpthread functionality is part of
libc The C standard library, sometimes referred to as libc, is the standard library for the C programming language, as specified in the ISO C standard.ISO/ IEC (2018). '' ISO/IEC 9899:2018(E): Programming Languages - C §7'' Starting from the origina ...
, not a separate library as on some other systems). This differs from the
BSD The Berkeley Software Distribution (BSD), also known as Berkeley Unix or BSD Unix, is a discontinued Unix operating system developed and distributed by the Computer Systems Research Group (CSRG) at the University of California, Berkeley, beginni ...
C libraries that Bionic shares code with, because they require a BSD kernel.


Original goals

The original publicly stated goals for Bionic were the following: * BSD-licensed: Google wanted to isolate Android applications from the effect of
copyleft Copyleft is the legal technique of granting certain freedoms over copies of copyrighted works with the requirement that the same rights be preserved in derivative works. In this sense, ''freedoms'' refers to the use of the work for any purpose, ...
licenses to create a proprietary user-space and application ecosystem, but: ** Android is based on the Linux kernel, which is subject to the copyleft GNU General Public License (GPL) version 2. ** The most widespread standard C library for the Linux kernel is the GNU C Library (glibc), which is subject to the GNU Lesser General Public License (LGPL), also a copyleft license. In contrast to the GPL, the LGPL explicitly allows for dynamic linking but it does not allow static linking of proprietary software without providing source code or linkable object files. ** The permissive BSD license is a non-
copyleft Copyleft is the legal technique of granting certain freedoms over copies of copyrighted works with the requirement that the same rights be preserved in derivative works. In this sense, ''freedoms'' refers to the use of the work for any purpose, ...
license that is compatible in both directions. A BSD-licensed glibc substitute could act as an isolation layer between the copyleft core (kernel) and the non-copyleft applications, and was therefore chosen by Google for its Bionic as a glibc substitute. * Small size: Bionic was much smaller than the GNU C Library; more importantly its memory requirements were (and remain) much lower. * Speed: Bionic was designed for CPUs at relatively low clock frequencies.


Supported architectures

Bionic only supports Linux kernels, but currently supports the arm, arm64, riscv64, x86, and x86-64 architectures. The platform itself required armv7 with
Neon Neon is a chemical element; it has symbol Ne and atomic number 10. It is the second noble gas in the periodic table. Neon is a colorless, odorless, inert monatomic gas under standard conditions, with approximately two-thirds the density of ...
since
Marshmallow Marshmallow (, ) is a confectionery made from sugar, water and gelatin whipped to a solid-but-soft consistency. It is used as a filling in baking or molded into shapes and coated with corn starch. This sugar confection is inspired by a medicina ...
, though the Android Native Development Kit (NDK) continued to support armv5 (which it called armeabi) up until NDK r16. The NDK still supports armv7, though NDK r24 dropped support for non-Neon. Historically there was partial SH-4 support in the platform, but no devices ever shipped and support has since been removed. The NDK never supported SH-4, and MIPS and MIPS64 support were removed from the NDK in r17.


Components

Some parts of the libc source, such as stdio, are from the BSDs (mainly
OpenBSD OpenBSD is a security-focused operating system, security-focused, free software, Unix-like operating system based on the Berkeley Software Distribution (BSD). Theo de Raadt created OpenBSD in 1995 by fork (software development), forking NetBSD ...
), whereas others, such as the pthread implementation, were written from scratch. The dynamic memory allocator implementation has changed over time. Before Lollipop there was a single native memory allocator, Doug Lea's dlmalloc. For Lollipop and Marshmallow there were two implementations: dlmalloc and jemalloc. jemalloc gives much higher performance than dlmalloc, but at the cost of extra memory required for bookkeeping. Most devices used jemalloc but low-memory devices still used dlmalloc. For Nougat through Android 10, all devices use jemalloc. Low-memory devices use a "svelte" configuration of jemalloc that disables the tcache to nearly match the lower memory overhead of dlmalloc while keeping most of the speed of jemalloc. In Android 11, the memory allocator for most devices was switched to Scudo, which sacrifices some of jemalloc's high performance for additional security hardening features. Low-memory devices, however, are still permitted to use jemalloc. Some 64-bit devices, like the Nexus 9, are effectively low-memory devices because of the extra space requirements of 64-bit pointers and hosting of two zygotes. (Zygote is an Android system service that is the parent of all Android application processes.) The libm source is largely
FreeBSD FreeBSD is a free-software Unix-like operating system descended from the Berkeley Software Distribution (BSD). The first version was released in 1993 developed from 386BSD, one of the first fully functional and free Unix clones on affordable ...
's, but with optimized assembler contributed by the various SoC vendors. The dynamic linker (and libdl) were written from scratch. Bionic doesn't include libthread_db (used by gdbserver), but the NDK did. The Android platform included a statically linked gdbserver, so that developers can use the latest gdb even on old devices. Since Android dropped gdb support and switched to lldb, this is no longer relevant. There is no separate libpthread, libresolv, or librt on Android the functionality is all in libc. For libpthread, there is no attempt to optimize for the single-threaded case because apps are in a multi-threaded environment even before the first instruction of third-party code is ever run. The Android platform uses libc++ for the C++ standard library (releases up to and including Lollipop used stlport). The NDK historically offered stlport and GNU libstdc++, but those were removed as of NDK r18. Note that if any native code in an Android app uses C++, all the C++ must use the ''same'' STL. The STL is not provided by the Android OS, and must be bundled with each app.


Differences from POSIX

Although Bionic aims to implement all of C11 and
POSIX The Portable Operating System Interface (POSIX; ) is a family of standards specified by the IEEE Computer Society for maintaining compatibility between operating systems. POSIX defines application programming interfaces (APIs), along with comm ...
, there are still (as of Android 15) about 11 POSIX functions missing from libc. There are also POSIX functions such as the endpwent/getpwent/setpwent family that are inapplicable to Android because it lacks a passwd database. As of Oreo, libm is complete. Some functions deliberately do not conform to the POSIX or C standards for security reasons, such as printf which does not support the %n format string. Many of the most-used GNU extensions are implemented in Bionic, as are various BSD extensions.


Relationship to the NDK

Platform code uses Bionic directly, but third-party developers use the Android Native Development Kit (NDK). Many third-party developers still target older OS releases, which contributes to a widespread belief that Bionic lacks many features.
Gingerbread Gingerbread refers to a broad category of baked goods, typically flavored with ginger root, ginger, cloves, nutmeg, and cinnamon and sweetened with honey, sugar, or molasses. Gingerbread foods vary, ranging from a moist loaf cake to forms nearly ...
exported 803 functions from libc but Oreo exports 1278 (a 1.6x increase). Historically the NDK and the platform diverged, but NDK r11 and later have replaced NDK forks with their current platform equivalents. This work initially focused on the GCC and
Clang Clang () is a compiler front end for the programming languages C, C++, Objective-C, Objective-C++, and the software frameworks OpenMP, OpenCL, RenderScript, CUDA, SYCL, and HIP. It acts as a drop-in replacement for the GNU Compiler ...
compilers. Prior to NDK r14, when "unified" headers were first offered on an opt-in basis, the NDK had forked copies of the platform headers for different API levels. This meant that header-only fixes (fixes to constant or structure definitions, for example) weren't available to most NDK users because they'd be targeting an older API level, but platform fixes were only going in to the current platform headers. In the Oreo development period the platform headers were annotated with API level information so that the same set of headers can be used for all API levels, with only those functions available at the developer's targeted API level being visible. These are the so-called "unified" headers, and have been the default since NDK r15. Prior to NDK r16, the NDK linked a library called libandroid_support.a to code using libc++ to provide functions required by libc++ that weren't in old OS releases. This wasn't the same code used by the platform and introduced numerous bugs (such as breaking positional arguments to the printf family in any code that used libc++). From NDK r16 to r25, libandroid_support.a still existed but was built directly from the then-current platform source at the time each NDK was built. From NDK r26, libandroid_support.a is gone, because all OS versions still supported by the NDK contain everything needed by libc++.


Fortify source

As of Android Jelly Bean MR1 (4.2), Bionic supports similar functionality to glibc's _FORTIFY_SOURCE, which is a feature where unsafe string and memory functions (such as strcpy(), strcat(), and memcpy()) include checks for buffer overruns. These checks are performed at compile time if the buffer sizes can be determined at compile time, or run-time otherwise. Because fortify relies on runtime support from libc, its portability to older Android releases is limited. The platform itself is built with _FORTIFY_SOURCE enabled. Historically, one of the shortcomings of fortify has been that it is closely tied with GCC, which makes it very difficult to support well in other compilers, like Clang. This meant that when Android swapped to Clang as its default compiler, Bionic's fortify implementation became substantially less useful. In Android Oreo (8.0), Bionic's fortify was overhauled with Clang in mind, resulting in fortify on Clang providing an experience on par with fortify on GCC. Since this overhaul, some checks were added above and beyond glibc's to catch code that — while not necessarily causing undefined behavior — is obviously incorrect. Because this new implementation requires no more libc support than the prior one, the Clang-specific enhancements are available to applications targeting versions of Android before Oreo.


Controversies

For the creation of Bionic, Google used GPLv2-licensed Linux kernel
header file An include directive instructs a text file processor to replace the directive text with the content of a specified file. The act of including may be logical in nature. The processor may simply process the include file content at the location of ...
s. To get rid of the GPL, Google claimed that it cleaned the header files from any copyright-able work, reducing them to non-copyrightable "facts".Android: Sued by Microsoft, not by Linux
"Microsoft launches new Android suit, Linus Torvalds' take on Linux kernel headers and Android" on ITworld (March 21, 2011)
Linux creator
Linus Torvalds Linus Benedict Torvalds ( , ; born 28 December 1969) is a Finnish software engineer who is the creator and lead developer of the Linux kernel. He also created the distributed version control system Git. He was honored, along with Shinya Yam ...
considered Google's behaviour to be acceptable, but Google's interpretation of the GPL has been challenged, for instance by Raymond Nimmer, a law professor at the University of Houston Law Center.Infringement and disclosure risk in development on copyleft platforms
on ipinfoblog.com by Raymond Nimmer (2011)


See also

* Hybris (also known as ''libhybris'') * musl *
Toybox Toybox is a free and open-source software implementation of over 200 Unix command line utilities such as '' ls'', '' cp'', and '' mv''. The Toybox project was started in 2006, and became a 0BSD licensed BusyBox alternative. Toybox is used for m ...


References


External links

*
Developer home page for Android

Android Native Development Kit (NDK) home page

Bionic sources (official repository)

Bionic notes on eLinux.org
{{CProLang Android (operating system) C standard library Interfaces of the Linux kernel Software using the BSD license