README revision 1.1
11.1Sriastrad $NetBSD: README,v 1.1 2015/03/20 12:57:48 riastradh Exp $ 21.1Sriastrad 31.1Sriastradlibc: The C library. 41.1Sriastrad 51.1Sriastrad* ELF symbols and source names 61.1Sriastrad 71.1Sriastradlibc contains symbols for: 81.1Sriastrad 91.1Sriastrad(a) standard library routines in C and POSIX, 101.1Sriastrad(b) published NetBSD-specific nonstandard extensions, 111.1Sriastrad(c) old versions of library routines, and 121.1Sriastrad(d) internal symbols. 131.1Sriastrad 141.1SriastradIf a library routine is standard and its signature has never changed, 151.1Sriastradit is defined as an ELF global symbol. Its name is declared normally 161.1Sriastradin the appropriate header file. 171.1Sriastrad 181.1Sriastrad=> Example: libc defines global symbols `malloc' and `free' for the 191.1Sriastrad standard C memory allocator routines. The names `malloc' and `free' 201.1Sriastrad are declared normally in <stdlib.h> (src/include/stdlib.h). 211.1Sriastrad 221.1SriastradIf a library routine is nonstandard but published and its signature has 231.1Sriastradnever changed, it is defined as an ELF weak symbol aliasing an ELF 241.1Sriastradglobal symbol of the same name with an underscore prefix. 251.1Sriastrad 261.1SriastradThe name is declared normally in the appropriate header file, provided 271.1Sriastradthat the relevant feature macro, such as _NETBSD_SOURCE, is defined. 281.1Sriastrad 291.1SriastradWithin libc, the name is defined in "namespace.h" 301.1Sriastrad(src/lib/libc/include/namespace.h) as a macro expanding to the 311.1Sriastradunderscored name, so that the definition in a .c file will define the 321.1Sriastradunderscored ELF global symbol. 331.1Sriastrad 341.1SriastradAlongside the definition in the .c file is a __weak_alias directive to 351.1Sriastradcreate the ELF weak symbol alias. 361.1Sriastrad 371.1Sriastrad=> Example: For the nonstandard extension consttime_memequal, libc 381.1Sriastrad defines a weak symbol `consttime_memequal' aliasing a global symbol 391.1Sriastrad `_consttime_memequal'. 401.1Sriastrad 411.1Sriastrad The name `consttime_memequal' is declared in <string.h> 421.1Sriastrad (src/include/string.h) if the caller defines _NETBSD_SOURCE. 431.1Sriastrad 441.1Sriastrad The name `consttime_memequal' is defined as a macro in "namespace.h" 451.1Sriastrad (src/lib/libc/include/namespace.h) expanding to 461.1Sriastrad `_consttime_memequal'. The source name `consttime_memequal' is 471.1Sriastrad defined in src/common/lib/libc/string/consttime_memequal.c, causing 481.1Sriastrad the ELF global symbol `_consttime_memequal' to be defined, after 491.1Sriastrad macro expansion. 501.1Sriastrad 511.1Sriastrad Alongside the definition is 521.1Sriastrad 531.1Sriastrad __weak_alias(consttime_memequal,_consttime_memequal) 541.1Sriastrad 551.1Sriastrad to provide `consttime_memequal' as an ELF weak symbol aliasing 561.1Sriastrad `_consttime_memequal'. 571.1Sriastrad 581.1SriastradIf a library routine is internal to libc, it is defined as an ELF 591.1Sriastradglobal symbol with an underscore prefix. 601.1Sriastrad 611.1SriastradIts name is declared in the appropriate internal header file. 621.1Sriastrad 631.1Sriastrad=> Example: For the internal library routine _initdir, used by the 641.1Sriastrad implementations of opendir and rewinddir, libc defines a global 651.1Sriastrad symbol `_initdir'. 661.1Sriastrad 671.1Sriastrad The name `_initdir' is declared normally in 681.1Sriastrad src/lib/libc/gen/dirent_private.h. 691.1Sriastrad 701.1SriastradIf the signature or semantics of a library routine foo changed in (for 711.1Sriastradexample) NetBSD 6.0, then libc provides 721.1Sriastrad 731.1Sriastrad(1) an ELF global symbol `_foo' implementing its old signature, 741.1Sriastrad(2) an ELF weak symbol `foo' aliasing `_foo', and 751.1Sriastrad(3) an ELF global symbol `__foo50' implementing its new signature (yes, 761.1Sriastrad `__foo50', not `__foo60'). 771.1Sriastrad 781.1SriastradThe name foo is declared in the appropriate header file, under any 791.1Sriastradrelevant feature macros, with a __RENAME directive so that for calls to 801.1Sriastradfoo, the compiler will generate relocations for __foo50. Old programs, 811.1Sriastradcompiled with the old signature, will continue to use the old symbol. 821.1Sriastrad 831.1Sriastrad=> Example: In NetBSD 5.0, time_t was int32_t on every machine. In 841.1Sriastrad NetBSD 6.0 and onward, time_t is int64_t on every machine. 851.1Sriastrad Consequently, the signature of time(3), written as 861.1Sriastrad 871.1Sriastrad time_t time(time_t *); 881.1Sriastrad 891.1Sriastrad changed in NetBSD 6.0 from being effectively 901.1Sriastrad 911.1Sriastrad int32_t time(int32_t *); 921.1Sriastrad 931.1Sriastrad to being effectively 941.1Sriastrad 951.1Sriastrad int64_t time(int64_t *); 961.1Sriastrad 971.1Sriastrad Thus, libc provides 981.1Sriastrad 991.1Sriastrad (1) the ELF global symbol `_time' implementing the old signature, 1001.1Sriastrad (2) the ELF weak symbol `time' aliasing `_time', and 1011.1Sriastrad (3) the ELF global symbol `__time50' implementing the new signature. 1021.1Sriastrad 1031.1Sriastrad The header file <time.h> declares 1041.1Sriastrad 1051.1Sriastrad time_t time(time_t *) __RENAME(__time50); 1061.1Sriastrad 1071.1Sriastrad so that compiling C programs that call time will yield objects that 1081.1Sriastrad use the __time50 symbol from libc. However, old programs that were 1091.1Sriastrad compiled against the 32-bit declaration will continue to use the 1101.1Sriastrad 32-bit symbol from libc. 111