{"id":13741211,"url":"https://github.com/embeddedartistry/libc","last_synced_at":"2025-05-15T11:08:16.787Z","repository":{"id":20091128,"uuid":"88765798","full_name":"embeddedartistry/libc","owner":"embeddedartistry","description":"libc targeted for embedded systems usage.  Reduced set of functionality (due to embedded nature). Chosen for portability and quick bringup.","archived":false,"fork":false,"pushed_at":"2025-03-05T21:30:04.000Z","size":1730,"stargazers_count":579,"open_issues_count":37,"forks_count":75,"subscribers_count":24,"default_branch":"master","last_synced_at":"2025-04-14T19:59:03.411Z","etag":null,"topics":["bringup","c","embedded-systems","hacktoberfest","libc","meson","portability","test-coverage"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/embeddedartistry.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"docs/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"docs/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-19T16:18:26.000Z","updated_at":"2025-04-11T12:16:05.000Z","dependencies_parsed_at":"2025-03-17T13:01:05.822Z","dependency_job_id":"74e90c46-51c3-4e8b-a917-c65cf39e9a32","html_url":"https://github.com/embeddedartistry/libc","commit_stats":null,"previous_names":[],"tags_count":58,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/embeddedartistry%2Flibc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/embeddedartistry%2Flibc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/embeddedartistry%2Flibc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/embeddedartistry%2Flibc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/embeddedartistry","download_url":"https://codeload.github.com/embeddedartistry/libc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254328384,"owners_count":22052632,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bringup","c","embedded-systems","hacktoberfest","libc","meson","portability","test-coverage"],"created_at":"2024-08-03T04:00:56.801Z","updated_at":"2025-05-15T11:08:16.769Z","avatar_url":"https://github.com/embeddedartistry.png","language":"C","readme":"# Embedded Artistry libc\n\nEmbedded Artistry's `libc` is a stripped-down C standard library implementation targeted for microcontroller-based embedded systems.\n\nIn order to conserve precious memory resources, this library does not supply the complete C standard library implementation. Instead, a subset of functions which are useful on bare-metal embedded systems has been selected. If you have a bare metal or RTOS-based embedded system, this library is for you!\n\nUnlike many other C libraries that I've come across, this library implements unit tests and has addressed long-standing flaws in open-source implementations of the C standard library functions. We're continually adding tests and making additional improvements over the baseline implementations.\n\n`malloc` and `free` are not included in this library. If you need dynamic memory allocation support, you will need to couple this library with something like [Embedded Artistry's `libmemory`](https://github.com/embeddedartistry/libmemory), which contains implementations of `malloc` and `free`.\n\nIf you are interested in contributing to this project, please read the [`CONTRIBUTING` guide](docs/CONTRIBUTING.md).\n\n## Table of Contents\n\n1. [About the Project](#about-the-project)\n2. [Project Status](#project-status)\n3. [Getting Started](#getting-started)\n\t1. [Requirements](#requirements)\n\t\t1. [git-lfs](#git-lfs)\n\t\t1. [Meson Build System](#meson-build-system)\n\t2. [Getting the Source](#getting-the-source)\n\t3. [Building](#building)\n\t\t2. [Disabling Position Independent Code](#disabling-position-independent-code)\n\t\t2. [Enabling Link-time Optimization](#enabling-link-time-optimization)\n\t4. [Installation](#installation)\n\t5. [Usage](#usage)\n4. [Configuration Options](#configuration-options)\n5. [Stack Overflow Protection](#stack-overflow-protection)\n5. [Documentation](#documentation)\n6. [Need Help?](#need-help)\n7. [Contributing](#contributing)\n8. [Further Reading](#further-reading)\n9. [Authors](#authors)\n10. [License](#license)\n11. [Acknowledgments](#acknowledgements)\n\n## About the Project\n\nEmbedded Artistry's `libc` is intended to provide a portable set of useful C standard library functions that allows quick bring-up of new bare-metal and RTOS-based embedded systems.\n\nAdditionally, we want to provide a high-quality `libc` implementation by ensuring that each function has unit test coverage and addresses flaws exposed by the static analyzer. Many C library function implementations remain untested and contain errors. We are fighting back against poor implementations.\n\nIn order to conserve memory, this library does not supply the complete C standard library functionality. Instead, a subset of functions which are useful on bare-metal embedded systems has been selected. This selection has primarily been driven by my own experience in microcontroller-focused development. If you need additional features, please file an issue and make a feature request.\n\nThe functional implementations in this library have been selected for portability and quick bring-up of new systems. There may be more efficient implementations for these functions, but often they are architecture specific implementations. If you have suggestions for improving performance, we are always happy to hear them.\n\n`malloc` and `free` are not included in this library. Because memory allocation schemes vary greatly with embedded systems (some not even allowing dynamic memory), you will need to supply your own implementations based on your system's needs. You can couple this library with the [Embedded Artistry `libmemory`](https://github.com/embeddedartistry/libmemory), which contains implementations of `malloc` and `free`.\n\n## Project Status\n\nThis library provides a complete-enough implementation to compile and link clang's `libc++` and `libc++abi` (see [Embedded Artistry's libcpp project](https://github.com/embeddedartistry/libcpp)). In order to achieve this, some functions are only defined in the headers but do not have an implementation. Unsupported-but-defined functions can be removed using a build option (`hide-unimplemented-libc-apis`).\n\nThe following portions of the C library have been implemented:\n\n* `assert`\n* Basic C runtime support (`crt.c`, `exit`, `atexit`, etc.)\n* ctype\n* math (via [openlibm](https://github.com/JuliaMath/openlibm))\n* string functions\n* stdlib\n\t* `atoX`\n\t* `abs`, `labs`, `llabs`\n\t* `bsearch`\n\t* `calloc`\n\t* `div`, `ldiv`, `lldiv`\n\t* `heapsort`, `heapsort_r`\n\t* `imaxabs`, `imaxdiv`\n\t* `qsort`, `qsort_r`\n\t* `rand` family\n\t* `realloc`\n\t* `strtoX` functions (many via [`gdtoa`](https://github.com/embeddedartistry/gdtoa))\n* Basic stdio\n\t- `printf` family (most via [`embeddedartistry/printf`](https://github.com/embeddedartistry/printf), based on [`eyalroz/printf`](https://github.com/eyalroz/printf) and originally [`mpaland/printf`](https://github.com/mpaland/printf))\n\t- `putchar`\n\t- `puts`\n* `time` types and `asctime()`\n* `wchar` type definitions and `wctype` functions\n\nIn addition, this library provides implementations for `__stack_chk_guard` and `__stack_chk_fail`.\n\nThe following architectures are currently supported:\n\n* x86\n* x86_64\n* ARM\n* ARM64\n\nThe following unit tests need to be added:\n\n* `realloc`\n* `rand` family\n\nThese are not implemented by may be added in the future:\n\n* `wchar` functions\n* `errno` support (enabled as a compile-time switch)\n* `getopt` support\n* `time` support\n* `FILE` and additional stdio functions\n\nWe are currently not planning full support for:\n\n* `locale`\n\n## Getting Started\n\n### Requirements\n\nThis project uses [Embedded Artistry's standard Meson build system](https://embeddedartistry.com/fieldatlas/embedded-artistrys-standardized-meson-build-system/), and dependencies are described in detail [on our website](https://embeddedartistry.com/fieldatlas/embedded-artistrys-standardized-meson-build-system/).\n\nAt a minimum you will need:\n\n* [`git-lfs`](https://git-lfs.github.com), which is used to store binary files in this repository\n* [Meson](#meson-build-system) is the build system\n* Some kind of compiler for your target system.\n\t- This repository has been tested with:\n\t\t- gcc-7, gcc-8, gcc-9\n\t\t- arm-none-eabi-gcc\n\t\t- Apple clang\n\t\t- Mainline clang\n\n#### git-lfs\n\nThis project stores some files using [`git-lfs`](https://git-lfs.github.com).\n\nTo install `git-lfs` on Linux:\n\n```\nsudo apt install git-lfs\n```\n\nTo install `git-lfs` on MacOS:\n\n```\nbrew install git-lfs\n```\n\nAdditional installation instructions can be found on the [`git-lfs` website](https://git-lfs.github.com).\n\n#### Meson Build System\n\nThe [Meson](https://mesonbuild.com) build system depends on `python3` and `ninja-build`.\n\nTo install on Linux:\n\n```\nsudo apt-get install python3 python3-pip ninja-build\n```\n\nTo install on OSX:\n\n```\nbrew install python3 ninja\n```\n\nMeson can be installed through `pip3`:\n\n```\npip3 install meson\n```\n\nIf you want to install Meson globally on Linux, use:\n\n```\nsudo -H pip3 install meson\n```\n\n### Getting the Source\n\nThis project uses [`git-lfs`](https://git-lfs.github.com), so please install it before cloning. If you cloned prior to installing `git-lfs`, simply run `git lfs pull` after installation.\n\nThis project is [hosted on GitHub](https://github.com/embeddedartistry/libc). You can clone the project directly using this command:\n\n```\ngit clone --recursive git@github.com:embeddedartistry/libc.git\n```\n\nIf you don't clone recursively, be sure to run the following command in the repository or your build will fail:\n\n```\ngit submodule update --init\n```\n\n### Building\n\nIf Make is installed, the library can be built by issuing the following command:\n\n```\nmake\n```\n\nThis will build all targets for your current architecture.\n\nYou can clean builds using:\n\n```\nmake clean\n```\n\nYou can eliminate the generated `buildresults` folder using:\n\n```\nmake distclean\n```\n\nYou can also use  `meson` directly for compiling.\n\nCreate a build output folder:\n\n```\nmeson buildresults\n```\n\nAnd build all targets by running\n\n```\nninja -C buildresults\n```\n\nCross-compilation is handled using `meson` cross files. Example files are included in the [`build/cross`](build/cross/) folder. You can write your own cross files for your specific processor by defining the toolchain, compilation flags, and linker flags. These settings will be used to compile `libc`. (or open an issue and we can help you).\n\nCross-compilation must be configured using the meson command when creating the build output folder. For example:\n\n```\nmeson buildresults --cross-file build/cross/gcc_arm_cortex-m4.txt\n```\n\nFollowing that, you can run `make` (at the project root) or `ninja` to build the project.\n\nTests will not be cross-compiled. They will only be built for the native platform.\n\n**Full instructions for building the project, using alternate toolchains, and running supporting tooling are documented in [Embedded Artistry's Standardized Meson Build System](https://embeddedartistry.com/fieldatlas/embedded-artistrys-standardized-meson-build-system/) on our website.**\n\n### Disabling Position Independent Code\n\nPosition Independent Code (PIC) is enabled by default, but can be disabled during the Meson configuration stage by setting the built-in option `b_staticpic` to `false`:\n\n```\nmeson buildresults -Db_staticpic=false\n```\n\n### Enabling Link-time Optimization\n\nLink-time Optimization (LTO) can be enabled during the meson configuration stage by setting the built-in option `b_lto` to `true`:\n\n```\nmeson buildresults -Db_lto=true\n```\n\nThis can be combined with other build options.\n\n### Installation\n\nIf you don't use `meson` for your project, the best method to use this project is to build it separately and copy the headers and library contents into your source tree.\n\n* Copy the `include/` directory contents into your source tree.\n* Library artifacts are stored in the `buildresults/src` folder\n* Copy the desired library to your project and add the library to your link step.\n\nExample linker flags:\n\n```\n-Lpath/to/libc.a -lc\n```\n\nIf you're using `meson`, you can use `libc` as a subproject. Place it into your subproject directory of choice and add a `subproject` statement:\n\n```\nlibc = subproject('libc')\n```\n\nYou will need to promote the desired subproject dependency variable to your project:\n\n```\nlibc_dep = libc.get_variable('libc_dep')\n```\n\nYou can use the dependency for your target library configuration in your `executable` declarations(s) or other dependencies. For example:\n\n```\nfwdemo_sim_platform_dep = declare_dependency(\n\tinclude_directories: fwdemo_sim_platform_inc,\n\tdependencies: [\n\t\tfwdemo_simulator_hw_platform_dep,\n\t\tposix_os_dep,\n\t\tlibmemory_native_dep,\n\t\tlibc_dep, # \u003c----- libc added here\n\t\tlibcxxabi_native_dep,\n\t\tlibcxx_full_native_dep,\n\t\tlogging_subsystem_dep\n\t],\n\tsources: files('platform.cpp'),\n)\n```\n\n### Testing\n\nThe tests for this library are written with CMocka, which is included as a subproject and does not need to be installed on your system. You can run the tests by issuing the following command:\n\n```\nmake test\n```\n\nBy default, test results are generated for use by the CI server and are formatted in JUnit XML. The test results XML files can be found in `buildresults/test/`.\n\n## Configuration Options\n\nThe following meson project options can be set for this library when creating the build results directory with `meson`, or by using `meson configure`:\n\n* `enable-pedantic`: Turn on `pedantic` warnings\n* `enable-pedantic-error`: Turn on `pedantic` warnings and errors\n* `hide-unimplemented-libc-apis`: Hides the header definitions for functions which are not actually implemented\n* `enable-gnu-extensions` will enable GNU libc extensions that are implemented in this library\n* `disable-builtins` will tell the compiler not to generate built-in functions, forcing it to use the library functions\n* `disable-stack-protection` will tell the compiler not to insert stack protection calls\n* `stack-canary-value` enables you to customize the canary value for your application. Supply a hexadecimal string (e.g., `'0xdeadbeef'`) with the same length as your processor's word size.\n* `disable-stk-guard-runtime-config` disables the code that is used to configure `__stk_chk_guard` during program initialization. When this option is `true`, the program will revert to using a hard-coded definition for the guard value.\n\nOptions can be specified using `-D` and the option name:\n\n```\nmeson buildresults -Ddisable-builtins=false\n```\n\nThe same style works with `meson configure`:\n\n```\ncd buildresults\nmeson configure -Ddisable-builtins=false\n```\n\n## Stack Overflow Protection\n\nThis library provides an implementation of `__stack_chk_guard` and `__stack_chk_fail`, which enables it to be used with GCC and Clang's stack protection code.\n\nThe default value for `__stack_chk_guard` can be overridden with the `stack-canary-value` build option.\n\n## Documentation\n\n[Documentation for the latest release can always be found here]https://embeddedartistry.github.io/libc/index.html.\n\nDocumentation can be built locally by running the following command:\n\n```\nmake docs\n```\n\nDocumentation can be found in `buildresults/docs`, and the root page is `index.html`.\n\n## Need help?\n\nIf you need further assistance or have any questions, please [file a GitHub Issue](https://github.com/embeddedartistry/libc/issues) or send us an email using the [Embedded Artistry Contact Form](http://embeddedartistry.com/contact).\n\nYou can also [reach out on Twitter: mbeddedartistry](https://twitter.com/mbeddedartistry/).\n\n## Contributing\n\nIf you are interested in contributing to this project, please read our [contributing guidelines](docs/CONTRIBUTING.md).\n\n## Authors\n\n* **[Phillip Johnston](https://github.com/phillipjohnston)** - original library author - [Embedded Artistry](https://github.com/embeddedartistry)\n\n## License\n\nCopyright © 2022 Embedded Artistry LLC\n\nThis project is licensed under the MIT License - see [LICENSE](LICENSE) file for details.\n\nFor other open-source licenses, please see the [Software Inventory](docs/software_inventory.xlsx).\n\n## Acknowledgments\n\nI'd like to thank the following individuals for their direct contributions on this project:\n\n* [\\@seekaddo](https://github.com/seekaddo) (Documentation)\n* [\\@mpaland](https://github.com/mpaland) (Original author of the `printf` library)\n* [\\@eyalroz](https://github.com/eyalroz) (Picked up mpaland's `printf` library and continued development)\n\nMany of the open-source function implementations used in this library have been pulled from two primary sources:\n\n* [Apple Open Source libc](https://opensource.apple.com/source/Libc/)\n\t* abs, atof, bsearch, div family, heapsort/qsort family, abs family, imax family, strtol/ll/ull\n\t* fls, flsl, flsll\n\t* strstr, strtok. strnstr, strnlen, strndup, strncpy, strncat, strlen, strdup, strcpy, strcat\n\t* memmem, memcpy\n* [musl libc](https://www.musl-libc.org)\n\t* All ctype member functions (locale support removed)\n\t* strrchr, strchrnul, strchr\n\t* memset, memrchr\n\nI have also used and improved the open-source `gdtoa` library.\n\nThe initial groundwork of testing was implemented by referencing the [libc-test](http://nsz.repo.hu/git/?p=libc-test) project.\n\n**[Back to top](#table-of-contents)**\n","funding_links":[],"categories":["C Libraries","Common","C"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fembeddedartistry%2Flibc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fembeddedartistry%2Flibc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fembeddedartistry%2Flibc/lists"}