NetBSD/lib/libc
christos 4dddbc1f8d put the state back after it is used. 2015-10-26 19:41:19 +00:00
..
arch In rumprun mode on ARM, don't build syscall or signal code into libc. 2015-08-20 16:13:40 +00:00
atomic Introduce membar_datadep_consumer. 2015-01-08 22:27:17 +00:00
cdb Fix typo. Reported by rudolf on netbsd-docs. 2015-02-08 19:09:56 +00:00
citrus Don't unconditionally pass MLIBDIR via CPPFLAGS. Drop now dead branch. 2015-08-28 11:45:02 +00:00
compat Return type of compat wait functions should be pid_t not int. 2015-03-26 11:17:08 +00:00
compat-43 End sentence with a dot. 2013-05-06 13:29:12 +00:00
compiler_rt Changes for OR1K 2014-09-03 19:29:14 +00:00
db Fix hash iteration that deletes the current element under the cursor by 2015-06-22 21:16:02 +00:00
dlfcn fix old style definitions; XXX: gcc should have picked them up but it did not. 2012-06-24 15:26:02 +00:00
gdtoa Fix non _REENTRANT build. 2015-01-20 18:31:24 +00:00
gen Use strerror(3) instead of strerror_r(3) and an arbitary buffer size which could be too small. 2015-10-26 11:44:30 +00:00
gmon make more descriptors that we open as close-on-exec 2014-09-18 13:58:20 +00:00
hash Fix rcsid comment. 2014-12-11 21:54:13 +00:00
iconv conforms -> conform, since it's the verb for three nouns and thus plural. 2013-05-12 10:44:23 +00:00
include namespace protect allocaddrinfo 2015-09-10 14:05:06 +00:00
inet remove unneeded code, and kill parens from return 2014-02-10 16:30:54 +00:00
isc time_t casts 2012-03-21 00:34:54 +00:00
locale Redo the locale cache to be constant. It now contains the localeconv() 2013-09-13 13:13:32 +00:00
md undo, the right place for this is compat_defs.h 2014-09-24 13:18:52 +00:00
misc Put the startup code in .text.startup 2013-08-19 22:14:37 +00:00
nameser reduce diffs with other copies of this code. 2014-03-07 01:07:01 +00:00
net put the state back after it is used. 2015-10-26 19:41:19 +00:00
nls belt-n-suspenders, close on exec catalog files. 2014-09-16 01:30:28 +00:00
quad Don't return 0x1.0p31 for every input value 2^N. 2013-09-30 19:32:14 +00:00
regex use the unsigned char version of the input char in all cases "cap[uc]" to 2015-09-12 19:08:47 +00:00
resolv belated removal of the advertising clause. 2015-02-24 17:56:20 +00:00
rpc remove various HAVE_GCC=45 fragments. 2015-04-15 19:13:46 +00:00
softfloat Restrict the arm compiler optimization hack to gcc 4.5 2015-04-08 13:16:37 +00:00
ssp void * is bad for computation, so cast to const char * first. 2015-05-13 19:57:16 +00:00
stdio add a bunch of functions found in <stdio.h> that weren't listed here. 2015-09-06 04:20:50 +00:00
stdlib ANSIfy getopt(3) - this is the REPLACE_GETOPT version from getopt_long(3) 2015-09-01 19:39:57 +00:00
string PR 49988 Kamil Rytarowski: fix pasto 2015-06-20 04:18:00 +00:00
sys PR/50295: Fix clock_nanosleep return value documentation. 2015-10-02 19:52:49 +00:00
termios Update old-style definitions to ANSI, remove a couple of register 2012-06-25 22:32:43 +00:00
thread-stub Put the startup code in .text.startup 2013-08-19 22:14:37 +00:00
time Release 2015g - 2015-10-01 00:39:51 -0700 2015-10-09 17:21:45 +00:00
tls fix powerpc TLS problems by removing the hacks for PPC EABI. 2014-12-14 23:49:17 +00:00
uuid
yp fix error messages 2015-06-17 00:15:26 +00:00
Makefile Only create and install the tags file for the normal libc (not any of the 2015-06-15 14:24:01 +00:00
Makefile.inc Don't unconditionally pass MLIBDIR via CPPFLAGS. Drop now dead branch. 2015-08-28 11:45:02 +00:00
README Elaborate documentation of libc symbol rules. 2015-07-11 15:23:57 +00:00
libcincludes.mk MKCOMPAT fixes for when compat MACHINE_CPU != normal MACHINE_CPU 2014-08-10 23:39:08 +00:00
shlib_version bump libc for strtoi and strtou 2015-01-16 18:45:01 +00:00

README

	$NetBSD: README,v 1.5 2015/07/11 15:23:57 riastradh Exp $

libc: The C library.

* ELF symbols and source names

libc contains symbols for:

(a) standard library routines in C and POSIX,
(b) published NetBSD-specific nonstandard extensions,
(c) internal symbols, and
(d) old versions of any published library routines.

** Standard library routines

If a library routine is standard and its signature has never changed,
it is provided as an ELF global symbol.  Its name is declared normally
in the appropriate header file.

=> Example: The names `malloc' and `free' are declared normally in
   <stdlib.h> (src/include/stdlib.h):

	void	*malloc(size_t);
	void	 free(void *);

   libc provides the following ELF symbols:

	malloc		global
	free		global

   In the implementation of libc, malloc and free are defined normally
   in src/lib/libc/stdlib/jemalloc.c:

	void *
	malloc(size_t size)
	{
	...

	void
	free(void *ptr)
	{
	...

** NetBSD-specific nonstandard extensions

If a library routine is nonstandard but published and its signature has
never changed, it is provided as an ELF weak symbol aliasing an ELF
global symbol of the same name with an underscore prefix.

The name is declared normally in the appropriate header file, provided
that the relevant feature macro, such as _NETBSD_SOURCE, is defined.

Within libc, the name is defined in "namespace.h"
(src/lib/libc/include/namespace.h) as a macro expanding to the
underscored name, which is included before the relevant header file, so
that

(a) the definition in a .c file will define the underscored ELF global
symbol, and

(b) the declaration in the standard header file will match the
definition in the .c file.

Alongside the definition in the .c file is a __weak_alias directive to
create the ELF weak symbol alias.

=> Example: For the nonstandard extension consttime_memequal, the
   header file <string.h> (src/include/string.h) declares
   `consttime_memequal' normally, if the caller defines _NETBSD_SOURCE:

	#if defined(_NETBSD_SOURCE)
	...
	int	consttime_memequal(const void *, const void *, size_t);
	...
	#endif	/* _NETBSD_SOURCE */

   libc provides the following ELF symbols:

	_consttime_memequal	global
	consttime_memequal	weak alias for	_consttime_memequal

   In the implementation of libc, the header file "namespace.h"
   (src/lib/libc/include/namespace.h) defines `consttime_memequal' as a
   macro expanding to `_consttime_memequal':

	#define	consttime_memequal	_consttime_memequal

   The source file src/common/lib/libc/string/consttime_memequal.c
   includes "namespace.h" and <string.h>, and defines
   `consttime_memequal' normally:

	int
	consttime_memequal(const void *b1, const void *b2, size_t len)
	{
	...

   Macro expansion replaces `consttime_memequal' by
   `_consttime_memequal', which is the ELF global symbol this defines.
   Alongside the definition is

	__weak_alias(consttime_memequal,_consttime_memequal)

   to provide `consttime_memequal' as an ELF weak symbol aliasing
   `_consttime_memequal'.

** Internal symbols

If a library routine is internal to libc, it is defined as an ELF
global symbol with an underscore prefix.  Its name is declared in the
appropriate internal header file.

=> Example: The implementations of opendir and rewinddir use a common
   subroutine _initdir, which is not part of the libc API or ABI -- it
   is just an internal subroutine.

   libc provides the following ELF symbols:

	_initdir	global

   The name `_initdir' is declared normally in
   src/lib/libc/gen/dirent_private.h:

	int	_initdir(DIR *, int, const char *);

   The name `_initdir' is defined normally in
   src/lib/libc/gen/initdir.c:

	int
	_initdir(DIR *dirp, int fd, const char *name)
	{
	...

** Old versions of library routines

If the signature or semantics of a library routine foo changed in (for
example) NetBSD 6.0, then libc provides

(1) an ELF global symbol `_foo' implementing its old signature,
(2) an ELF weak symbol `foo' aliasing `_foo', and
(3) an ELF global symbol `__foo50' implementing its new signature (yes,
    `__foo50', not `__foo60').

The name foo is declared in the appropriate header file, under any
relevant feature macros, with a __RENAME directive so that for calls to
foo, the compiler will generate relocations for __foo50.  Old programs,
compiled with the old signature, will continue to use the old symbol.

=> Example: In NetBSD 5.0, time_t was int32_t on every machine.  In
   NetBSD 6.0 and onward, time_t is int64_t on every machine.
   Consequently, the signature of time(3), written as

	time_t	time(time_t *);

   was effectively

	int32_t	time(int32_t *);

   before NetBSD 6.0.  In NetBSD 6.0, it changed to be effectively

	int64_t time(int64_t *);

   Before NetBSD 6.0, libc provided the following libc symbols:

	_time		global (implementing the old signature)
	time		weak alias for _time

   In NetBSD 6.0 and later, libc provides the following ELF symbols:

	_time		global (implementing the old signature)
	time		weak alias for _time
	__time50	global (implementing the new signature)

   (Note that the only change is to add __time50, so that existing
   programs linked against old versions of libc will see the same
   semantics for the symbols that were already there.)

   The header file <time.h> (src/include/time.h) declares

	time_t	time(time_t *) __RENAME(__time50);

   so that compiling C programs that call time will yield objects that
   use the __time50 symbol from libc.  However, old programs that were
   compiled against the 32-bit declaration will continue to use the
   32-bit symbol from libc.

   The header file "namespace.h" (src/lib/libc/include/namespace.h)
   defines `time' as a macro expanding to `_time':

	#define	time	_time

   The source file src/lib/libc/gen/time.c includes "namespace.h" and
   <time.h> and defines `time' normally:

	time_t
	time(time_t *t)
	{
	...

   Macro expansion replaces `time' by `_time', but the
   `__RENAME(__time50)' directive on the declaration <time.h> (to which
   the "namespace.h" macro expansion also applies) means the ELF global
   symbol defined here is actually `__time50'.

   The header file <compat/include/time.h>
   (src/lib/libc/compat/include/time.h) declares

	int32_t	time(int32_t *);

   The source file src/lib/libc/compat/gen/compat_time.c includes
   "namespace.h", <compat/include/time.h>, and <time.h>, but suppresses
   the normal declaration of `time' in <time.h> by defining
   __LIBC12_SOURCE__.  Instead, <compat/include/time.h>
   (src/lib/libc/compat/include/time.h) declares `time' with the
   effective old signature:

	int32_t	time(int32_t *);

   Then compat_time.c defines `time' normally:

	time_t
	time(time_t *t)
	{
	...

   Again, macro expansion replaces `time' by `_time', but since there
   is no __RENAME directive in <compat/include/time.h>, the resulting
   ELF global symbol is `_time'.

   Finally, alongside the definition in compat_time.c is

	__weak_alias(time,_time)

   to define `time' as an ELF weak symbol aliasing `_time'.

   The net effect is that NetBSD 6's libc provides the same definitions
   as NetBSD 5's libc for the symbols `time' and `_time', so that old
   programs that were compiled in NetBSD 5 will continue to work with
   NetBSD 6's libc.  But programs compiled in NetBSD 6 will have 64-bit
   time_t.