Glibc_vs_uClibc_Differences.txt 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. uClibc and Glibc are not the same -- there are a number of differences which
  2. may or may not cause you problems. This document attempts to list these
  3. differences and, when completed, will contain a full list of all relevant
  4. differences.
  5. 1) uClibc is smaller than glibc. We attempt to maintain a glibc compatible
  6. interface, allowing applications that compile with glibc to easily compile with
  7. uClibc. However, we do not include _everything_ that glibc includes, and
  8. therefore some applications may not compile. If this happens to you, please
  9. report the failure to the uclibc mailing list, with detailed error messages.
  10. 2) uClibc is much more configurable then glibc. This means that a developer
  11. may have compiled uClibc in such a way that significant amounts of
  12. functionality have been omitted.
  13. 3) uClibc does not even attempt to ensure binary compatibility across releases.
  14. When a new version of uClibc is released, you may or may not need to recompile
  15. all your binaries.
  16. 4) malloc(0) in glibc returns a valid pointer to something(!?!?) while in
  17. uClibc calling malloc(0) returns a NULL. The behavior of malloc(0) is listed
  18. as implementation-defined by SuSv3, so both libraries are equally correct.
  19. This difference also applies to realloc(NULL, 0). I personally feel glibc's
  20. behavior is not particularly safe. To enable glibc behavior, one has to
  21. explicitly enable the MALLOC_GLIBC_COMPAT option.
  22. 4.1) glibc's malloc() implementation has behavior that is tunable via the
  23. MALLOC_CHECK_ environment variable. This is primarily used to provide extra
  24. malloc debugging features. These extended malloc debugging features are not
  25. available within uClibc. There are many good malloc debugging libraries
  26. available for Linux (dmalloc, electric fence, valgrind, etc) that work much
  27. better than the glibc extended malloc debugging. So our omitting this
  28. functionality from uClibc is not a great loss.
  29. 5) uClibc does not provide a database library (libdb).
  30. 6) uClibc does not support NSS (/lib/libnss_*), which allows glibc to easily
  31. support various methods of authentication and DNS resolution. uClibc only
  32. supports flat password files and shadow password files for storing
  33. authentication information. If you need something more complex than this,
  34. you can compile and install pam.
  35. 7) uClibc's libresolv is only a stub. Some, but not all of the functionality
  36. provided by glibc's libresolv is provided internal to uClibc. Other functions
  37. are not at all implemented.
  38. 8) libnsl provides support for Network Information Service (NIS) which was
  39. originally called "Yellow Pages" or "YP", which is an extension of RPC invented
  40. by Sun to share Unix password files over the network. I personally think NIS
  41. is an evil abomination and should not be used. These days, using ldap is much
  42. more effective mechanism for doing the same thing. uClibc provides a stub
  43. libnsl, but has no actual support for Network Information Service (NIS).
  44. We therefore, also do not provide any of the headers files provided by glibc
  45. under /usr/include/rpcsvc.
  46. 9) uClibc's locale support is not 100% complete yet. We are working on it.
  47. 10) uClibc's math library only supports long double as inlines, and even
  48. then the long double support is quite limited. Also, very few of the
  49. float math functions are implemented. Stick with double and you should
  50. be just fine.
  51. 11) uClibc's libcrypt does not support the reentrant crypt_r, setkey_r and
  52. encrypt_r, since these are not required by SuSv3.
  53. 12) uClibc directly uses kernel types to define most opaque data types.
  54. 13) uClibc directly uses the linux kernel's arch specific 'struct stat'.
  55. 14) uClibc's librt library currently lacks all aio routines, all clock
  56. routines, and all shm routines (only the timer routines and the mq
  57. routines are implemented).
  58. <other things as we notice them>
  59. ****************************** Manuel's Notes ******************************
  60. Some general comments...
  61. The intended target for all my uClibc code is ANSI/ISO C99 and SUSv3
  62. compliance. While some glibc extensions are present, many will eventually
  63. be configurable. Also, even when present, the glibc-like extensions may
  64. differ slightly or be more restrictive than the native glibc counterparts.
  65. They are primarily meant to be porting _aides_ and not necessarily
  66. drop-in replacements.
  67. Now for some details...
  68. time functions
  69. --------------
  70. 1) Leap seconds are not supported.
  71. 2) /etc/timezone and the whole zoneinfo directory tree are not supported.
  72. To set the timezone, set the TZ environment variable as specified in
  73. http://www.opengroup.org/onlinepubs/007904975/basedefs/xbd_chap08.html
  74. or you may also create an /etc/TZ file of a single line, ending with a
  75. newline, containing the TZ setting. For example
  76. echo CST6CDT > /etc/TZ
  77. 3) Currently, locale specific eras and alternate digits are not supported.
  78. They are on my TODO list.
  79. wide char support
  80. -----------------
  81. 1) The only multibyte encoding currently supported is UTF-8. The various
  82. ISO-8859-* encodings are (optionally) supported. The internal
  83. representation of wchar's is assumed to be 31 bit unicode values in
  84. native endian representation. Also, the underlying char encoding is
  85. assumed to match ASCII in the range 0-0x7f.
  86. 2) In the next iteration of locale support, I plan to add support for
  87. (at least some) other multibyte encodings.
  88. locale support
  89. --------------
  90. 1) The target for support is SUSv3 locale functionality. While nl_langinfo
  91. has been extended, similar to glibc, it only returns values for related
  92. locale entries.
  93. 2) Currently, all SUSv3 libc locale functionality should be implemented
  94. except for wcsftime and collating item support in regex.
  95. stdio
  96. -----
  97. 1) Conversion of large magnitude floating-point values by printf suffers a loss
  98. of precision due to the algorithm used.
  99. 2) uClibc's printf is much stricter than glibcs, especially regarding positional
  100. args. The entire format string is parsed first and an error is returned if
  101. a problem is detected. In locales other than C, the format string is checked
  102. to be a valid multibyte sequence as well. Also, currently at most 10 positional
  103. args are allowed (although this is configurable).
  104. 3) BUFSIZ is configurable, but no attempt is made at automatic tuning of internal
  105. buffer sizes for stdio streams. In fact, the stdio code in general sacrifices
  106. sophistication/performace for minimal size.
  107. 4) uClibc allows glibc-like custom printf functions. However, while not
  108. currently checked, the specifier must be <= 0x7f.
  109. 5) uClibc allows glibc-like custom streams. However, no in-buffer seeking is
  110. done.
  111. 6) The functions fcloseall() and __fpending() can behave differently than their
  112. glibc counterparts.
  113. 7) uClibc's setvbuf is more restrictive about when it can be called than glibc's
  114. is. The standards specify that setvbuf must occur before any other operations
  115. take place on the stream.
  116. 8) Right now, %m is not handled properly by printf when the format uses positional
  117. args.
  118. 9) The FILEs created by glibc's fmemopen(), open_memstream(), and fopencookie()
  119. are not capable of wide orientation. The corresponding uClibc routines do
  120. not have this limitation.
  121. 10) For scanf, the C99 standard states "The fscanf function returns the value of
  122. the macro EOF if an input failure occurs before any conversion." But glibc's
  123. scanf does not respect conversions for which assignment was surpressed, even
  124. though the standard states that the value is converted but not stored.
  125. glibc bugs that Ulrich Drepper has refused to acknowledge or comment on
  126. ( http://sources.redhat.com/ml/libc-alpha/2003-09/ )
  127. -----------------------------------------------------------------------
  128. 1) The C99 standard says that for printf, a %s conversion makes no special
  129. provisions for multibyte characters. SUSv3 is even more clear, stating
  130. that bytes are written and a specified precision is in bytes. Yet glibc
  131. treats the arg as a multibyte string when a precision is specified and
  132. not otherwise.
  133. 2) Both C99 and C89 state that the %c conversion for scanf reads the exact
  134. number of bytes specified by the optional field width (or 1 if not specified).
  135. uClibc complies with the standard. There is an argument that perhaps the
  136. specified width should be treated as an upper bound, based on some historical
  137. use. However, such behavior should be mentioned in the Conformance document.
  138. 3) glibc's scanf is broken regarding some numeric patterns. Some invalid
  139. strings are accepted as valid ("0x.p", "1e", digit grouped strings).
  140. In spite of my posting examples clearly illustrating the bugs, they remain
  141. unacknowledged by the glibc developers.
  142. 4) glibc's scanf seems to require a 'p' exponent for hexadecimal float strings.
  143. According to the standard, this is optional.
  144. 5) C99 requires that once an EOF is encountered, the stream should be treated
  145. as if at end-of-file even if more data becomes available. Further reading
  146. can be attempted by clearing the EOF flag though, via clearerr() or a file
  147. positioning function. For details concerning the original change, see
  148. Defect Report #141. glibc is currently non-compliant, and the developers
  149. did not comment when I asked for their official position on this issue.
  150. 6) glibc's collation routines and/or localedef are broken regarding implicit
  151. and explicit UNDEFINED rules.
  152. More to follow as I think of it...
  153. Profiling:
  154. -------------------------------------------------------------------
  155. uClibc no longer supports 'gcc -fprofile-arcs -pg' style profiling, which
  156. causes your application to generate a 'gmon.out' file that can then be analyzed
  157. by 'gprof'. Not only does this require explicit extra support in uClibc, it
  158. requires that you rebuild everything with profiling support. There is both a
  159. size and performance penalty to profiling your applications this way, as well
  160. as Heisenberg effects, where the act of measuring changes what is measured.
  161. There exist a number of less invasive alternatives that do not require you to
  162. specially instrument your application, and recompile and relink everything.
  163. The OProfile system-wide profiler is an excellent alternative:
  164. http://oprofile.sourceforge.net/
  165. Many people have had good results using the combination of Valgrind
  166. to generate profiling information and KCachegrind for analysis:
  167. http://developer.kde.org/~sewardj/
  168. http://kcachegrind.sourceforge.net/
  169. Prospect is another alternative based on OProfile:
  170. http://prospect.sourceforge.net/
  171. And the Linux Trace Toolkit (LTT) is also a fine tool:
  172. http://www.opersys.com/LTT/
  173. FunctionCheck:
  174. http://www710.univ-lyon1.fr/~yperret/fnccheck/