NetBSD/lib/libc
nia f76dddbc66 getaddrinfo(3): malloc + memset -> calloc 2021-10-27 19:24:38 +00:00
..
arch Merge all MD __sigaction14_sigtramp.c copies into one: 2021-10-26 16:16:34 +00:00
atomic Add italic correction to _Atomic-qualified. 2020-10-09 19:41:02 +00:00
cdb Optimize CPU and memory use of cdbw(3) 2021-01-07 14:41:50 +00:00
citrus Don't overalign _RuneStatePriv, it must share the alignment of mbstate_t 2020-06-02 01:30:31 +00:00
compat fix various typos in compatibility, mainly in comments. 2021-08-09 20:49:08 +00:00
compat-43 create was present in v1 2019-09-01 19:28:31 +00:00
compiler_rt PR port-arm/55897 2021-06-16 05:21:08 +00:00
db Avoid undefined behavior in *BIT macros 2020-02-21 22:04:06 +00:00
dlfcn Compute relocbase correctly for static PIE. AT_BASE is not usable in 2018-07-13 19:49:47 +00:00
gdtoa fix typos in word "successfully", mainly s/succesfully/successfully/. 2021-09-16 21:29:41 +00:00
gen Add missing double p and d for stopped and overriden accordingly. 2021-09-11 20:28:03 +00:00
gmon libc: suppress lint warning for namespacing mismatch for _mcount 2021-08-29 16:44:16 +00:00
hash Use An in AUTHORS section. 2018-12-17 08:18:06 +00:00
iconv Switch the iconv(3) prototype to the POSIX conformant variation 2019-10-24 18:17:14 +00:00
include Add missing double p and d for stopped and overriden accordingly. 2021-09-11 20:28:03 +00:00
inet Remove unused macro. 2018-12-13 08:39:34 +00:00
isc
locale setlocale.3: minor updates to reflect the current implementation 2021-10-24 17:30:19 +00:00
md Use .An in authors section. Remove empty section. 2018-05-23 06:08:01 +00:00
misc Instead of compiling files with -fcommon, create an include file and declare 2021-04-20 21:42:31 +00:00
nameser Since we advance cp after the bounds check, we need to test for bounds 2019-09-04 12:14:09 +00:00
net getaddrinfo(3): malloc + memset -> calloc 2021-10-27 19:24:38 +00:00
nls PR standards/44921: Add errno consts for robust mutexes 2020-03-08 22:09:42 +00:00
posix1e this file contained the same information as extattr_namespace_to_string.3 2020-07-26 18:10:00 +00:00
quad
regex PR/56120: Chris Pinnock: build.sh (-m alpha) release fails on current on 2021-04-22 19:20:24 +00:00
resolv kqueue(2) file descriptors are not inherited across fork(2). A 2021-09-30 12:35:55 +00:00
rpc fix mainly same typos as in my previous commit but outside sys/dev/dm. 2021-08-21 23:00:30 +00:00
softfloat Avoid warnings (signed/unsigned comparision and unused variable) 2016-03-29 18:42:29 +00:00
ssp make the 2nd argument to __memmove_chk() const 2020-09-05 13:37:59 +00:00
stdio printf(3): mention snprintb(3) 2021-09-23 12:17:57 +00:00
stdlib Remove lint workarounds 2021-08-30 13:12:16 +00:00
string for GCC, built memset.c with -fno-builtin. this avoids GCC 10 compiling 2021-04-14 08:07:49 +00:00
sys - Use the signal trampoline version constants from <sys/signal.h>. 2021-10-27 04:48:33 +00:00
termios tcgetsid() is defined in <termios.h>, not <sys/types.h> or <unistd.h>. 2019-12-19 16:12:21 +00:00
thread-stub change libc sched_yield() stub to actually still call the syscall 2021-02-06 00:08:58 +00:00
time fix problem with uninitialized variable on malformed 32 bit time. 2021-10-27 11:27:25 +00:00
tls mmap MAP_FAILED audit. 2020-08-20 15:54:11 +00:00
uuid
yp Remove useless macros. Sort errors. 2018-02-11 13:30:55 +00:00
Makefile Add ACL support for FFS. From FreeBSD. 2020-05-16 18:31:45 +00:00
Makefile.inc Instead of compiling files with -fcommon, create an include file and declare 2021-04-20 21:42:31 +00:00
README Omit duplicate text. 2017-02-08 13:31:36 +00:00
libcincludes.mk MKCOMPAT fixes for when compat MACHINE_CPU != normal MACHINE_CPU 2014-08-10 23:39:08 +00:00
shlib_version Add native implementations of eventfd(2) and timerfd(2), compatible with 2021-09-19 15:51:27 +00:00

README

	$NetBSD: README,v 1.7 2017/02/08 13:31:36 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__ and thus gets it from <compat/include/time.h>
   instead.  Then compat_time.c defines `time' normally:

	int32_t
	time(int32_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'.  (Actually, compat_time.c just has
   `#define time_t int32_t' and `#include "gen/time.c"' to get the same
   text of the definition of time.  The above definition is what we get
   effectively by substituting int32_t for the type time_t.)

   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.