{"id":22880813,"url":"https://github.com/xuantie-rv/riscv-bionic","last_synced_at":"2025-11-09T01:02:12.965Z","repository":{"id":114567435,"uuid":"328926062","full_name":"XUANTIE-RV/riscv-bionic","owner":"XUANTIE-RV","description":null,"archived":false,"fork":false,"pushed_at":"2021-01-18T08:19:47.000Z","size":31909,"stargazers_count":4,"open_issues_count":0,"forks_count":5,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-05-07T02:46:52.561Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/XUANTIE-RV.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"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":"2021-01-12T08:53:11.000Z","updated_at":"2024-08-22T19:22:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"0cfe18e2-804a-41cf-a6ec-fb1e17d6bc48","html_url":"https://github.com/XUANTIE-RV/riscv-bionic","commit_stats":null,"previous_names":["xuantie-rv/riscv-bionic"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/XUANTIE-RV/riscv-bionic","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XUANTIE-RV%2Friscv-bionic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XUANTIE-RV%2Friscv-bionic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XUANTIE-RV%2Friscv-bionic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XUANTIE-RV%2Friscv-bionic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/XUANTIE-RV","download_url":"https://codeload.github.com/XUANTIE-RV/riscv-bionic/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XUANTIE-RV%2Friscv-bionic/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263385622,"owners_count":23458738,"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":[],"created_at":"2024-12-13T17:27:24.806Z","updated_at":"2025-11-09T01:02:12.831Z","avatar_url":"https://github.com/XUANTIE-RV.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bionic\n\n[bionic](https://en.wikipedia.org/wiki/Bionic_(software)) is Android's\nC library, math library, and dynamic linker.\n\n# Using bionic as an app developer\n\nSee the [user documentation](docs/).\n\n# Working on bionic itself\n\nThis documentation is about making changes to bionic itself.\n\n## What are the big pieces of bionic?\n\n#### libc/ --- libc.so, libc.a\n\nThe C library. Stuff like `fopen(3)` and `kill(2)`.\n\n#### libm/ --- libm.so, libm.a\n\nThe math library. Traditionally Unix systems kept stuff like `sin(3)` and\n`cos(3)` in a separate library to save space in the days before shared\nlibraries.\n\n#### libdl/ --- libdl.so\n\nThe dynamic linker interface library. This is actually just a bunch of stubs\nthat the dynamic linker replaces with pointers to its own implementation at\nruntime. This is where stuff like `dlopen(3)` lives.\n\n#### libstdc++/ --- libstdc++.so\n\nThe C++ ABI support functions. The C++ compiler doesn't know how to implement\nthread-safe static initialization and the like, so it just calls functions that\nare supplied by the system. Stuff like `__cxa_guard_acquire` and\n`__cxa_pure_virtual` live here.\n\n#### linker/ --- /system/bin/linker and /system/bin/linker64\n\nThe dynamic linker. When you run a dynamically-linked executable, its ELF file\nhas a `DT_INTERP` entry that says \"use the following program to start me\".  On\nAndroid, that's either `linker` or `linker64` (depending on whether it's a\n32-bit or 64-bit executable). It's responsible for loading the ELF executable\ninto memory and resolving references to symbols (so that when your code tries to\njump to `fopen(3)`, say, it lands in the right place).\n\n#### tests/ --- unit tests\n\nThe `tests/` directory contains unit tests. Roughly arranged as one file per\npublicly-exported header file.\n\n#### benchmarks/ --- benchmarks\n\nThe `benchmarks/` directory contains benchmarks, with its own [documentation](benchmarks/README.md).\n\n\n## What's in libc/?\n\n```\nlibc/\n  arch-arm/\n  arch-arm64/\n  arch-common/\n  arch-mips/\n  arch-mips64/\n  arch-x86/\n  arch-x86_64/\n    # Each architecture has its own subdirectory for stuff that isn't shared\n    # because it's architecture-specific. There will be a .mk file in here that\n    # drags in all the architecture-specific files.\n    bionic/\n      # Every architecture needs a handful of machine-specific assembler files.\n      # They live here.\n    string/\n      # Most architectures have a handful of optional assembler files\n      # implementing optimized versions of various routines. The \u003cstring.h\u003e\n      # functions are particular favorites.\n    syscalls/\n      # The syscalls directories contain script-generated assembler files.\n      # See 'Adding system calls' later.\n\n  include/\n    # The public header files on everyone's include path. These are a mixture of\n    # files written by us and files taken from BSD.\n\n  kernel/\n    # The kernel uapi header files. These are scrubbed copies of the originals\n    # in external/kernel-headers/. These files must not be edited directly. The\n    # generate_uapi_headers.sh script should be used to go from a kernel tree to\n    # external/kernel-headers/ --- this takes care of the architecture-specific\n    # details. The update_all.py script should be used to regenerate bionic's\n    # scrubbed headers from external/kernel-headers/.\n\n  private/\n    # These are private header files meant for use within bionic itself.\n\n  dns/\n    # Contains the DNS resolver (originates from NetBSD code).\n\n  upstream-freebsd/\n  upstream-netbsd/\n  upstream-openbsd/\n    # These directories contain unmolested upstream source. Any time we can\n    # just use a BSD implementation of something unmodified, we should.\n    # The structure under these directories mimics the upstream tree,\n    # but there's also...\n    android/\n      include/\n        # This is where we keep the hacks necessary to build BSD source\n        # in our world. The *-compat.h files are automatically included\n        # using -include, but we also provide equivalents for missing\n        # header/source files needed by the BSD implementation.\n\n  bionic/\n    # This is the biggest mess. The C++ files are files we own, typically\n    # because the Linux kernel interface is sufficiently different that we\n    # can't use any of the BSD implementations. The C files are usually\n    # legacy mess that needs to be sorted out, either by replacing it with\n    # current upstream source in one of the upstream directories or by\n    # switching the file to C++ and cleaning it up.\n\n  malloc_debug/\n    # The code that implements the functionality to enable debugging of\n    # native allocation problems.\n\n  stdio/\n    # These are legacy files of dubious provenance. We're working to clean\n    # this mess up, and this directory should disappear.\n\n  tools/\n    # Various tools used to maintain bionic.\n\n  tzcode/\n    # A modified superset of the IANA tzcode. Most of the modifications relate\n    # to Android's use of a single file (with corresponding index) to contain\n    # time zone data.\n  zoneinfo/\n    # Android-format time zone data.\n    # See 'Updating tzdata' later.\n```\n\n\n## Adding libc wrappers for system calls\n\nThe first question you should ask is \"should I add a libc wrapper for\nthis system call?\". The answer is usually \"no\".\n\nThe answer is \"yes\" if the system call is part of the POSIX standard.\n\nThe answer is probably \"yes\" if the system call has a wrapper in at\nleast one other C library.\n\nThe answer may be \"yes\" if the system call has three/four distinct\nusers in different projects, and there isn't a more specific library\nthat would make more sense as the place to add the wrapper.\n\nIn all other cases, you should use\n[syscall(3)](http://man7.org/linux/man-pages/man2/syscall.2.html) instead.\n\nAdding a system call usually involves:\n\n  1. Add entries to SYSCALLS.TXT.\n     See SYSCALLS.TXT itself for documentation on the format.\n  2. Run the gensyscalls.py script.\n  3. Add constants (and perhaps types) to the appropriate header file.\n     Note that you should check to see whether the constants are already in\n     kernel uapi header files, in which case you just need to make sure that\n     the appropriate POSIX header file in libc/include/ includes the\n     relevant file or files.\n  4. Add function declarations to the appropriate header file. Don't forget\n     to include the appropriate `__INTRODUCED_IN()`.\n  5. Add the function name to the correct section in libc/libc.map.txt and\n     run `./libc/tools/genversion-scripts.py`.\n  6. Add at least basic tests. Even a test that deliberately supplies\n     an invalid argument helps check that we're generating the right symbol\n     and have the right declaration in the header file, and that you correctly\n     updated the maps in step 5. (You can use strace(1) to confirm that the\n     correct system call is being made.)\n\n\n## Updating kernel header files\n\nAs mentioned above, this is currently a two-step process:\n\n  1. Use generate_uapi_headers.sh to go from a Linux source tree to appropriate\n     contents for external/kernel-headers/.\n  2. Run update_all.py to scrub those headers and import them into bionic.\n\nNote that if you're actually just trying to expose device-specific headers to\nbuild your device drivers, you shouldn't modify bionic. Instead use\n`TARGET_DEVICE_KERNEL_HEADERS` and friends described in [config.mk](https://android.googlesource.com/platform/build/+/master/core/config.mk#186).\n\n\n## Updating tzdata\n\nThis is fully automated (and these days handled by the libcore team, because\nthey own icu, and that needs to be updated in sync with bionic):\n\n  1. Run update-tzdata.py in external/icu/tools/.\n\n\n## Verifying changes\n\nIf you make a change that is likely to have a wide effect on the tree (such as a\nlibc header change), you should run `make checkbuild`. A regular `make` will\n_not_ build the entire tree; just the minimum number of projects that are\nrequired for the device. Tests, additional developer tools, and various other\nmodules will not be built. Note that `make checkbuild` will not be complete\neither, as `make tests` covers a few additional modules, but generally speaking\n`make checkbuild` is enough.\n\n\n## Running the tests\n\nThe tests are all built from the tests/ directory.\n\n### Device tests\n\n    $ mma # In $ANDROID_ROOT/bionic.\n    $ adb root \u0026\u0026 adb remount \u0026\u0026 adb sync\n    $ adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests\n    $ adb shell \\\n        /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static\n    # Only for 64-bit targets\n    $ adb shell /data/nativetest64/bionic-unit-tests/bionic-unit-tests\n    $ adb shell \\\n        /data/nativetest64/bionic-unit-tests-static/bionic-unit-tests-static\n\nNote that we use our own custom gtest runner that offers a superset of the\noptions documented at\n\u003chttps://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md#running-test-programs-advanced-options\u003e,\nin particular for test isolation and parallelism (both on by default).\n\n### Device tests via CTS\n\nMost of the unit tests are executed by CTS. By default, CTS runs as\na non-root user, so the unit tests must also pass when not run as root.\nSome tests cannot do any useful work unless run as root. In this case,\nthe test should check `getuid() == 0` and do nothing otherwise (typically\nwe log in this case to prevent accidents!). Obviously, if the test can be\nrewritten to not require root, that's an even better solution.\n\nCurrently, the list of bionic CTS tests is generated at build time by\nrunning a host version of the test executable and dumping the list of\nall tests. In order for this to continue to work, all architectures must\nhave the same number of tests, and the host version of the executable\nmust also have the same number of tests.\n\nRunning the gtests directly is orders of magnitude faster than using CTS,\nbut in cases where you really have to run CTS:\n\n    $ make cts # In $ANDROID_ROOT.\n    $ adb unroot # Because real CTS doesn't run as root.\n    # This will sync any *test* changes, but not *code* changes:\n    $ cts-tradefed \\\n        run singleCommand cts --skip-preconditions -m CtsBionicTestCases\n\n### Host tests\n\nThe host tests require that you have `lunch`ed either an x86 or x86_64 target.\nNote that due to ABI limitations (specifically, the size of pthread_mutex_t),\n32-bit bionic requires PIDs less than 65536. To enforce this, set /proc/sys/kernel/pid_max\nto 65536.\n\n    $ ./tests/run-on-host.sh 32\n    $ ./tests/run-on-host.sh 64   # For x86_64-bit *targets* only.\n\nYou can supply gtest flags as extra arguments to this script.\n\n### Against glibc\n\nAs a way to check that our tests do in fact test the correct behavior (and not\njust the behavior we think is correct), it is possible to run the tests against\nthe host's glibc.\n\n    $ ./tests/run-on-host.sh glibc\n\n\n## Gathering test coverage\n\nFor either host or target coverage, you must first:\n\n * `$ export NATIVE_COVERAGE=true`\n     * Note that the build system is ignorant to this flag being toggled, i.e. if\n       you change this flag, you will have to manually rebuild bionic.\n * Set `bionic_coverage=true` in `libc/Android.mk` and `libm/Android.mk`.\n\n### Coverage from device tests\n\n    $ mma\n    $ adb sync\n    $ adb shell \\\n        GCOV_PREFIX=/data/local/tmp/gcov \\\n        GCOV_PREFIX_STRIP=`echo $ANDROID_BUILD_TOP | grep -o / | wc -l` \\\n        /data/nativetest/bionic-unit-tests/bionic-unit-tests\n    $ acov\n\n`acov` will pull all coverage information from the device, push it to the right\ndirectories, run `lcov`, and open the coverage report in your browser.\n\n### Coverage from host tests\n\nFirst, build and run the host tests as usual (see above).\n\n    $ croot\n    $ lcov -c -d $ANDROID_PRODUCT_OUT -o coverage.info\n    $ genhtml -o covreport coverage.info # or lcov --list coverage.info\n\nThe coverage report is now available at `covreport/index.html`.\n\n\n## Attaching GDB to the tests\n\nBionic's test runner will run each test in its own process by default to prevent\ntests failures from impacting other tests. This also has the added benefit of\nrunning them in parallel, so they are much faster.\n\nHowever, this also makes it difficult to run the tests under GDB. To prevent\neach test from being forked, run the tests with the flag `--no-isolate`.\n\n\n## 32-bit ABI bugs\n\nSee [32-bit ABI bugs](docs/32-bit-abi.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxuantie-rv%2Friscv-bionic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxuantie-rv%2Friscv-bionic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxuantie-rv%2Friscv-bionic/lists"}