Bionic is an implementation of the
standard C library, developed by
Google
Google LLC () is an American Multinational corporation, multinational technology company focusing on Search Engine, search engine technology, online advertising, cloud computing, software, computer software, quantum computing, e-commerce, ar ...
for its
Android
Android may refer to:
Science and technology
* Android (robot), a humanoid robot or synthetic organism designed to imitate a human
* Android (operating system), Google's mobile operating system
** Bugdroid, a Google mascot sometimes referred to ...
operating system
An operating system (OS) is system software that manages computer hardware, software resources, and provides common daemon (computing), services for computer programs.
Time-sharing operating systems scheduler (computing), schedule tasks for ef ...
.
It differs from the
GNU C Library (glibc) in being designed for devices with less memory and processor power than a typical
Linux
Linux ( or ) is a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically packaged as a Linux distribution, which i ...
system. It is a combination of new code and code from
FreeBSD
FreeBSD is a free and open-source Unix-like operating system descended from the Berkeley Software Distribution (BSD), which was based on Research Unix. The first version of FreeBSD was released in 1993. In 2005, FreeBSD was the most popular ...
,
NetBSD
NetBSD is a free and open-source Unix operating system based on the Berkeley Software Distribution (BSD). It was the first open-source BSD descendant officially released after 386BSD was forked. It continues to be actively developed and is a ...
, and
OpenBSD
OpenBSD is a security-focused operating system, security-focused, free and open-source, Unix-like operating system based on the Berkeley Software Distribution (BSD). Theo de Raadt created OpenBSD in 1995 by fork (software development), forking N ...
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 li ...
, 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 is still helpful in introducing Android to software companies used to proprietary operating systems, who can be wary of the LGPL, and unclear about the differences between it and the full
GNU General Public License
The GNU General Public License (GNU GPL or simply GPL) is a series of widely used free software licenses that guarantee end user
In product development, an end user (sometimes end-user) is a person who ultimately uses or is intended to ulti ...
(GPL).
Bionic is a C library for use with the
Linux kernel
The Linux kernel is a free and open-source, monolithic, modular, multitasking, Unix-like operating system kernel. It was originally authored in 1991 by Linus Torvalds for his i386-based PC, and it was soon adopted as the kernel for the GNU ...
, and provides
libc
The C standard library or 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 original ANSI C standard, it wa ...
,
libdl, and
libm (
libpthread functionality is part of
libc
The C standard library or 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 original ANSI C standard, it wa ...
, not a separate library as on some other systems). This differs from the
BSD C libraries that bionic shares code with, because they require a BSD
kernel
Kernel may refer to:
Computing
* Kernel (operating system), the central component of most operating systems
* Kernel (image processing), a matrix used for image convolution
* Compute kernel, in GPGPU programming
* Kernel method, in machine lea ...
.
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
A modern computer operating system usually segregates virtual memory into user space and kernel space. Primarily, this separation serves to provide memory protection and hardware protection from malicious or errant software behaviour.
Kern ...
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, x86, and x86-64 architectures. The platform itself required armv7 with
Neon
Neon is a chemical element with the symbol Ne and atomic number 10. It is a noble gas. Neon is a colorless, odorless, inert monatomic gas under standard conditions, with about two-thirds the density of air. It was discovered (along with krypt ...
since
Marshmallow
Marshmallow (, ) is a type of confectionery that is typically made from sugar, water and gelatin whipped to a solid-but-soft consistency. It is used as a filling in baking or normally molded into shapes and coated with corn starch. The sugar c ...
, though the
Android Native Development Kit (NDK) continued to support armv5 (which it called armeabi) up until NDK r16. The NDK still supports armv7 both with and without 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 and open-source, Unix-like operating system based on the Berkeley Software Distribution (BSD). Theo de Raadt created OpenBSD in 1995 by fork (software development), forking N ...
), whereas others, such as the
pthread
POSIX Threads, commonly known as pthreads, is an execution model that exists independently from a language, as well as a parallel execution model. It allows a program to control multiple different flows of work that overlap in time. Each flow of ...
implementation, were written from scratch.
The
dynamic memory allocator implementation has changed over time. Before
Lollipop
A lollipop is a type of sugar candy usually consisting of hard candy mounted on a stick and intended for sucking or licking. Different informal terms are used in different places, including lolly, sucker, sticky-pop, etc. Lollipops are av ...
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
Nougat ( , ; ; az, nuqa; fa, نوقا) is a family of confections made with sugar or honey, roasted nuts ( almonds, walnuts, pistachios, hazelnuts, and macadamia nuts are common), whipped egg whites, and sometimes chopped candied fruit. ...
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 and open-source Unix-like operating system descended from the Berkeley Software Distribution (BSD), which was based on Research Unix. The first version of FreeBSD was released in 1993. In 2005, FreeBSD was the most popular ...
'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 does. The Android platform includes a statically linked gdbserver, so that developers can use the latest
gdb even on old devices.
There is no separate libpthread, libresolv, or librt on Android the functionality is all in libc. For libpthread, there's 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 STL may refer to:
Communications
* Standard telegraph level
*Studio/transmitter link
International law
*Special Tribunal for Lebanon
The Special Tribunal for Lebanon (STL), also referred to as the Lebanon Tribunal or the Hariri Tribunal, is a ...
. 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 C11, C.XI, C-11 or C.11 may refer to:
Transport
* C-11 Fleetster, a 1920s American light transport aircraft for use of the United States Assistant Secretary of War
* Fokker C.XI, a 1935 Dutch reconnaissance seaplane
* LET C-11, a license-build var ...
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 both the system- and user-level application programming inte ...
, there are still (as of Oreo) about 70 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
passwd is a command on Unix, Plan 9, Inferno, and most Unix-like operating systems used to change a user's password. The password entered by the user is run through a key derivation function to create a hashed version of the new password, wh ...
database. As of
Oreo
Oreo () (stylized as OREO) is a brand of sandwich cookie consisting of two biscuits or cookie pieces with a sweet creme filling. It was introduced by Nabisco on March 6, 1912, and through a series of corporate acquisitions, mergers and splits ...
, libm is complete.
Some functions deliberately do not conform to the POSIX or C standards for security reasons, such as
printf
The printf format string is a control parameter used by a class of functions in the input/output libraries of C and many other programming languages. The string is written in a simple template language: characters are usually copied liter ...
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, cloves, nutmeg, and cinnamon and sweetened with honey, sugar, or molasses. Gingerbread foods vary, ranging from a moist loaf cake to forms nearly as crisp a ...
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 C, C++, Objective-C, and Objective-C++ programming languages, as well as the OpenMP, OpenCL, RenderScript, CUDA, and HIP frameworks. It acts as a drop-in replacement for the GNU Compiler Collection ...
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++. This provided 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++). In NDK r16 libandroid_support.a still exists, but is now built directly from platform source (current at the time the NDK is built).
Fortify source
As of
Android Jelly Bean
Android Jelly Bean, or Android 4.1 is the codename given to the tenth version of the Android mobile operating system developed by Google, spanning three major point releases (versions 4.1 through 4.3.1). Among the devices that run Android 4.1 t ...
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
Many programming languages and other computer files have a directive, often called include (sometimes copy or import), that causes the contents of the specified file to be inserted into the original file. These included files are called copybooks ...
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](_blank)
"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, historically, the lead developer of the Linux kernel, used by Linux distributions and other operating systems such as Android. He also ...
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
The University of Houston Law Center is the law school of the University of Houston in Houston, Texas. Founded in 1947, the Law Center is one of 12 colleges of the University of Houston, a state university. It is accredited by the American Bar A ...
.
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 ...
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