|
Description
|
To avoid namespace pollution, that is, to allow applications
to have their own definitions of common functions like memcpy()
that are both defined by libc and are called from other parts
of libc, the common scheme of providing an alias for such functions
is employed, namely to have two symbols for the same function,
one with a leading underscore to emphasize its reserved nature:
memcpy()
_memcpy()
This is accomplished via "#pragma weak memcpy _memcpy" in the
libc source code for the function.
The rule is, all calls to memcpy() from within libc must call
the leading underscore version. The non-leading underscore
version is provided for applications to call (or ignore).
This way, libc will not malfunction just because the application
to which it is linked defines its own version of memcpy() with
different arguments and semantics from libc's version of memcpy().
The rule is implemented, for the most part, by having libc source
files include a special header file before all other headers:
#include "synonyms.h"
which contains #define statements such as:
#define memcpy _memcpy
and etcetera for all such function name pairs.
The code calls memcpy(), but the generated code calls _memcpy().
This makes the files lintable and straightforwardly readable.
The problem is, the rule is not enforced across the entirity
of libc. The gaps need to be closed and a mechanism for future
enforcement must be provided so that someone doesn't come along
after the Big Cleanup and add or modify libc code such as to
reintroduce the problem.
A Makefile-enforced final pass over all of the object files
linked into libc.so.1 to detect violations is required.
|