Why is statically linking glibc discouraged?Where is the x86-64 System V ABI documented?Linux kernel API changes/additionsWith arrays, why is it the case that a[5] == 5[a]?Can templates only be implemented in header files?What does “static” mean in C?Why is “using namespace std;” considered bad practice?Static linking vs dynamic linkingLinux static linking is dead?Why are elementwise additions much faster in separate loops than in a combined loop?Why is reading lines from stdin much slower in C++ than Python?Difference between shared objects (.so), static libraries (.a), and DLL's (.so)?Why is processing a sorted array faster than processing an unsorted array?

What are the occurences of total war in the Native Americans?

“T” in subscript in formulas

How can I unambiguously ask for a new user's "Display Name"?

Why did Khan ask Admiral James T. Kirk about Project Genesis?

Macro inserted via everypar in obeylines context doesn't see some commands

Redacting URLs as an email-phishing preventative?

Boot Windows from SAN

To get so rich that you are not in need of anymore money

Can RMSE and MAE have the same value?

Limitations with dynamical systems vs. PDEs?

How many birds in the bush?

When, exactly, does the Rogue Scout get to use their Skirmisher ability?

Does this VCO produce a sine wave or square wave

Why do banks “park” their money at the European Central Bank?

Movie where people enter a church but find they can't leave, not in English

How does the OS tell whether an "Address is already in use"?

Who was the most successful German spy against Great Britain in WWII, from the contemporary German perspective?

What names do Cormyr's people use?

Does Yeshayahu 43:10b / 43:13a imply HaShem was created?

The Wires Underground

I don't have the theoretical background in my PhD topic. I can't justify getting the degree

Why is the UK so keen to remove the "backstop" when their leadership seems to think that no border will be needed in Northern Ireland?

Is first Ubuntu user root?

What does "rel" in `mathrel` and `stackrel` stands for?



Why is statically linking glibc discouraged?


Where is the x86-64 System V ABI documented?Linux kernel API changes/additionsWith arrays, why is it the case that a[5] == 5[a]?Can templates only be implemented in header files?What does “static” mean in C?Why is “using namespace std;” considered bad practice?Static linking vs dynamic linkingLinux static linking is dead?Why are elementwise additions much faster in separate loops than in a combined loop?Why is reading lines from stdin much slower in C++ than Python?Difference between shared objects (.so), static libraries (.a), and DLL's (.so)?Why is processing a sorted array faster than processing an unsorted array?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








30















Most of the sources online state that you can statically link glibc, but discourage from doing so; e.g. centos package repo:



The glibc-static package contains the C library static libraries
for -static linking. You don't need these, unless you link statically,
which is highly discouraged.


These sources rarely (or never) say why that would be a bad idea.










share|improve this question



















  • 2





    Ironic that CentOS's package repo is so outdated that it sometimes forces developers to link statically.

    – nada
    Aug 13 at 15:01

















30















Most of the sources online state that you can statically link glibc, but discourage from doing so; e.g. centos package repo:



The glibc-static package contains the C library static libraries
for -static linking. You don't need these, unless you link statically,
which is highly discouraged.


These sources rarely (or never) say why that would be a bad idea.










share|improve this question



















  • 2





    Ironic that CentOS's package repo is so outdated that it sometimes forces developers to link statically.

    – nada
    Aug 13 at 15:01













30












30








30








Most of the sources online state that you can statically link glibc, but discourage from doing so; e.g. centos package repo:



The glibc-static package contains the C library static libraries
for -static linking. You don't need these, unless you link statically,
which is highly discouraged.


These sources rarely (or never) say why that would be a bad idea.










share|improve this question














Most of the sources online state that you can statically link glibc, but discourage from doing so; e.g. centos package repo:



The glibc-static package contains the C library static libraries
for -static linking. You don't need these, unless you link statically,
which is highly discouraged.


These sources rarely (or never) say why that would be a bad idea.







c++ c linker glibc static-linking






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Aug 13 at 11:10









pzelaskopzelasko

9646 silver badges23 bronze badges




9646 silver badges23 bronze badges










  • 2





    Ironic that CentOS's package repo is so outdated that it sometimes forces developers to link statically.

    – nada
    Aug 13 at 15:01












  • 2





    Ironic that CentOS's package repo is so outdated that it sometimes forces developers to link statically.

    – nada
    Aug 13 at 15:01







2




2





Ironic that CentOS's package repo is so outdated that it sometimes forces developers to link statically.

– nada
Aug 13 at 15:01





Ironic that CentOS's package repo is so outdated that it sometimes forces developers to link statically.

– nada
Aug 13 at 15:01












4 Answers
4






active

oldest

votes


















23















The reasons given in other answers are correct, but they are not the most important reason.



The most important reason why glibc should not be statically linked, is that it makes extensive internal use of dlopen, to load NSS (Name Service Switch) modules and iconv conversions. The modules themselves refer to C library functions. If the main program is dynamically linked with the C library, that's no problem. But if the main program is statically linked with the C library, dlopen has to go load a second copy of the C library to satisfy the modules' load requirements.



This means your "statically linked" program still needs a copy of libc.so.6 to be present on the file system, plus the NSS or iconv or whatever modules themselves, plus other dynamic libraries that the modules might need, like ld-linux.so.2, libresolv.so.2, etc. This is not what people usually want when they statically link programs.



It also means the statically linked program has two copies of the C library in its address space, and they might fight over whose stdout buffer is to be used, who gets to call sbrk with a nonzero argument, that sort of thing. There is a bunch of defensive logic inside glibc to try to make this work, but it's never been guaranteed to work.



You might think your program doesn't need to worry about this because it doesn't ever call getaddrinfo or iconv, but locale support uses iconv internally, which means any stdio.h function might trigger a call to dlopen, and you don't control this, the user's environment variable settings do.






share|improve this answer




















  • 3





    Note that the need for a second copy of glibc is a design decision. If the static glibc library had linked in NSS and iconv statically, it wouldn't have been necessary. The downside of course would be that you could only use those NSS modules and iconv conversions that were linked in statically, but that's pretty obvious from the definition of static linking.

    – MSalters
    Aug 13 at 13:52






  • 2





    @MSalters There has been some discussion recently on the glibc development list about doing just that. This design decision was made in the 1990s, and there's a strong argument that we don't need quite so much flexibility in character encoding for terminal output anymore, especially not in the kinds of programs that people want to link statically. NSS flexibility is still important but there are alternative ways to handle that (e.g. nscd).

    – zwol
    Aug 13 at 14:01











  • This is not quite right; I discovered that staticly linked C programs using stdio.h work with no libraries in /lib. The program I had to do this with was lilo.

    – Joshua
    Aug 13 at 20:13











  • @Joshua Did you try it with LANG set to a locale that requires use of an unusual character set?

    – zwol
    Aug 13 at 20:21











  • @zwol: It just switches to LANG=C if it can't load the library. This behavior is necessary for early boot.

    – Joshua
    Aug 13 at 20:23



















6















One of the reason is bug fixes and security patches. When you link statically the system updated glibc and other libraries don't benefit your application, your application stays vulnerable.






share|improve this answer






















  • 2





    And of course also the obvious: size of the executable.

    – Lundin
    Aug 13 at 11:16






  • 3





    @rustyx It is common knowledge. See, for example, en.wikipedia.org/wiki/Static_library

    – Maxim Egorushkin
    Aug 13 at 11:59






  • 10





    @MaximEgorushkin Not being resource-constrained is not an excuse to use more resources than you need to. This is the mindset that leads to Chrome being a multi-gigabyte RAM hog, and why Windows comes on 20,000 DVDs. Wouldn't it have been nice if, when computer resources got bigger, we could therefore run more things?!

    – Lightness Races in Orbit
    Aug 13 at 14:56






  • 2





    @nada Indeed, like An optimization applied to glibc changed the implementation of memcpy(), breaking a number of programs in the process.

    – Maxim Egorushkin
    Aug 13 at 15:12






  • 2





    @Lightness Races in Orbit Yeah, it's like Ward's Law -- the time take to boot a computer is independent of the speed of the computer. The amount of work done during bootup just expands to use the available cycles.

    – Badger
    Aug 13 at 23:33


















1















Bug fixes in glibc aren't included in a statically linked application when you upgrade glibc unless you rebuild the application.



Also, NSS (Name Service Switch) doesn't work unless you use dynamic linking.






share|improve this answer






















  • 1





    what do you mean by NSS?

    – pzelasko
    Aug 13 at 12:23











  • @pzelasko Name Service Switch.

    – JL2210
    Aug 13 at 14:53


















-1















The program/glibc interface is standardized and documented by POSIX, the C and C++ standards, and others. For example, the fopen() function behaves per the C standard, and pthread_mutex_lock() per POSIX.



The glibc/kernel interface is not standardized. Does fopen() use open() under the hood? Or does it use openat()? Or something else? What will it use next year? You don't know.



If the glibc/kernel interface changes, a program that uses whatever changed but statically links glibc won't work any more.



15+ years ago, Solaris removed all static versions of libc for this very reason.



Static Linking - where did it go?




With Solaris 10 you can no longer build a static executable. It's not that ld(1) doesn't allow static linking, or using archives, it's just that libc.a, the archive version of libc.so.1, is no longer provided. This library provides the interfaces between user land and the kernel, and without this library it is rather hard to create any form of application.



We've been warning users against static linking for some time now, and linking against libc.a has been especially problematic. Every solaris release, or update (even some patches) has resulted in some application that was built against libc.a, failing. The problem is that libc is supposed to isolate an application from the user/kernel boundary, a boundary which can undergo changes from release to release.



If an application is built against libc.a, then any kernel interface it references is extracted from the archive and becomes a part of the application. Thus, this application can only run on a kernel that is in-sync with the kernel interfaces used. Should these interfaces change, the application is treading on shaky ground.



...




Edit:



There seems to be serious overestimation of the stability of the Linux kernel interface. See Linux kernel API changes/additions for details. To summarize:



enter image description here






share|improve this answer






















  • 3





    yarchive.net/comp/linux/gcc_vs_kernel_stability.html: We care about user-space interfaces to an insane degree. We go to extreme lengths to maintain even badly designed or unintentional interfaces. Breaking user programs simply isn't acceptable.

    – Maxim Egorushkin
    Aug 13 at 11:37






  • 1





    @MaximEgorushkin Reality is different. The Linux ABI isn't very stable, to the point it's been mocked relatively recently: "It's not a secret that there are two basic ways of running a Linux distribution on your hardware. Either you use a stable distro which has quite an outdated kernel release which might not support your hardware or you run the most recent stable version but you lose stability and you are prone to regressions."

    – Andrew Henle
    Aug 13 at 11:46







  • 6





    The quote you cited is about in-kernel driver APIs, not the user-space API.

    – Maxim Egorushkin
    Aug 13 at 11:50







  • 2





    "The glibc interface is standardized. By POSIX. By the C standard. And others." the programming interface is, but the binary interface is not!

    – plugwash
    Aug 13 at 19:58






  • 1





    The kernel's binary interface is not standardised, but neither is glibc's binary interface.

    – plugwash
    Aug 13 at 20:18













Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f57476533%2fwhy-is-statically-linking-glibc-discouraged%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























4 Answers
4






active

oldest

votes








4 Answers
4






active

oldest

votes









active

oldest

votes






active

oldest

votes









23















The reasons given in other answers are correct, but they are not the most important reason.



The most important reason why glibc should not be statically linked, is that it makes extensive internal use of dlopen, to load NSS (Name Service Switch) modules and iconv conversions. The modules themselves refer to C library functions. If the main program is dynamically linked with the C library, that's no problem. But if the main program is statically linked with the C library, dlopen has to go load a second copy of the C library to satisfy the modules' load requirements.



This means your "statically linked" program still needs a copy of libc.so.6 to be present on the file system, plus the NSS or iconv or whatever modules themselves, plus other dynamic libraries that the modules might need, like ld-linux.so.2, libresolv.so.2, etc. This is not what people usually want when they statically link programs.



It also means the statically linked program has two copies of the C library in its address space, and they might fight over whose stdout buffer is to be used, who gets to call sbrk with a nonzero argument, that sort of thing. There is a bunch of defensive logic inside glibc to try to make this work, but it's never been guaranteed to work.



You might think your program doesn't need to worry about this because it doesn't ever call getaddrinfo or iconv, but locale support uses iconv internally, which means any stdio.h function might trigger a call to dlopen, and you don't control this, the user's environment variable settings do.






share|improve this answer




















  • 3





    Note that the need for a second copy of glibc is a design decision. If the static glibc library had linked in NSS and iconv statically, it wouldn't have been necessary. The downside of course would be that you could only use those NSS modules and iconv conversions that were linked in statically, but that's pretty obvious from the definition of static linking.

    – MSalters
    Aug 13 at 13:52






  • 2





    @MSalters There has been some discussion recently on the glibc development list about doing just that. This design decision was made in the 1990s, and there's a strong argument that we don't need quite so much flexibility in character encoding for terminal output anymore, especially not in the kinds of programs that people want to link statically. NSS flexibility is still important but there are alternative ways to handle that (e.g. nscd).

    – zwol
    Aug 13 at 14:01











  • This is not quite right; I discovered that staticly linked C programs using stdio.h work with no libraries in /lib. The program I had to do this with was lilo.

    – Joshua
    Aug 13 at 20:13











  • @Joshua Did you try it with LANG set to a locale that requires use of an unusual character set?

    – zwol
    Aug 13 at 20:21











  • @zwol: It just switches to LANG=C if it can't load the library. This behavior is necessary for early boot.

    – Joshua
    Aug 13 at 20:23
















23















The reasons given in other answers are correct, but they are not the most important reason.



The most important reason why glibc should not be statically linked, is that it makes extensive internal use of dlopen, to load NSS (Name Service Switch) modules and iconv conversions. The modules themselves refer to C library functions. If the main program is dynamically linked with the C library, that's no problem. But if the main program is statically linked with the C library, dlopen has to go load a second copy of the C library to satisfy the modules' load requirements.



This means your "statically linked" program still needs a copy of libc.so.6 to be present on the file system, plus the NSS or iconv or whatever modules themselves, plus other dynamic libraries that the modules might need, like ld-linux.so.2, libresolv.so.2, etc. This is not what people usually want when they statically link programs.



It also means the statically linked program has two copies of the C library in its address space, and they might fight over whose stdout buffer is to be used, who gets to call sbrk with a nonzero argument, that sort of thing. There is a bunch of defensive logic inside glibc to try to make this work, but it's never been guaranteed to work.



You might think your program doesn't need to worry about this because it doesn't ever call getaddrinfo or iconv, but locale support uses iconv internally, which means any stdio.h function might trigger a call to dlopen, and you don't control this, the user's environment variable settings do.






share|improve this answer




















  • 3





    Note that the need for a second copy of glibc is a design decision. If the static glibc library had linked in NSS and iconv statically, it wouldn't have been necessary. The downside of course would be that you could only use those NSS modules and iconv conversions that were linked in statically, but that's pretty obvious from the definition of static linking.

    – MSalters
    Aug 13 at 13:52






  • 2





    @MSalters There has been some discussion recently on the glibc development list about doing just that. This design decision was made in the 1990s, and there's a strong argument that we don't need quite so much flexibility in character encoding for terminal output anymore, especially not in the kinds of programs that people want to link statically. NSS flexibility is still important but there are alternative ways to handle that (e.g. nscd).

    – zwol
    Aug 13 at 14:01











  • This is not quite right; I discovered that staticly linked C programs using stdio.h work with no libraries in /lib. The program I had to do this with was lilo.

    – Joshua
    Aug 13 at 20:13











  • @Joshua Did you try it with LANG set to a locale that requires use of an unusual character set?

    – zwol
    Aug 13 at 20:21











  • @zwol: It just switches to LANG=C if it can't load the library. This behavior is necessary for early boot.

    – Joshua
    Aug 13 at 20:23














23














23










23









The reasons given in other answers are correct, but they are not the most important reason.



The most important reason why glibc should not be statically linked, is that it makes extensive internal use of dlopen, to load NSS (Name Service Switch) modules and iconv conversions. The modules themselves refer to C library functions. If the main program is dynamically linked with the C library, that's no problem. But if the main program is statically linked with the C library, dlopen has to go load a second copy of the C library to satisfy the modules' load requirements.



This means your "statically linked" program still needs a copy of libc.so.6 to be present on the file system, plus the NSS or iconv or whatever modules themselves, plus other dynamic libraries that the modules might need, like ld-linux.so.2, libresolv.so.2, etc. This is not what people usually want when they statically link programs.



It also means the statically linked program has two copies of the C library in its address space, and they might fight over whose stdout buffer is to be used, who gets to call sbrk with a nonzero argument, that sort of thing. There is a bunch of defensive logic inside glibc to try to make this work, but it's never been guaranteed to work.



You might think your program doesn't need to worry about this because it doesn't ever call getaddrinfo or iconv, but locale support uses iconv internally, which means any stdio.h function might trigger a call to dlopen, and you don't control this, the user's environment variable settings do.






share|improve this answer













The reasons given in other answers are correct, but they are not the most important reason.



The most important reason why glibc should not be statically linked, is that it makes extensive internal use of dlopen, to load NSS (Name Service Switch) modules and iconv conversions. The modules themselves refer to C library functions. If the main program is dynamically linked with the C library, that's no problem. But if the main program is statically linked with the C library, dlopen has to go load a second copy of the C library to satisfy the modules' load requirements.



This means your "statically linked" program still needs a copy of libc.so.6 to be present on the file system, plus the NSS or iconv or whatever modules themselves, plus other dynamic libraries that the modules might need, like ld-linux.so.2, libresolv.so.2, etc. This is not what people usually want when they statically link programs.



It also means the statically linked program has two copies of the C library in its address space, and they might fight over whose stdout buffer is to be used, who gets to call sbrk with a nonzero argument, that sort of thing. There is a bunch of defensive logic inside glibc to try to make this work, but it's never been guaranteed to work.



You might think your program doesn't need to worry about this because it doesn't ever call getaddrinfo or iconv, but locale support uses iconv internally, which means any stdio.h function might trigger a call to dlopen, and you don't control this, the user's environment variable settings do.







share|improve this answer












share|improve this answer



share|improve this answer










answered Aug 13 at 13:24









zwolzwol

104k27 gold badges183 silver badges285 bronze badges




104k27 gold badges183 silver badges285 bronze badges










  • 3





    Note that the need for a second copy of glibc is a design decision. If the static glibc library had linked in NSS and iconv statically, it wouldn't have been necessary. The downside of course would be that you could only use those NSS modules and iconv conversions that were linked in statically, but that's pretty obvious from the definition of static linking.

    – MSalters
    Aug 13 at 13:52






  • 2





    @MSalters There has been some discussion recently on the glibc development list about doing just that. This design decision was made in the 1990s, and there's a strong argument that we don't need quite so much flexibility in character encoding for terminal output anymore, especially not in the kinds of programs that people want to link statically. NSS flexibility is still important but there are alternative ways to handle that (e.g. nscd).

    – zwol
    Aug 13 at 14:01











  • This is not quite right; I discovered that staticly linked C programs using stdio.h work with no libraries in /lib. The program I had to do this with was lilo.

    – Joshua
    Aug 13 at 20:13











  • @Joshua Did you try it with LANG set to a locale that requires use of an unusual character set?

    – zwol
    Aug 13 at 20:21











  • @zwol: It just switches to LANG=C if it can't load the library. This behavior is necessary for early boot.

    – Joshua
    Aug 13 at 20:23













  • 3





    Note that the need for a second copy of glibc is a design decision. If the static glibc library had linked in NSS and iconv statically, it wouldn't have been necessary. The downside of course would be that you could only use those NSS modules and iconv conversions that were linked in statically, but that's pretty obvious from the definition of static linking.

    – MSalters
    Aug 13 at 13:52






  • 2





    @MSalters There has been some discussion recently on the glibc development list about doing just that. This design decision was made in the 1990s, and there's a strong argument that we don't need quite so much flexibility in character encoding for terminal output anymore, especially not in the kinds of programs that people want to link statically. NSS flexibility is still important but there are alternative ways to handle that (e.g. nscd).

    – zwol
    Aug 13 at 14:01











  • This is not quite right; I discovered that staticly linked C programs using stdio.h work with no libraries in /lib. The program I had to do this with was lilo.

    – Joshua
    Aug 13 at 20:13











  • @Joshua Did you try it with LANG set to a locale that requires use of an unusual character set?

    – zwol
    Aug 13 at 20:21











  • @zwol: It just switches to LANG=C if it can't load the library. This behavior is necessary for early boot.

    – Joshua
    Aug 13 at 20:23








3




3





Note that the need for a second copy of glibc is a design decision. If the static glibc library had linked in NSS and iconv statically, it wouldn't have been necessary. The downside of course would be that you could only use those NSS modules and iconv conversions that were linked in statically, but that's pretty obvious from the definition of static linking.

– MSalters
Aug 13 at 13:52





Note that the need for a second copy of glibc is a design decision. If the static glibc library had linked in NSS and iconv statically, it wouldn't have been necessary. The downside of course would be that you could only use those NSS modules and iconv conversions that were linked in statically, but that's pretty obvious from the definition of static linking.

– MSalters
Aug 13 at 13:52




2




2





@MSalters There has been some discussion recently on the glibc development list about doing just that. This design decision was made in the 1990s, and there's a strong argument that we don't need quite so much flexibility in character encoding for terminal output anymore, especially not in the kinds of programs that people want to link statically. NSS flexibility is still important but there are alternative ways to handle that (e.g. nscd).

– zwol
Aug 13 at 14:01





@MSalters There has been some discussion recently on the glibc development list about doing just that. This design decision was made in the 1990s, and there's a strong argument that we don't need quite so much flexibility in character encoding for terminal output anymore, especially not in the kinds of programs that people want to link statically. NSS flexibility is still important but there are alternative ways to handle that (e.g. nscd).

– zwol
Aug 13 at 14:01













This is not quite right; I discovered that staticly linked C programs using stdio.h work with no libraries in /lib. The program I had to do this with was lilo.

– Joshua
Aug 13 at 20:13





This is not quite right; I discovered that staticly linked C programs using stdio.h work with no libraries in /lib. The program I had to do this with was lilo.

– Joshua
Aug 13 at 20:13













@Joshua Did you try it with LANG set to a locale that requires use of an unusual character set?

– zwol
Aug 13 at 20:21





@Joshua Did you try it with LANG set to a locale that requires use of an unusual character set?

– zwol
Aug 13 at 20:21













@zwol: It just switches to LANG=C if it can't load the library. This behavior is necessary for early boot.

– Joshua
Aug 13 at 20:23






@zwol: It just switches to LANG=C if it can't load the library. This behavior is necessary for early boot.

– Joshua
Aug 13 at 20:23














6















One of the reason is bug fixes and security patches. When you link statically the system updated glibc and other libraries don't benefit your application, your application stays vulnerable.






share|improve this answer






















  • 2





    And of course also the obvious: size of the executable.

    – Lundin
    Aug 13 at 11:16






  • 3





    @rustyx It is common knowledge. See, for example, en.wikipedia.org/wiki/Static_library

    – Maxim Egorushkin
    Aug 13 at 11:59






  • 10





    @MaximEgorushkin Not being resource-constrained is not an excuse to use more resources than you need to. This is the mindset that leads to Chrome being a multi-gigabyte RAM hog, and why Windows comes on 20,000 DVDs. Wouldn't it have been nice if, when computer resources got bigger, we could therefore run more things?!

    – Lightness Races in Orbit
    Aug 13 at 14:56






  • 2





    @nada Indeed, like An optimization applied to glibc changed the implementation of memcpy(), breaking a number of programs in the process.

    – Maxim Egorushkin
    Aug 13 at 15:12






  • 2





    @Lightness Races in Orbit Yeah, it's like Ward's Law -- the time take to boot a computer is independent of the speed of the computer. The amount of work done during bootup just expands to use the available cycles.

    – Badger
    Aug 13 at 23:33















6















One of the reason is bug fixes and security patches. When you link statically the system updated glibc and other libraries don't benefit your application, your application stays vulnerable.






share|improve this answer






















  • 2





    And of course also the obvious: size of the executable.

    – Lundin
    Aug 13 at 11:16






  • 3





    @rustyx It is common knowledge. See, for example, en.wikipedia.org/wiki/Static_library

    – Maxim Egorushkin
    Aug 13 at 11:59






  • 10





    @MaximEgorushkin Not being resource-constrained is not an excuse to use more resources than you need to. This is the mindset that leads to Chrome being a multi-gigabyte RAM hog, and why Windows comes on 20,000 DVDs. Wouldn't it have been nice if, when computer resources got bigger, we could therefore run more things?!

    – Lightness Races in Orbit
    Aug 13 at 14:56






  • 2





    @nada Indeed, like An optimization applied to glibc changed the implementation of memcpy(), breaking a number of programs in the process.

    – Maxim Egorushkin
    Aug 13 at 15:12






  • 2





    @Lightness Races in Orbit Yeah, it's like Ward's Law -- the time take to boot a computer is independent of the speed of the computer. The amount of work done during bootup just expands to use the available cycles.

    – Badger
    Aug 13 at 23:33













6














6










6









One of the reason is bug fixes and security patches. When you link statically the system updated glibc and other libraries don't benefit your application, your application stays vulnerable.






share|improve this answer















One of the reason is bug fixes and security patches. When you link statically the system updated glibc and other libraries don't benefit your application, your application stays vulnerable.







share|improve this answer














share|improve this answer



share|improve this answer








edited Aug 13 at 22:21

























answered Aug 13 at 11:15









Maxim EgorushkinMaxim Egorushkin

96.1k11 gold badges110 silver badges203 bronze badges




96.1k11 gold badges110 silver badges203 bronze badges










  • 2





    And of course also the obvious: size of the executable.

    – Lundin
    Aug 13 at 11:16






  • 3





    @rustyx It is common knowledge. See, for example, en.wikipedia.org/wiki/Static_library

    – Maxim Egorushkin
    Aug 13 at 11:59






  • 10





    @MaximEgorushkin Not being resource-constrained is not an excuse to use more resources than you need to. This is the mindset that leads to Chrome being a multi-gigabyte RAM hog, and why Windows comes on 20,000 DVDs. Wouldn't it have been nice if, when computer resources got bigger, we could therefore run more things?!

    – Lightness Races in Orbit
    Aug 13 at 14:56






  • 2





    @nada Indeed, like An optimization applied to glibc changed the implementation of memcpy(), breaking a number of programs in the process.

    – Maxim Egorushkin
    Aug 13 at 15:12






  • 2





    @Lightness Races in Orbit Yeah, it's like Ward's Law -- the time take to boot a computer is independent of the speed of the computer. The amount of work done during bootup just expands to use the available cycles.

    – Badger
    Aug 13 at 23:33












  • 2





    And of course also the obvious: size of the executable.

    – Lundin
    Aug 13 at 11:16






  • 3





    @rustyx It is common knowledge. See, for example, en.wikipedia.org/wiki/Static_library

    – Maxim Egorushkin
    Aug 13 at 11:59






  • 10





    @MaximEgorushkin Not being resource-constrained is not an excuse to use more resources than you need to. This is the mindset that leads to Chrome being a multi-gigabyte RAM hog, and why Windows comes on 20,000 DVDs. Wouldn't it have been nice if, when computer resources got bigger, we could therefore run more things?!

    – Lightness Races in Orbit
    Aug 13 at 14:56






  • 2





    @nada Indeed, like An optimization applied to glibc changed the implementation of memcpy(), breaking a number of programs in the process.

    – Maxim Egorushkin
    Aug 13 at 15:12






  • 2





    @Lightness Races in Orbit Yeah, it's like Ward's Law -- the time take to boot a computer is independent of the speed of the computer. The amount of work done during bootup just expands to use the available cycles.

    – Badger
    Aug 13 at 23:33







2




2





And of course also the obvious: size of the executable.

– Lundin
Aug 13 at 11:16





And of course also the obvious: size of the executable.

– Lundin
Aug 13 at 11:16




3




3





@rustyx It is common knowledge. See, for example, en.wikipedia.org/wiki/Static_library

– Maxim Egorushkin
Aug 13 at 11:59





@rustyx It is common knowledge. See, for example, en.wikipedia.org/wiki/Static_library

– Maxim Egorushkin
Aug 13 at 11:59




10




10





@MaximEgorushkin Not being resource-constrained is not an excuse to use more resources than you need to. This is the mindset that leads to Chrome being a multi-gigabyte RAM hog, and why Windows comes on 20,000 DVDs. Wouldn't it have been nice if, when computer resources got bigger, we could therefore run more things?!

– Lightness Races in Orbit
Aug 13 at 14:56





@MaximEgorushkin Not being resource-constrained is not an excuse to use more resources than you need to. This is the mindset that leads to Chrome being a multi-gigabyte RAM hog, and why Windows comes on 20,000 DVDs. Wouldn't it have been nice if, when computer resources got bigger, we could therefore run more things?!

– Lightness Races in Orbit
Aug 13 at 14:56




2




2





@nada Indeed, like An optimization applied to glibc changed the implementation of memcpy(), breaking a number of programs in the process.

– Maxim Egorushkin
Aug 13 at 15:12





@nada Indeed, like An optimization applied to glibc changed the implementation of memcpy(), breaking a number of programs in the process.

– Maxim Egorushkin
Aug 13 at 15:12




2




2





@Lightness Races in Orbit Yeah, it's like Ward's Law -- the time take to boot a computer is independent of the speed of the computer. The amount of work done during bootup just expands to use the available cycles.

– Badger
Aug 13 at 23:33





@Lightness Races in Orbit Yeah, it's like Ward's Law -- the time take to boot a computer is independent of the speed of the computer. The amount of work done during bootup just expands to use the available cycles.

– Badger
Aug 13 at 23:33











1















Bug fixes in glibc aren't included in a statically linked application when you upgrade glibc unless you rebuild the application.



Also, NSS (Name Service Switch) doesn't work unless you use dynamic linking.






share|improve this answer






















  • 1





    what do you mean by NSS?

    – pzelasko
    Aug 13 at 12:23











  • @pzelasko Name Service Switch.

    – JL2210
    Aug 13 at 14:53















1















Bug fixes in glibc aren't included in a statically linked application when you upgrade glibc unless you rebuild the application.



Also, NSS (Name Service Switch) doesn't work unless you use dynamic linking.






share|improve this answer






















  • 1





    what do you mean by NSS?

    – pzelasko
    Aug 13 at 12:23











  • @pzelasko Name Service Switch.

    – JL2210
    Aug 13 at 14:53













1














1










1









Bug fixes in glibc aren't included in a statically linked application when you upgrade glibc unless you rebuild the application.



Also, NSS (Name Service Switch) doesn't work unless you use dynamic linking.






share|improve this answer















Bug fixes in glibc aren't included in a statically linked application when you upgrade glibc unless you rebuild the application.



Also, NSS (Name Service Switch) doesn't work unless you use dynamic linking.







share|improve this answer














share|improve this answer



share|improve this answer








edited Aug 13 at 14:53

























answered Aug 13 at 11:50









JL2210JL2210

3,1283 gold badges12 silver badges38 bronze badges




3,1283 gold badges12 silver badges38 bronze badges










  • 1





    what do you mean by NSS?

    – pzelasko
    Aug 13 at 12:23











  • @pzelasko Name Service Switch.

    – JL2210
    Aug 13 at 14:53












  • 1





    what do you mean by NSS?

    – pzelasko
    Aug 13 at 12:23











  • @pzelasko Name Service Switch.

    – JL2210
    Aug 13 at 14:53







1




1





what do you mean by NSS?

– pzelasko
Aug 13 at 12:23





what do you mean by NSS?

– pzelasko
Aug 13 at 12:23













@pzelasko Name Service Switch.

– JL2210
Aug 13 at 14:53





@pzelasko Name Service Switch.

– JL2210
Aug 13 at 14:53











-1















The program/glibc interface is standardized and documented by POSIX, the C and C++ standards, and others. For example, the fopen() function behaves per the C standard, and pthread_mutex_lock() per POSIX.



The glibc/kernel interface is not standardized. Does fopen() use open() under the hood? Or does it use openat()? Or something else? What will it use next year? You don't know.



If the glibc/kernel interface changes, a program that uses whatever changed but statically links glibc won't work any more.



15+ years ago, Solaris removed all static versions of libc for this very reason.



Static Linking - where did it go?




With Solaris 10 you can no longer build a static executable. It's not that ld(1) doesn't allow static linking, or using archives, it's just that libc.a, the archive version of libc.so.1, is no longer provided. This library provides the interfaces between user land and the kernel, and without this library it is rather hard to create any form of application.



We've been warning users against static linking for some time now, and linking against libc.a has been especially problematic. Every solaris release, or update (even some patches) has resulted in some application that was built against libc.a, failing. The problem is that libc is supposed to isolate an application from the user/kernel boundary, a boundary which can undergo changes from release to release.



If an application is built against libc.a, then any kernel interface it references is extracted from the archive and becomes a part of the application. Thus, this application can only run on a kernel that is in-sync with the kernel interfaces used. Should these interfaces change, the application is treading on shaky ground.



...




Edit:



There seems to be serious overestimation of the stability of the Linux kernel interface. See Linux kernel API changes/additions for details. To summarize:



enter image description here






share|improve this answer






















  • 3





    yarchive.net/comp/linux/gcc_vs_kernel_stability.html: We care about user-space interfaces to an insane degree. We go to extreme lengths to maintain even badly designed or unintentional interfaces. Breaking user programs simply isn't acceptable.

    – Maxim Egorushkin
    Aug 13 at 11:37






  • 1





    @MaximEgorushkin Reality is different. The Linux ABI isn't very stable, to the point it's been mocked relatively recently: "It's not a secret that there are two basic ways of running a Linux distribution on your hardware. Either you use a stable distro which has quite an outdated kernel release which might not support your hardware or you run the most recent stable version but you lose stability and you are prone to regressions."

    – Andrew Henle
    Aug 13 at 11:46







  • 6





    The quote you cited is about in-kernel driver APIs, not the user-space API.

    – Maxim Egorushkin
    Aug 13 at 11:50







  • 2





    "The glibc interface is standardized. By POSIX. By the C standard. And others." the programming interface is, but the binary interface is not!

    – plugwash
    Aug 13 at 19:58






  • 1





    The kernel's binary interface is not standardised, but neither is glibc's binary interface.

    – plugwash
    Aug 13 at 20:18















-1















The program/glibc interface is standardized and documented by POSIX, the C and C++ standards, and others. For example, the fopen() function behaves per the C standard, and pthread_mutex_lock() per POSIX.



The glibc/kernel interface is not standardized. Does fopen() use open() under the hood? Or does it use openat()? Or something else? What will it use next year? You don't know.



If the glibc/kernel interface changes, a program that uses whatever changed but statically links glibc won't work any more.



15+ years ago, Solaris removed all static versions of libc for this very reason.



Static Linking - where did it go?




With Solaris 10 you can no longer build a static executable. It's not that ld(1) doesn't allow static linking, or using archives, it's just that libc.a, the archive version of libc.so.1, is no longer provided. This library provides the interfaces between user land and the kernel, and without this library it is rather hard to create any form of application.



We've been warning users against static linking for some time now, and linking against libc.a has been especially problematic. Every solaris release, or update (even some patches) has resulted in some application that was built against libc.a, failing. The problem is that libc is supposed to isolate an application from the user/kernel boundary, a boundary which can undergo changes from release to release.



If an application is built against libc.a, then any kernel interface it references is extracted from the archive and becomes a part of the application. Thus, this application can only run on a kernel that is in-sync with the kernel interfaces used. Should these interfaces change, the application is treading on shaky ground.



...




Edit:



There seems to be serious overestimation of the stability of the Linux kernel interface. See Linux kernel API changes/additions for details. To summarize:



enter image description here






share|improve this answer






















  • 3





    yarchive.net/comp/linux/gcc_vs_kernel_stability.html: We care about user-space interfaces to an insane degree. We go to extreme lengths to maintain even badly designed or unintentional interfaces. Breaking user programs simply isn't acceptable.

    – Maxim Egorushkin
    Aug 13 at 11:37






  • 1





    @MaximEgorushkin Reality is different. The Linux ABI isn't very stable, to the point it's been mocked relatively recently: "It's not a secret that there are two basic ways of running a Linux distribution on your hardware. Either you use a stable distro which has quite an outdated kernel release which might not support your hardware or you run the most recent stable version but you lose stability and you are prone to regressions."

    – Andrew Henle
    Aug 13 at 11:46







  • 6





    The quote you cited is about in-kernel driver APIs, not the user-space API.

    – Maxim Egorushkin
    Aug 13 at 11:50







  • 2





    "The glibc interface is standardized. By POSIX. By the C standard. And others." the programming interface is, but the binary interface is not!

    – plugwash
    Aug 13 at 19:58






  • 1





    The kernel's binary interface is not standardised, but neither is glibc's binary interface.

    – plugwash
    Aug 13 at 20:18













-1














-1










-1









The program/glibc interface is standardized and documented by POSIX, the C and C++ standards, and others. For example, the fopen() function behaves per the C standard, and pthread_mutex_lock() per POSIX.



The glibc/kernel interface is not standardized. Does fopen() use open() under the hood? Or does it use openat()? Or something else? What will it use next year? You don't know.



If the glibc/kernel interface changes, a program that uses whatever changed but statically links glibc won't work any more.



15+ years ago, Solaris removed all static versions of libc for this very reason.



Static Linking - where did it go?




With Solaris 10 you can no longer build a static executable. It's not that ld(1) doesn't allow static linking, or using archives, it's just that libc.a, the archive version of libc.so.1, is no longer provided. This library provides the interfaces between user land and the kernel, and without this library it is rather hard to create any form of application.



We've been warning users against static linking for some time now, and linking against libc.a has been especially problematic. Every solaris release, or update (even some patches) has resulted in some application that was built against libc.a, failing. The problem is that libc is supposed to isolate an application from the user/kernel boundary, a boundary which can undergo changes from release to release.



If an application is built against libc.a, then any kernel interface it references is extracted from the archive and becomes a part of the application. Thus, this application can only run on a kernel that is in-sync with the kernel interfaces used. Should these interfaces change, the application is treading on shaky ground.



...




Edit:



There seems to be serious overestimation of the stability of the Linux kernel interface. See Linux kernel API changes/additions for details. To summarize:



enter image description here






share|improve this answer















The program/glibc interface is standardized and documented by POSIX, the C and C++ standards, and others. For example, the fopen() function behaves per the C standard, and pthread_mutex_lock() per POSIX.



The glibc/kernel interface is not standardized. Does fopen() use open() under the hood? Or does it use openat()? Or something else? What will it use next year? You don't know.



If the glibc/kernel interface changes, a program that uses whatever changed but statically links glibc won't work any more.



15+ years ago, Solaris removed all static versions of libc for this very reason.



Static Linking - where did it go?




With Solaris 10 you can no longer build a static executable. It's not that ld(1) doesn't allow static linking, or using archives, it's just that libc.a, the archive version of libc.so.1, is no longer provided. This library provides the interfaces between user land and the kernel, and without this library it is rather hard to create any form of application.



We've been warning users against static linking for some time now, and linking against libc.a has been especially problematic. Every solaris release, or update (even some patches) has resulted in some application that was built against libc.a, failing. The problem is that libc is supposed to isolate an application from the user/kernel boundary, a boundary which can undergo changes from release to release.



If an application is built against libc.a, then any kernel interface it references is extracted from the archive and becomes a part of the application. Thus, this application can only run on a kernel that is in-sync with the kernel interfaces used. Should these interfaces change, the application is treading on shaky ground.



...




Edit:



There seems to be serious overestimation of the stability of the Linux kernel interface. See Linux kernel API changes/additions for details. To summarize:



enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited Aug 14 at 10:03

























answered Aug 13 at 11:24









Andrew HenleAndrew Henle

22k3 gold badges15 silver badges37 bronze badges




22k3 gold badges15 silver badges37 bronze badges










  • 3





    yarchive.net/comp/linux/gcc_vs_kernel_stability.html: We care about user-space interfaces to an insane degree. We go to extreme lengths to maintain even badly designed or unintentional interfaces. Breaking user programs simply isn't acceptable.

    – Maxim Egorushkin
    Aug 13 at 11:37






  • 1





    @MaximEgorushkin Reality is different. The Linux ABI isn't very stable, to the point it's been mocked relatively recently: "It's not a secret that there are two basic ways of running a Linux distribution on your hardware. Either you use a stable distro which has quite an outdated kernel release which might not support your hardware or you run the most recent stable version but you lose stability and you are prone to regressions."

    – Andrew Henle
    Aug 13 at 11:46







  • 6





    The quote you cited is about in-kernel driver APIs, not the user-space API.

    – Maxim Egorushkin
    Aug 13 at 11:50







  • 2





    "The glibc interface is standardized. By POSIX. By the C standard. And others." the programming interface is, but the binary interface is not!

    – plugwash
    Aug 13 at 19:58






  • 1





    The kernel's binary interface is not standardised, but neither is glibc's binary interface.

    – plugwash
    Aug 13 at 20:18












  • 3





    yarchive.net/comp/linux/gcc_vs_kernel_stability.html: We care about user-space interfaces to an insane degree. We go to extreme lengths to maintain even badly designed or unintentional interfaces. Breaking user programs simply isn't acceptable.

    – Maxim Egorushkin
    Aug 13 at 11:37






  • 1





    @MaximEgorushkin Reality is different. The Linux ABI isn't very stable, to the point it's been mocked relatively recently: "It's not a secret that there are two basic ways of running a Linux distribution on your hardware. Either you use a stable distro which has quite an outdated kernel release which might not support your hardware or you run the most recent stable version but you lose stability and you are prone to regressions."

    – Andrew Henle
    Aug 13 at 11:46







  • 6





    The quote you cited is about in-kernel driver APIs, not the user-space API.

    – Maxim Egorushkin
    Aug 13 at 11:50







  • 2





    "The glibc interface is standardized. By POSIX. By the C standard. And others." the programming interface is, but the binary interface is not!

    – plugwash
    Aug 13 at 19:58






  • 1





    The kernel's binary interface is not standardised, but neither is glibc's binary interface.

    – plugwash
    Aug 13 at 20:18







3




3





yarchive.net/comp/linux/gcc_vs_kernel_stability.html: We care about user-space interfaces to an insane degree. We go to extreme lengths to maintain even badly designed or unintentional interfaces. Breaking user programs simply isn't acceptable.

– Maxim Egorushkin
Aug 13 at 11:37





yarchive.net/comp/linux/gcc_vs_kernel_stability.html: We care about user-space interfaces to an insane degree. We go to extreme lengths to maintain even badly designed or unintentional interfaces. Breaking user programs simply isn't acceptable.

– Maxim Egorushkin
Aug 13 at 11:37




1




1





@MaximEgorushkin Reality is different. The Linux ABI isn't very stable, to the point it's been mocked relatively recently: "It's not a secret that there are two basic ways of running a Linux distribution on your hardware. Either you use a stable distro which has quite an outdated kernel release which might not support your hardware or you run the most recent stable version but you lose stability and you are prone to regressions."

– Andrew Henle
Aug 13 at 11:46






@MaximEgorushkin Reality is different. The Linux ABI isn't very stable, to the point it's been mocked relatively recently: "It's not a secret that there are two basic ways of running a Linux distribution on your hardware. Either you use a stable distro which has quite an outdated kernel release which might not support your hardware or you run the most recent stable version but you lose stability and you are prone to regressions."

– Andrew Henle
Aug 13 at 11:46





6




6





The quote you cited is about in-kernel driver APIs, not the user-space API.

– Maxim Egorushkin
Aug 13 at 11:50






The quote you cited is about in-kernel driver APIs, not the user-space API.

– Maxim Egorushkin
Aug 13 at 11:50





2




2





"The glibc interface is standardized. By POSIX. By the C standard. And others." the programming interface is, but the binary interface is not!

– plugwash
Aug 13 at 19:58





"The glibc interface is standardized. By POSIX. By the C standard. And others." the programming interface is, but the binary interface is not!

– plugwash
Aug 13 at 19:58




1




1





The kernel's binary interface is not standardised, but neither is glibc's binary interface.

– plugwash
Aug 13 at 20:18





The kernel's binary interface is not standardised, but neither is glibc's binary interface.

– plugwash
Aug 13 at 20:18

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f57476533%2fwhy-is-statically-linking-glibc-discouraged%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?