OpenSolaris

Printable Version Enter a New Search
Bug ID 6362982
Synopsis namespace pollution/protection in libc
State 10-Fix Delivered (Fix available in build)
Category:Subcategory library:libc
Keywords
Responsible Engineer Roger Faulkner
Reported Against s10
Duplicate Of
Introduced In
Commit to Fix snv_32
Fixed In snv_32
Release Fixed solaris_nevada(snv_32)
Related Bugs 6367203 , 6369040 , 6370388 , 6377978 , 6460378 , 6495726
Submit Date 14-December-2005
Last Update Date 16-February-2007
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.
Work Around
N/A
Comments
N/A