简体   繁体   English

Android libc 文档在哪里?

[英]Where is the Android libc documentation?

For glibc you can find an online documentation here .对于 glibc,您可以在此处找到在线文档。

I am looking for an equivalent documentation for Android's libc implementation (headers located under sysroot/usr/include).我正在寻找 Android 的 libc 实现的等效文档(位于 sysroot/usr/include 下的头文件)。

Is there a documentation for these?有这些的文档吗?

(For example the call statfs() under sysroot/usr/include/sys/vfs.h). (例如 sysroot/usr/include/sys/vfs.h 下的调用 statfs())。

Where is the Bionic documentation?仿生文档在哪里?

Google's documentation is sparse, to say the least.至少可以说,Google 的文档很少。 You can find it here and here .你可以在 这里这里找到它。 There's a lot of good information if you're generally familiar with C run-time libraries, but there is no full set of function-by-function documentation.如果您通常熟悉 C 运行时库,这里有很多很好的信息,但是没有完整的函数文档集。 Google appear to assume that you won't be learning C/C++ programming for the first time on Android. Google 似乎假设您不会第一次在 Android 上学习 C/C++ 编程。

The OpenBSD manual pages are available here . OpenBSD 手册页可在此处获得。 Use the form in the top part of the page to select a different function.使用页面顶部的表格选择不同的功能。

The definitive source on functions available is the header files.可用函数的权威来源是头文件。 Since you can install the NDK anywhere in your filesystem, I'll describe the header locations relative to the NDK directory:由于您可以将 NDK 安装在文件系统中的任何位置,因此我将描述相对于 NDK 目录的标头位置:

On Windows, you'll find most of them in:在 Windows 上,您会在以下位置找到其中的大部分:

<NDK-directory>\sysroot\usr\include

However, some headers, which are closely associated with the compiler, are in:但是,一些与编译器密切相关的头文件位于:

<NDK-directory>\toolchains\llvm\prebuilt\windows-x86_64\lib64\clang\<clang-version>\include

On Linux, those directories are:在 Linux 上,这些目录是:

<NDK-directory>/sysroot/usr/include
<NDK-directory>/lib64/clang/<clang-version>/include

Why does Android use Bionic rather than glibc?为什么 Android 使用 Bionic 而不是 glibc?

When the Android project was taking shape, Google had some specific requirements for a C run-time library for it:在 Android 项目成型时,Google 对其 C 运行时库有一些特定要求

  • Small.小的。 Early Android devices had much less RAM than current equipment.早期的 Android 设备的 RAM 比当前设备少得多。 The HTC Dream, the first Android device on sale, had 192MB, whereas 1GB is now the minimum. HTC Dream 是第一款在售的 Android 设备,有 192MB,而现在是 1GB 的最小值。 As well as the code being small, the library could not require large amounts of working memory.除了代码很小之外,该库也不需要大量的工作内存。

  • Fast.快速地。 The Dream ran at 528MHz, as opposed to 1GHz or more for current low-end devices. Dream 的运行频率为 528MHz,而当前低端设备的运行频率为 1GHz 或更高。 The size and speed requirements meant that simplicity was very desirable.尺寸和速度要求意味着简单是非常可取的。

  • BSD-licensed. BSD 许可。 Google very much wanted to avoid application developers having to use GPL-licensed libraries. Google 非常希望避免应用程序开发人员不得不使用 GPL 许可的库。 In the first decade of this century, open source was far less accepted in business, and many companies who were potential app suppliers would have nothing to do with GPL or other copyleft licenses.在本世纪的前十年,开源在商业中的接受程度要低得多,许多潜在的应用程序供应商公司与 GPL 或其他 copyleft 许可证无关。 In early Android native code work, static linking was quite common, and if you statically link to GPL'ed code, you need to open-source your own code.在早期的 Android 原生代码工作中,静态链接非常普遍,如果您静态链接到 GPL 代码,则需要开源您自己的代码。 The BSD license is far more permissive: you can do pretty much what you like with BSD-licensed code, provided you acknowledge it is present. BSD 许可证更加宽松:只要您承认存在 BSD 许可代码,您就可以使用 BSD 许可代码做任何您喜欢的事情。

Glibc evolved on reasonably fast PCs, which had far more RAM and processor speed than early Android devices, so it did not have the same pressure to be small and simple. Glibc 是在相当快的 PC 上发展起来的,这些 PC 的 RAM 和处理器速度比早期的 Android 设备要快得多,因此它没有那么小而简单的压力。 The PCs could also use "swapping" of data and programs between memory and disk. PC 还可以使用内存和磁盘之间的数据和程序“交换”。 Android has never supported that: the physical RAM is all of the memory that can be in use by all the programs running at the same time. Android 从来不支持:物理 RAM 是所有同时运行的程序可以使用的所有内存。

Glibc is also a very complete C run-time library, with most of the features of every other C run-time combined. Glibc 也是一个非常完整的 C 运行时库,结合了其他所有 C 运行时的大部分特性。 It's also compatible with a very wide range of hardware and operating systems.它还与非常广泛的硬件和操作系统兼容。 Both of those things tend to make it bigger.这两件事往往会使它变得更大。 It uses the LGPL, rather than full GPL, but understanding the distinction requires you to understand the difference between static and dynamic linking.它使用 LGPL,而不是完整的 GPL,但要了解区别,您需要了解静态链接和动态链接之间的区别。 Google didn't want to try educating executives about that.谷歌不想尝试对高管进行这方面的教育。

Bionic has only ever supported ARM32, ARM64, x86, x86-64, MIPS and MIPS64, all of them little-endian. Bionic 只支持 ARM32、ARM64、x86、x86-64、MIPS 和 MIPS64,它们都是 little-endian。 The only operating system kernel it has ever supported is Linux.它曾经支持的唯一操作系统内核是 Linux。 Multi-threading is always in operation, and there's always an MMU.多线程总是在运行,并且总是有一个 MMU。 These things definitely simplify the code of Bionic.这些东西绝对简化了 Bionic 的代码。

An overview of Bionic from Android 4.0 can be found here .可以在此处找到 Android 4.0 的 Bionic 概述。

Differences from standards与标准的差异

Bionic does not support all of POSIX, although it is fairly close. Bionic 不支持所有的 POSIX,尽管它相当接近。 It contains many BSD extensions, and quite a few glibc extensions that don't increase memory use unduly.它包含许多 BSD 扩展,以及不少不会过度增加内存使用的 glibc 扩展。 Some things are deliberately excluded at the expense of standards conformance.有些东西被故意排除在外,以牺牲标准的一致性为代价。 For example, printf does not support the %n formatter on security grounds (a very sound decision), and there are no Unix password database functions because Android doesn't have that kind of database.例如,出于安全原因, printf不支持%n格式化程序(一个非常合理的决定),并且没有 Unix 密码数据库功能,因为 Android没有那种数据库。

Evolution of Bionic仿生的进化

The library has gained more functionality over the life of Android.该库在 Android 的整个生命周期中获得了更多功能。 The C headers in modern versions of the NDK contain conditional compilation that let you choose a version of Android as the oldest you're supporting.现代版本的 NDK 中的 C 标头包含条件编译,可让您选择 Android 版本作为您支持的最旧版本。 Only functions present on that version will be available in your compiles.只有该版本上存在的函数才能在您的编译中使用。 From personal experience, porting C/C++ code to Android 5.0 “Lollipop” is considerably easier than for earlier versions.根据个人经验,将 C/C++ 代码移植到 Android 5.0 “Lollipop” 比早期版本要容易得多。 A lot of classic Unix functionality appeared then.那时出现了很多经典的 Unix 功能。

Where did the code in Bionic come from? Bionic 中的代码是从哪里来的?

Quite a lot of it comes from the various BSD Unixes.其中很大一部分来自各种 BSD Unix。 Changes were needed to run on a Linux, rather than BSD, kernel.需要进行更改才能在 Linux 而不是 BSD 内核上运行。 OpenBSD seems to be the largest contributor, but the math library is mostly from FreeBSD, with optimised assembler routines from SoC manufacturers. OpenBSD 似乎是最大的贡献者,但数学库主要来自 FreeBSD,并带有来自 SoC 制造商的优化汇编程序。 The pthreads library, and the dynamic linker were written from scratch. pthreads 库和动态链接器是从头开始编写的。 There is no separate libpthread, as it and many other extensions to a traditional Unix libc have been incorporated into Bionic's libc.没有单独的 libpthread,因为它和对传统 Unix libc 的许多其他扩展已被合并到 Bionic 的 libc 中。

C++ C++

Bionic is a C run-time library, but C++ code often calls it. Bionic 是一个C运行时库,但 C++ 代码经常调用它。 The C++ run-time library, unlike Bionic, is not part of the Android operating system.与 Bionic 不同,C++ 运行时库不是 Android 操作系统的一部分。 Historically, several different C++ runtimes were available, but nowadays libc++ from the LLVM project is the standard.从历史上看,有几种不同的 C++ 运行时可用,但现在来自 LLVM 项目的 libc++ 是标准。 You have to include libc++_shared.so in your application APK, since it is not provided by the operating system.您必须在应用程序 APK 中包含libc++_shared.so ,因为它不是由操作系统提供的。 This wastes some memory and storage, but not very much by the standards of modern apps.这会浪费一些内存和存储空间,但按照现代应用程序的标准来说并不是很多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM