在阅读 glibc 源代码时,我偶然发现了assert.h中的这条评论:
/* The following is not at all used here but needed for standard
compliance. */
extern void __assert (const char *__assertion, const char *__file, int __line)
__THROW __attribute__ ((__noreturn__));
Run Code Online (Sandbox Code Playgroud)
什么标准规定了__assert函数?
我在 POSIX 或 C 或 git 提交历史记录中找不到任何内容,也无法在网络或本网站上找到任何内容。
我在邮件列表中发现了这一点:glibc 应该符合 Sys V ABI 兼容,因此实现 __assert()。
ABI 标准虽然不如源标准那么重要,但仍然是标准。
System V ABI(可从 ftp://ftp.linux.sgi.com/pub/linux/mips/doc/ABI等处获得)指定了一个函数 __assert
我认为 gcc(在 libgcc 中)和 glibc(在 libc.a 中)都应该实现 __assert。
如果它在标准中的存在还不是一个足够好的理由,那么这里有一个实际的错误:这是允许 glibc 在 Solaris 上替换 libc 所必需的。当然,glibcers 会认为这是一个崇高的目标。
引用:“移植图书馆并不难。” 将此视为 Solaris 移植的开始。
当然,glibc还需要实现Solaris libc中的其他符号,以实现与Solaris的二进制兼容性。如果它们尚未包含在 glibc 中,则大多数可能可以从 libgcc 复制。
在System V ABI 版本 4.1第 6-9 页中:
图 6-6:
libc内容,不带同义词的内部名称
_cleanup_xftw__flsbuf__trwctype*_tolower__assert__iswctype*___errno*_toupper__filbuf__thr_errno*