Search code examples
cglibc

Where does `__assert` come from?


When reading glibc sources I stumbled upon this comment in 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__));

What standard specifies a __assert function?

I couldn't find anything in POSIX or C or in git commit history or find on the net or on this site.


Solution

  • I found this digging through the mailing list: glibc should be Sys V ABI compliant, hence implement __assert().

    ABI standards, though not as important as source standards, are still standards.

    The System V ABI (available from ftp://ftp.linux.sgi.com/pub/linux/mips/doc/ABI and elsewhere) specifies a function __assert

    I think both gcc (in libgcc) and glibc (in libc.a) should implement __assert.

    If its existence in a standard is not a good enough reason, here is an actual bug: this is required to allow glibc to replace libc on Solaris. Certainly glibcers will consider this a noble goal.

    Quote: "Porting the library is not hard." Consider this a start of the Solaris port.

    Of course, glibc also needs to implement other symbols in Solaris libc for binary compatibility with Solaris. If they are not already in glibc, most can probably be copied from libgcc.

    In System V ABI Edition 4.1 pp. 6-9:

    Figure 6-6: libc Contents, Internal Names without Synonyms

    _cleanup _xftw __flsbuf __trwctype* _tolower __assert __iswctype* ___errno* _toupper __filbuf __thr_errno*