NetBSD/lib/libc
christos 0c69da7c8a welcome to tzcode 2015d (zic performance improvements and cleanups) 2015-04-28 17:00:24 +00:00
..
arch Add set/longjmp and friends (nearly verbatim from FreeBSD). 2015-04-17 12:51:05 +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 Fix our iconv version for the issues that apply to us from CVE-2014-3951 2014-06-24 22:24:18 +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
compiler_rt Changes for OR1K 2014-09-03 19:29:14 +00:00
db whitelist O_CLOEXEC flag, should fix lastlogin issue. 2014-12-22 17:01:42 +00:00
dlfcn
gdtoa Fix non _REENTRANT build. 2015-01-20 18:31:24 +00:00
gen Remove #ifdef MAP_INHERIT_ZERO. 2015-03-19 05:46:25 +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
include Introduce reallocarr(3) for easy (re)allocation of memory with overflow 2015-02-17 20:29:20 +00:00
inet remove unneeded code, and kill parens from return 2014-02-10 16:30:54 +00:00
isc
locale
md undo, the right place for this is compat_defs.h 2014-09-24 13:18:52 +00:00
misc
nameser reduce diffs with other copies of this code. 2014-03-07 01:07:01 +00:00
net remove various HAVE_GCC=45 fragments. 2015-04-15 19:13:46 +00:00
nls belt-n-suspenders, close on exec catalog files. 2014-09-16 01:30:28 +00:00
quad
regex Use reallocarr and simplify. Document valid reallocation failures. 2015-02-17 20:30:44 +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 Provide explicit prototypes in case HAVE_SSP=no. 2014-09-17 00:39:28 +00:00
stdio Use Pq to avoid space before O_EXCL. 2015-02-11 15:19:05 +00:00
stdlib Redo __aeabi_atexit by shuffling the arguments and dropping the code in 2015-04-19 18:15:26 +00:00
string Strengthen prohibition against overlapping in strcpy(3). 2015-04-01 20:18:17 +00:00
sys Remove trailing whitespace. 2015-04-22 13:59:54 +00:00
termios
thread-stub
time welcome to tzcode 2015d (zic performance improvements and cleanups) 2015-04-28 17:00:24 +00:00
tls fix powerpc TLS problems by removing the hacks for PPC EABI. 2014-12-14 23:49:17 +00:00
uuid
yp make more descriptors that we open as close-on-exec 2014-09-18 13:58:20 +00:00
Makefile Include compat in rumprun libc 2015-02-09 22:44:34 +00:00
Makefile.inc Add hooks for RUMPRUN build of libc 2014-12-10 00:37:30 +00:00
README Tweak wording. 2015-03-20 14:10:40 +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.3 2015/03/20 14:10:40 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) old versions of library routines, and
(d) internal symbols.

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

=> Example: libc defines global symbols `malloc' and `free' for the
   standard C memory allocator routines.  The names `malloc' and `free'
   are declared normally in <stdlib.h> (src/include/stdlib.h).

If a library routine is nonstandard but published and its signature has
never changed, it is defined 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, so that the definition in a .c file will define the
underscored ELF global symbol.

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, libc
   defines a weak symbol `consttime_memequal' aliasing a global symbol
   `_consttime_memequal'.

   The header file <string.h> (src/include/string.h) declares
   `consttime_memequal' normally, if the caller defines _NETBSD_SOURCE.

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

   The source file src/common/lib/libc/string/consttime_memequal.c
   includes "namespace.h" and <string.h>, and defines
   `consttime_memequal' normally, which, after macro expansion, causes
   the ELF global symbol `_consttime_memequal' to be defined.

   Alongside the definition is

	__weak_alias(consttime_memequal,_consttime_memequal)

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

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: For the internal library routine _initdir, used by the
   implementations of opendir and rewinddir, libc defines a global
   symbol `_initdir'.  The name `_initdir' is declared normally in
   src/lib/libc/gen/dirent_private.h, and defined normally in
   src/lib/libc/gen/initdir.c.

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 *);

   changed in NetBSD 6.0 from being effectively

	int32_t time(int32_t *);

   to being effectively

	int64_t time(int64_t *);

   Thus, libc provides

   (1) the ELF global symbol `_time' implementing the old signature,
   (2) the ELF weak symbol `time' aliasing `_time', and
   (3) the ELF global symbol `__time50' implementing the new signature.

   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'.

   The source file src/lib/libc/gen/time.c includes "namespace.h" and
   <time.h> and defines `time' normally.  The declaration of `time' in
   <time.h> is replaced after macro expansion by a declaration of
   `_time', and the definition in time.c is replaced by a definition of
   `_time'.  But the __RENAME directive causes the resulting ELF global
   symbol to be `__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__.  Then compat_time.c defines `time' normally.
   Again, the name is replaced after macro expansion 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 provide `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.