{"id":2074,"date":"2015-04-18T14:46:30","date_gmt":"2015-04-18T06:46:30","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=2074"},"modified":"2015-04-18T14:46:30","modified_gmt":"2015-04-18T06:46:30","slug":"linux%e4%b8%ad%e7%9a%84glibc%e5%92%8clibc-so-6","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/2074.html","title":{"rendered":"Linux\u4e2d\u7684[g]libc\u548clibc.so.6"},"content":{"rendered":"<p>\u5728\u64cd\u4f5c\u7684\u65f6\u5019\u72af\u4e86\u5927\u9519\uff0c\u4e0d\u60f3\u591a\u8bf4\uff0c\u4e00\u53e5\u8bdd\uff1a\u7cfb\u7edf\u65e0\u6cd5\u6b63\u5e38\u767b\u5f55\u4e86\u2026\u2026\u4e4b\u524d\u8fd8\u4e0d\u6e05\u695alibc\u6216glibc\u5728Linux\u7cfb\u7edf\u4e0a\u7684\u91cd\u8981\u6027\uff08\u73b0\u5728\u771f\u7684\u662f\u5207\u5207\u5b9e\u5b9e\u7684\u8ba4\u8bc6\u5230\u4e86\uff0c\u6c89\u75db\u7684\u7ecf\u9a8c\u6559\u8bad\u554a\uff01\uff09<\/p>\n<p>\u641c\u7d22\u5173\u952e\u5b57\uff1a<\/p>\n<ul>\n<li>linux libc.so.<\/li>\n<li>linux libc.so.6 stackoverflow.com<\/li>\n<li>site:stackoverflow.com LD_LIBRARY_PATH LD_PRELOAD<\/li>\n<\/ul>\n<p>==<\/p>\n<pre class=\"lang:default decode:true \">env\nexport LD_LIBRARY_PATH=\/lib\/i386-linux-gnu\nexport LD_PRELOAD=\/lib\/i386-linux-gnu\/libc-2.19.so<\/pre>\n<p>libc implements both standard C functions like strcpy() and POSIX functions (which may be system calls) like getpid(). Note that <span style=\"color: #ff0000;\">not all standard C functions are in libc &#8211; most math functions are in libm<\/span>.<\/p>\n<p>You cannot directly make system calls in the same way that you call normal functions because calls to the kernel aren&#8217;t normal function calls, so they can&#8217;t be resolved by the linker. Instead, architecture-specific assembly language thunks are used to call into the kernel &#8211; you can of course write these directly in your own program too, but you don&#8217;t need to because libc provides them for you.<\/p>\n<p>Note that in Linux it is the combination of the kernel and libc that provides the POSIX API. libc adds a decent amount of value &#8211; not every POSIX function is necessarily a system call, and for the ones that are, the kernel behaviour isn&#8217;t always POSIX conforming.<\/p>\n<p><span style=\"color: #ff0000;\"><strong>libc is a single library file<\/strong><\/span> (both .so and .a versions are available) and in most cases resides in \/usr\/lib. However, the glibc (GNU libc) project provides more than just libc &#8211; it also provides the libm mentioned earlier, and other core libraries like libpthread. So libc is just one of the libraries provided by glibc &#8211; and there are other alternate implementations of libc other than glibc.<\/p>\n<p>=<\/p>\n<h6><strong>Why glibc binary is called libc.so.6 not a libc.so.1 or libc.so.4?<\/strong><\/h6>\n<p>Those\u00a0<a href=\"http:\/\/en.wikipedia.org\/wiki\/Soname\" target=\"_blank\">SONAMEs<\/a>\u00a0have already been used. Since the new version of the library presents a break in the interface, a new major SONAME number must be used for it.<\/p>\n<p>=<\/p>\n<p>The term &#8220;libc&#8221; is commonly used as a shorthand for the &#8220;<span style=\"color: #ff0000;\"><strong>standard C library<\/strong><\/span>&#8220;, a library of standard functions that can be used by all C programs (and sometimes by programs in other languages).\u00a0 <span style=\"color: #ff0000;\">Because of some history (see below), use of the term &#8220;libc&#8221; to refer to the standard C library is somewhat ambiguous on Linux.<\/span><\/p>\n<h6>glibc<\/h6>\n<p>By far the most widely used C library on Linux is the GNU C Library &lt;http:\/\/www.gnu.org\/software\/libc\/&gt;, often referred to as glibc.<\/p>\n<p>This is the C library that is nowadays used in all major Linux distributions.\u00a0 It is also the C library whose details are documented in the relevant pages of the man-pages project (primarily in Section 3 of the manual).\u00a0 Documentation of glibc is also available in the glibc manual, available via the command info libc.\u00a0 Release 1.0 of glibc was made in September 1992.\u00a0 (There were earlier 0.x releases.)<\/p>\n<p>The next major release of glibc was 2.0, at the beginning of 1997.<\/p>\n<p>The pathname \/lib\/libc.so.6 (or something similar) is normally a symbolic link that points to the location of the glibc library, and executing this pathname will cause glibc to display various information about the version installed on your system.<\/p>\n<h6>Linux libc<\/h6>\n<p>In the early to mid 1990s, there was for a while Linux libc, a fork of glibc 1.x created by Linux developers who felt that glibc development at the time was not sufficing for the needs of Linux.\u00a0 Often, this library was referred to (ambiguously) as just &#8220;libc&#8221;.\u00a0 Linux libc released major versions 2, 3, 4, and 5 (as well as many minor versions of those releases).\u00a0 For a while, Linux libc was the standard C library in many Linux distributions.<\/p>\n<p>However, notwithstanding the original motivations of the Linux libc effort, by the time glibc 2.0 was released (in 1997), it was clearly superior to Linux libc, and all major Linux distributions that had been using Linux libc soon switched back to glibc.\u00a0 Since this switch occurred long ago, man-pages no longer takes care to document Linux libc details.\u00a0 Nevertheless, the history is visible in vestiges of information about Linux libc that remain in some manual pages, in particular, references to libc4 and libc5.<\/p>\n<h6>Other C libraries<\/h6>\n<p>There are various other less widely used C libraries for Linux.<\/p>\n<p>These libraries are generally smaller than glibc, both in terms of features and memory footprint, and often intended for building small binaries, perhaps targeted at development for embedded Linux systems.<\/p>\n<p>Among such libraries are uClibc &lt;http:\/\/www.uclibc.org\/&gt;, dietlibc &lt;http:\/\/www.fefe.de\/dietlibc\/&gt;, and musl libc &lt;http:\/\/www.musl-libc.org\/&gt;.\u00a0 Details of these libraries are covered by the man-pages project, where they are known.<\/p>\n<p>==<\/p>\n<h6>\u53c2\u8003\u94fe\u63a5\uff1a<\/h6>\n<ul>\n<li><a href=\"http:\/\/man7.org\/linux\/man-pages\/man7\/libc.7.html\">http:\/\/man7.org\/linux\/man-pages\/man7\/libc.7.html<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/11372872\/what-the-role-of-libcglibc-in-our-linux-app\">http:\/\/stackoverflow.com\/questions\/11372872\/what-the-role-of-libcglibc-in-our-linux-app<\/a><\/li>\n<li>=<\/li>\n<li><a href=\"http:\/\/en.wikipedia.org\/wiki\/GNU_C_Library\">http:\/\/en.wikipedia.org\/wiki\/GNU_C_Library<\/a><\/li>\n<li><a href=\"https:\/\/sourceware.org\/glibc\/wiki\/FAQ\">https:\/\/sourceware.org\/glibc\/wiki\/FAQ<\/a><\/li>\n<li><a href=\"http:\/\/www.gnu.org\/software\/libc\/\">http:\/\/www.gnu.org\/software\/libc\/<\/a><\/li>\n<li>=<\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/6495817\/why-glibc-binary-is-called-libc-so-6-not-a-libc-so-1-or-libc-so-4\">http:\/\/stackoverflow.com\/questions\/6495817\/why-glibc-binary-is-called-libc-so-6-not-a-libc-so-1-or-libc-so-4<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/12249547\/how-to-recover-after-deleting-the-symbolic-link-libc-so-6\">http:\/\/stackoverflow.com\/questions\/12249547\/how-to-recover-after-deleting-the-symbolic-link-libc-so-6<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/19682782\/relevance-of-libc-so-6-in-linux-kernel\">http:\/\/stackoverflow.com\/questions\/19682782\/relevance-of-libc-so-6-in-linux-kernel<\/a><\/li>\n<li><a href=\"https:\/\/blogs.oracle.com\/ksplice\/entry\/hello_from_a_libc_free\">https:\/\/blogs.oracle.com\/ksplice\/entry\/hello_from_a_libc_free<\/a><\/li>\n<li>=<\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/14715175\/what-is-the-difference-between-ld-preload-path-and-ld-library-path\">http:\/\/stackoverflow.com\/questions\/14715175\/what-is-the-difference-between-ld-preload-path-and-ld-library-path<\/a><\/li>\n<li><a href=\"http:\/\/joxeankoret.com\/blog\/2012\/11\/14\/patching-old-linux-binaries-to-work-with-recent-libc-versions\/\">http:\/\/joxeankoret.com\/blog\/2012\/11\/14\/patching-old-linux-binaries-to-work-with-recent-libc-versions\/<\/a><\/li>\n<li>=<\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/3436008\/how-to-determine-version-of-glibc-glibcxx-binary-will-depend-on\">http:\/\/stackoverflow.com\/questions\/3436008\/how-to-determine-version-of-glibc-glibcxx-binary-will-depend-on<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/2856438\/how-can-i-link-to-a-specific-glibc-version\">http:\/\/stackoverflow.com\/questions\/2856438\/how-can-i-link-to-a-specific-glibc-version<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/725472\/static-link-of-shared-library-function-in-gcc\">http:\/\/stackoverflow.com\/questions\/725472\/static-link-of-shared-library-function-in-gcc<\/a><\/li>\n<li>=<\/li>\n<li><a href=\"http:\/\/www.tldp.org\/HOWTO\/Glibc2-HOWTO-5.html\">http:\/\/www.tldp.org\/HOWTO\/Glibc2-HOWTO-5.html<\/a><\/li>\n<li><a href=\"http:\/\/www.tldp.org\/FAQ\/Linux-FAQ\/system-libraries.html\">http:\/\/www.tldp.org\/FAQ\/Linux-FAQ\/system-libraries.html<\/a><\/li>\n<li>=<\/li>\n<li><a href=\"http:\/\/www.linuxfromscratch.org\/lfs\/view\/development\/chapter06\/glibc.html\">http:\/\/www.linuxfromscratch.org\/lfs\/view\/development\/chapter06\/glibc.html<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u64cd\u4f5c\u7684\u65f6\u5019\u72af\u4e86\u5927\u9519\uff0c\u4e0d\u60f3\u591a\u8bf4\uff0c\u4e00\u53e5\u8bdd\uff1a\u7cfb\u7edf\u65e0\u6cd5\u6b63\u5e38\u767b\u5f55\u4e86\u2026\u2026\u4e4b\u524d\u8fd8\u4e0d\u6e05\u695alibc\u6216glibc\u5728Linux\u7cfb\u7edf [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,11],"tags":[455,489],"class_list":["post-2074","post","type-post","status-publish","format-standard","hentry","category-knowledgebase-2","category-linux","tag-glibc","tag-libc"],"views":6901,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2074","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=2074"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2074\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=2074"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=2074"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=2074"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}