Glibc_vs_uClibc.html 11 KB

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