Hubbry Logo
NewlibNewlibMain
Open search
Newlib
Community hub
Newlib
logo
7 pages, 0 posts
0 subscribers
Be the first to start a discussion here.
Be the first to start a discussion here.
Newlib
Newlib
from Wikipedia
Newlib
Original authorCygnus Support
DeveloperRed Hat
Stable release
4.5.0 / December 31, 2024; 9 months ago (2024-12-31)[1]
Repository
Operating systemCross-platform[citation needed]
TypeRuntime library
LicenseVarious MIT/BSD-like licenses
Websitewww.sourceware.org/newlib/

Newlib is a C standard library implementation intended for use on embedded systems. It is a conglomeration of several library parts, all under free software licenses that make them easily usable on embedded products.

It was created by Cygnus Support as part of building the first GNU cross-development toolchains. It is now maintained by Red Hat developers Jeff Johnston and Corinna Vinschen, and is used in most commercial and non-commercial GCC ports for non-Linux embedded systems.

System calls

[edit]

The section System Calls[2] of the Newlib documentation describes how it can be used with many operating systems. Its primary use is on embedded systems that lack any kind of operating system; in that case it calls a board support package that can do things like write a byte of output on a serial port, or read a sector from a disk or other memory device.

Inclusion

[edit]

Newlib is included in commercial GCC distributions by Atollic, CodeSourcery, Code Red, KPIT, Red Hat and others, and receives support from major embedded-processor architecture vendors such as ARM and Renesas. It is used as the standard C library in Cygwin, as well as being one standard C library among several for AmigaOS 4.

As of 2004, KallistiOS, an independent SDK targeting the Sega Dreamcast, has used Newlib as its standard C library, shipping it with many commercial titles on the platform.[3]

As of 2007, devkitARM and devkitPPC, toolchains targeted at homebrew development for commercial game systems, include Newlib as their C library. The Open-R SDK for Sony AIBO is also based on Newlib on top of the non-Unix Aperios.

As of 2013, Google Native Client SDK (NaCl) includes Newlib as the default C library over glibc.[4]

In 2019, Keith Packard released Picolibc,[5] a library offering standard C library APIs that targets small embedded systems with limited RAM, based on blending code from Newlib and AVR Libc.

See also

[edit]
Other C standard libraries

References

[edit]

Further reading

[edit]
[edit]
Revisions and contributorsEdit on WikipediaRead on Wikipedia
from Grokipedia
Newlib is an open-source implementation primarily designed for use on embedded systems and in cross-development environments. It serves as a lightweight, portable alternative to full-featured libraries like , providing core functions such as printf(), malloc(), and file I/O operations while supporting resource-constrained hardware. Developed as a conglomeration of software components from multiple sources, Newlib was originally assembled by (now part of ) in the 1990s to support early cross-compilation toolchains. Newlib's architecture emphasizes modularity and configurability, allowing developers to enable or disable features like multibyte character support, hardware floating-point acceleration, or space-optimized algorithms via build options such as --enable-newlib-mb or --enable-target-optspace. This flexibility makes it suitable for a wide range of microcontrollers and real-time operating systems (RTOS), including integrations with toolchains like GCC, and platforms such as , Zephyr, and . Licensing is permissive and varied across its components—encompassing BSD, , and other licenses—ensuring no requirement for source code disclosure or royalties in derivative projects, which facilitates its widespread adoption in commercial embedded products. Annual snapshots are released from its Sourceware repository, with ongoing maintenance focused on compatibility with evolving C standards and embedded hardware trends.

History and Development

Origins and Creation

Newlib was created by in the late 1990s as part of the effort to build the first GNU cross-development toolchains for embedded targets lacking native operating system support. This initiative addressed the need for a compact that could operate in resource-constrained environments, enabling developers to compile and run code on diverse hardware without relying on heavy-weight system libraries. The library was assembled by combining existing free software components from multiple open-source implementations, including parts derived from BSD and other public domain codebases. These sources were selected for their permissive licenses, such as MIT and BSD variants, which allowed redistribution and modification while ensuring compatibility with the GNU toolchain. This modular approach facilitated rapid development and broad applicability across different architectures. Newlib's initial design emphasized a lightweight alternative to full-featured libraries like , prioritizing minimal dependencies to suit bare-metal and (RTOS) environments. , a key early contributor, integrated Newlib directly with the GNU Compiler Collection (GCC), streamlining cross-compilation workflows for embedded developers. It has since evolved into modern releases under maintenance.

Maintainers and Release History

Following the acquisition of Cygnus Support by Red Hat in 1999, Newlib's maintenance transitioned to Red Hat sponsorship around 2001, with primary maintainers Jeff Johnston ([email protected]) and Corinna Vinschen ([email protected]) overseeing development as Red Hat employees. Newlib follows an annual release cadence for major versions, with early versions dating back to the late 1990s; subsequent releases include 2.0.0 in December 2012, 3.0.0 in January 2018, 4.0.0 in November 2020, 4.4.0 in December 2023, and the latest stable version 4.5.0 released on December 31, 2024. Key milestones include integration with the GNU Compiler Collection (GCC) to support cross-development toolchains, the introduction of the nano-newlib variant in the 2010s (specifically with GCC Embedded 4.7 in 2013) for resource-constrained embedded devices, and enhancements in versions 4.x such as support for new ISA extensions and ongoing architecture improvements. Development occurs through the Git repository hosted on Sourceware.org, with contributions submitted as patches via the [email protected] mailing list using git format-patch and git send-email formats, emphasizing a focus on maintaining backward compatibility across releases.

Architecture and Components

Core Library Structure

Newlib's core library is structured as a modular amalgamation of several key components designed for embedded environments, primarily consisting of the standard C library (libc), which implements core functions such as string manipulation, memory allocation, and input/output operations, and the mathematics library (libm), which provides floating-point arithmetic routines compliant with IEEE 754 standards. These sub-libraries form the foundational bulk of Newlib, with additional support modules integrated for compatibility with compilers like GCC, including runtime routines that handle low-level operations not covered by the standard C specification. A critical aspect of Newlib's internal organization is its reentrancy mechanism, which manages global variables through a single structure pointed to by the global pointer _impure_ptr. This pointer references a struct _reent instance, containing thread-specific state such as errno, file descriptors, and buffers, enabling safe operation in multi-threaded or "impure" environments where multiple execution contexts may access shared resources concurrently. By default, Newlib initializes _impure_ptr to a single global _reent structure for single-threaded use, but in hosted environments, it can be dynamically reassigned per thread to maintain isolation and prevent race conditions during library calls. The library's design emphasizes modularity, permitting developers to selectively include or exclude features during compilation to optimize for resource-constrained targets; for instance, floating-point support from libm can be omitted to significantly reduce code size in integer-only applications. This configurability is achieved through build-time options in the Newlib configuration system, allowing tailored builds like the lightweight "newlib-nano" variant that strips non-essential components while retaining core functionality. All components of Newlib are distributed under permissive licenses, with the core libc and libm primarily governed by the BSD license to facilitate broad adoption, while certain extensions and target-specific modules use GPL-compatible terms such as LGPL v2.1, ensuring compatibility for redistribution in both open-source and toolchains without imposing restrictions on linking applications. This licensing approach, originating from contributions by entities like and the , underscores Newlib's emphasis on portability and vendor neutrality.

System Call Mechanism

Newlib interfaces with operating systems or hardware through a set of low-level stubs, which provide a uniform mechanism for operations such as and allocation. These stubs, such as _read, _write, and _open, are not implemented within the core library but must be supplied by the host environment, (BSP), or application code to enable functionality like file access or console output. For instance, the _write stub typically directs output to a specific device, while _open manages resource initialization, ensuring Newlib remains portable across diverse targets. The library supports multiple layers of system call implementations to accommodate varying environments. In hosted settings with POSIX-compliant systems, stubs invoke standard OS calls for full compatibility. For bare-metal applications without an OS, minimal stubs perform direct hardware interactions, such as returning codes or zero for unsupported operations like _read (which might return 0 to indicate ). RTOS integrations, such as with , extend this by providing hooks that route calls through the RTOS's scheduling and resource management, allowing seamless operation in multithreaded contexts. To support reentrancy in concurrent environments, Newlib offers variant stubs like _read_r, _write_r, and _open_r that accept a pointer to a reentrancy structure (struct _reent), enabling per-thread . The global _impure_ptr variable points to this structure, which stores thread-specific state, including errno values and file operation contexts, for syscalls involving dynamic allocation (e.g., malloc) or I/O. This design prevents across threads by isolating resources, with the structure initialized in startup code like crt0.c. In embedded targets, syscall stubs often feature simple, hardware-specific implementations; for example, a bare-metal _write might poll a UART peripheral to transmit characters sequentially without buffering or interrupts, ensuring reliable I/O on resource-constrained devices like microcontrollers. Such stubs are typically defined in a syscalls.c file within the BSP, overriding default weak symbols from Newlib's libnosys.a library.

Features and Design Principles

Embedded System Adaptations

Newlib is particularly suited for embedded systems through its configurable options that minimize resource usage, such as the nano variant, which achieves a smaller footprint by excluding non-essential features like full locale support and advanced stdio buffering. The nano variant significantly reduces the code size compared to the full implementation, often by around 80% or more in sample applications, enabling deployment on memory-constrained microcontrollers without sacrificing core C standard library functionality. This size optimization is achieved via build-time configurations that prioritize code density over comprehensive feature sets, making it ideal for applications where every kilobyte matters. A key adaptation for embedded environments is Newlib's lack of inherent assumptions about operating system services, instead depending on user-supplied stubs for system calls related to time, , and operations. This design facilitates bare-metal operation on resource-limited hardware, such as series microcontrollers, where developers implement minimal syscall handlers to interface with hardware peripherals directly. By avoiding dependencies on a full OS, Newlib ensures portability and low overhead in environments without multitasking or file systems. The math library component, libm, includes adaptations for embedded hardware lacking dedicated floating-point units, featuring software-emulated (soft-float) routines that can be selected during compilation. Precision is configurable to support either single-precision (float) or double-precision (double) operations, with dedicated functions like acosf for floats and acos for doubles to optimize performance and size based on application needs. These options allow developers to balance computational accuracy with the constraints of no-FPU devices, ensuring reliable mathematical computations in power-sensitive systems. For concurrent embedded applications, Newlib incorporates thread-safety via reentrancy support, employing compile-time flags and the _impure_ptr mechanism to direct library functions to per-thread reentrancy structures (_reent). This approach stores thread-local state, such as errno and file pointers, preventing conflicts in multi-threaded contexts without requiring a complex OS. It is well-suited for lightweight real-time operating systems like , where enabling reentrancy flags allows safe shared use of library routines across tasks.

Portability and Configuration

Newlib employs a GNU autotools-based build system, utilizing and to facilitate configuration and compilation across diverse host and target environments. The configuration process begins with the , which accepts numerous options to tailor the library for specific use cases, such as the nano variant, which is selected at compile time using GCC specifications such as --specs=nano.specs for memory-constrained embedded systems, or --enable-newlib-multithread to include support for threads through reentrant implementations. These options allow developers to generate a customized by specifying the target architecture and enabling or disabling features like reentrancy or formatted I/O optimizations during the build phase. The library's portability is achieved through its integration with GCC cross-compilers, enabling pre-built configurations for a wide range of architectures including x86, , and , often via board support packages (BSPs) provided by vendors. For instance, FPGA toolchains incorporate Newlib adaptations within their BSPs for Nios processors, while Nordic Semiconductor's SDKs leverage Newlib for ARM-based nRF devices, allowing seamless deployment on vendor-specific hardware without extensive porting efforts. This modular design, combined with Libgloss for low-level stubs, ensures that Newlib can be adapted to new targets by implementing a minimal set of architecture-specific routines, such as those in the libc/machine/ directory. Newlib's permissive licensing, primarily under a BSD-style license, supports flexible distribution models, including static linking into closed-source without requiring the disclosure of code. This contrasts with more restrictive licenses and facilitates its widespread adoption in commercial embedded products. To validate builds, Newlib includes a comprehensive testsuite run via make check-target-newlib, which employs the DejaGnu framework to execute regression tests assessing compliance with and C11 standards, such as string handling, floating-point operations, and standard I/O functions, ensuring reliability across configurations.

Adoption and Implementations

Inclusion in Toolchains

Newlib serves as the standard C library implementation in numerous GCC-based cross-compilers targeted at embedded systems, providing essential runtime support without relying on a full operating system. This integration enables developers to produce standalone executables for resource-constrained environments, where Newlib's allows for customization to minimize footprint. Prominent examples include the GNU Toolchain, which bundles Newlib as its default libc for Arm architectures, with the latest release (14.3.Rel1, dated July 2025) incorporating updates from GCC 14.3 and supporting bare-metal development across Cortex-M, Cortex-R, and Cortex-A series processors. Similarly, devkitPro toolchains for game console development, such as devkitARM and devkitPPC, rely on a forked version of Newlib optimized for embedded gaming applications, ensuring compatibility with hardware-specific syscalls. In embedded integrated development environments (IDEs), Newlib is integral to workflows like Atollic TrueSTUDIO (now part of ' ecosystem), where it defaults to the newlib-nano variant for reduced code size in Cortex-M projects starting from version 7.1.0. Intel's toolchain for FPGA-based soft processors formerly included precompiled Newlib libraries (libc.a and libm.a), facilitating C/C++ development on customizable hardware without additional configuration. A key aspect of Newlib's inclusion is its preference for static linking, which compiles the library directly into the binary to create self-contained executables suitable for no-OS (bare-metal) targets, avoiding overhead and ensuring portability across diverse hardware. This approach is particularly valuable in embedded scenarios where runtime environments are minimal or absent. Toolchains typically synchronize Newlib versions with their GCC releases to maintain compatibility and leverage optimizations; for instance, builds of GCC 14 often pair with recent Newlib versions, as seen in cross-compilation setups for architectures like M68K and , ensuring consistent ABI support and feature alignment.

Use in Operating Systems and Projects

Newlib serves as a core component in several -compliant environments, providing standard C library functionality for systems seeking behavior on non-traditional platforms. In , a layer for Windows, Newlib has been integral since its early versions, enabling support through a that maps system calls to Windows APIs. Similarly, utilizes Newlib as its primary C library, supporting the operating system's modernized subset and facilitating development for the hardware architecture. In embedded operating systems and real-time operating systems (RTOS), Newlib's lightweight design makes it suitable for resource-constrained environments. KallistiOS, a homebrew operating system for the released in 2004, integrates Newlib to provide essential libc functions for game and application development on the console. Zephyr RTOS incorporates Newlib as an option through the Nordic nRF Connect SDK, supporting low-power IoT devices and Bluetooth-enabled systems. Additionally, the (NaCl) SDK, introduced in 2013, employed Newlib to deliver a secure, sandboxed execution environment for web applications using native code. Newlib has found significant adoption in gaming and retro computing projects, particularly for console homebrew development. The devkitARM and devkitPPC toolchains, which target handheld and home consoles, have included Newlib since 2007, enabling C/C++ programming for the , , and platforms with optimized libc implementations. More recently, Newlib influences modern embedded projects through forks and integrations aimed at minimal resource usage. The Picolibc project, forked from Newlib in 2019, refines it for even smaller memory footprints in applications, though the original Newlib remains the foundational for numerous IoT firmware initiatives, such as those in wireless sensor networks and edge devices. It is often the default C library in GCC-based toolchains for such embedded targets.

References

Add your contribution
Related Hubs
User Avatar
No comments yet.