Static linking libc, possible or not, recommended or not?2019 Community Moderator ElectionIs the Solaris libc based on the GNU libc?Determine libc version used to create static libraryRun a program with a newer libcSpecifying local libc does call global libc?Find out glibc compilation optionsLocally-installing glibc-2.23 causes all programs to segfaultRunning C++11 library with older libcIs it possible to recover from corrupted libc on Redhat?Different function offset for same libc versionupgrading GNU libc (Debian Sid)
How to pass a string to a command that expects a file?
Replacing Windows 7 security updates with 3rd party alternatives?
Are babies of evil humanoid species inherently evil?
What Happens when Passenger Refuses to Fly Boeing 737 Max?
Examples of a statistic that is not independent of sample's distribution?
Is it true that real estate prices mainly go up?
Numbering Question Help Me!
Word for a person who has no opinion about whether god exists
Offered promotion but I'm leaving. Should I tell?
Do I really need to have a scientific explanation for my premise?
Are there historical instances of the capital of a colonising country being temporarily or permanently shifted to one of its colonies?
Reverse string, can I make it faster?
PTIJ: where are Tzafra and Urta located?
2000s TV show: people stuck in primitive other world, bit of magic and bit of dinosaurs
Finding algorithms of QGIS commands?
Is there any way to click on 6th item of this list
Set and print content of environment variable in cmd.exe subshell?
How did Alan Turing break the enigma code using the hint given by the lady in the bar?
Is there an equal sign with wider gap?
Virginia employer terminated employee and wants signing bonus returned
infinitive telling the purpose
Is Gradient Descent central to every optimizer?
How strictly should I take "Candidates must be local"?
What may be happening here?
Static linking libc, possible or not, recommended or not?
2019 Community Moderator ElectionIs the Solaris libc based on the GNU libc?Determine libc version used to create static libraryRun a program with a newer libcSpecifying local libc does call global libc?Find out glibc compilation optionsLocally-installing glibc-2.23 causes all programs to segfaultRunning C++11 library with older libcIs it possible to recover from corrupted libc on Redhat?Different function offset for same libc versionupgrading GNU libc (Debian Sid)
I see this line in my binary:
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
Shouldn't I rather get rid of it? Actually more confusingly, why is it there in the first place, I feel like gcc by default compiling things that only run on the host machine is a bit crazy.
Isnt it super dangerous to just depend on some random libc that may or may not be on the machine that I'll eventually copy paste this binary to? I dont get it.
On Windows I think I'd get some kind of "missing runtime" error that is versioned to the exact runtime that I compiled it with, so if I compiled on XP with a certain compiler then any host machine has to have that runtime installed too.
But on Linux I've never heard of such a case, or is there a directory of 50 different libc.so somewhere and the right one gets linked when my application is trying to start up? Because I sort of have a feeling that .dll hell exists for real on Linux and this isn't actually the case.
linux glibc
add a comment |
I see this line in my binary:
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
Shouldn't I rather get rid of it? Actually more confusingly, why is it there in the first place, I feel like gcc by default compiling things that only run on the host machine is a bit crazy.
Isnt it super dangerous to just depend on some random libc that may or may not be on the machine that I'll eventually copy paste this binary to? I dont get it.
On Windows I think I'd get some kind of "missing runtime" error that is versioned to the exact runtime that I compiled it with, so if I compiled on XP with a certain compiler then any host machine has to have that runtime installed too.
But on Linux I've never heard of such a case, or is there a directory of 50 different libc.so somewhere and the right one gets linked when my application is trying to start up? Because I sort of have a feeling that .dll hell exists for real on Linux and this isn't actually the case.
linux glibc
You can read this for some intro link
– Tryna Learn Somethin
1 hour ago
that answers nothing about versioning and so on, I'm not asking some basic question ala 'what is the libc'. I'm asking exactly why there is such hard coupling and whether this can result in silent runtime problems as I suspect it can if I run the executable on a machine that has an incompatible libc
– Blub
1 hour ago
If you use some function from libc in your code. The fucntion parameters etc will be the same accross different version of libc. The only thing that is different is implementation of those function inside of libc which generally shouldn't be of interest to you
– Tryna Learn Somethin
1 hour ago
add a comment |
I see this line in my binary:
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
Shouldn't I rather get rid of it? Actually more confusingly, why is it there in the first place, I feel like gcc by default compiling things that only run on the host machine is a bit crazy.
Isnt it super dangerous to just depend on some random libc that may or may not be on the machine that I'll eventually copy paste this binary to? I dont get it.
On Windows I think I'd get some kind of "missing runtime" error that is versioned to the exact runtime that I compiled it with, so if I compiled on XP with a certain compiler then any host machine has to have that runtime installed too.
But on Linux I've never heard of such a case, or is there a directory of 50 different libc.so somewhere and the right one gets linked when my application is trying to start up? Because I sort of have a feeling that .dll hell exists for real on Linux and this isn't actually the case.
linux glibc
I see this line in my binary:
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
Shouldn't I rather get rid of it? Actually more confusingly, why is it there in the first place, I feel like gcc by default compiling things that only run on the host machine is a bit crazy.
Isnt it super dangerous to just depend on some random libc that may or may not be on the machine that I'll eventually copy paste this binary to? I dont get it.
On Windows I think I'd get some kind of "missing runtime" error that is versioned to the exact runtime that I compiled it with, so if I compiled on XP with a certain compiler then any host machine has to have that runtime installed too.
But on Linux I've never heard of such a case, or is there a directory of 50 different libc.so somewhere and the right one gets linked when my application is trying to start up? Because I sort of have a feeling that .dll hell exists for real on Linux and this isn't actually the case.
linux glibc
linux glibc
asked 1 hour ago
BlubBlub
1134
1134
You can read this for some intro link
– Tryna Learn Somethin
1 hour ago
that answers nothing about versioning and so on, I'm not asking some basic question ala 'what is the libc'. I'm asking exactly why there is such hard coupling and whether this can result in silent runtime problems as I suspect it can if I run the executable on a machine that has an incompatible libc
– Blub
1 hour ago
If you use some function from libc in your code. The fucntion parameters etc will be the same accross different version of libc. The only thing that is different is implementation of those function inside of libc which generally shouldn't be of interest to you
– Tryna Learn Somethin
1 hour ago
add a comment |
You can read this for some intro link
– Tryna Learn Somethin
1 hour ago
that answers nothing about versioning and so on, I'm not asking some basic question ala 'what is the libc'. I'm asking exactly why there is such hard coupling and whether this can result in silent runtime problems as I suspect it can if I run the executable on a machine that has an incompatible libc
– Blub
1 hour ago
If you use some function from libc in your code. The fucntion parameters etc will be the same accross different version of libc. The only thing that is different is implementation of those function inside of libc which generally shouldn't be of interest to you
– Tryna Learn Somethin
1 hour ago
You can read this for some intro link
– Tryna Learn Somethin
1 hour ago
You can read this for some intro link
– Tryna Learn Somethin
1 hour ago
that answers nothing about versioning and so on, I'm not asking some basic question ala 'what is the libc'. I'm asking exactly why there is such hard coupling and whether this can result in silent runtime problems as I suspect it can if I run the executable on a machine that has an incompatible libc
– Blub
1 hour ago
that answers nothing about versioning and so on, I'm not asking some basic question ala 'what is the libc'. I'm asking exactly why there is such hard coupling and whether this can result in silent runtime problems as I suspect it can if I run the executable on a machine that has an incompatible libc
– Blub
1 hour ago
If you use some function from libc in your code. The fucntion parameters etc will be the same accross different version of libc. The only thing that is different is implementation of those function inside of libc which generally shouldn't be of interest to you
– Tryna Learn Somethin
1 hour ago
If you use some function from libc in your code. The fucntion parameters etc will be the same accross different version of libc. The only thing that is different is implementation of those function inside of libc which generally shouldn't be of interest to you
– Tryna Learn Somethin
1 hour ago
add a comment |
1 Answer
1
active
oldest
votes
At least with the GNU C library, linking carries version information for every single symbol (function etc.) that’s used. You can see this with objdump -T; for example, on /bin/ls, I get
DYNAMIC SYMBOL TABLE:
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.3 __ctype_toupper_loc
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 __uflow
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 getenv
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 sigprocmask
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.3.4 __snprintf_chk
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 raise
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 free
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 abort
etc.
The C library developers go to great lengths to ensure that the C library remains backwards compatible. The above output means that ls needs __ctype_toupper_loc from version 2.3 or later of the C library, etc. Any C library which provides all the required symbols will be able to run a given binary; and any given version of the GNU C library provides implementations of all the symbols which have ever been provided by an older version of the C library (going back to 1997).
Another way of handling things, used by most libraries on Linux-based systems (in fact, ELF-based systems and others), is the soname. Each library defines not only its name, but a version number, which is changed whenever breaking changes are introduced (in some cases, more often). Multiple versions of libraries, with different sonames, can be installed in parallel; for example
-rw-r--r-- 1 root root 2500416 Dec 16 21:07 libcrypto.so.1.0.2
-rw-r--r-- 1 root root 2711616 Nov 28 23:43 libcrypto.so.1.1
(This is also used by the C library, as evidenced by the dependency name, libc.so.6 — but the last GNU C library soname bump occurred many years ago.)
To address the question in your title, it is possible to statically link the C library, but it’s rarely necessary or useful (and can be confusing since some parts of the C library are dynamically linked even when the C library is statically linked). It can be useful to link other libraries statically. Other languages use different approaches, and for example Go programs are statically linked.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f505868%2fstatic-linking-libc-possible-or-not-recommended-or-not%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
At least with the GNU C library, linking carries version information for every single symbol (function etc.) that’s used. You can see this with objdump -T; for example, on /bin/ls, I get
DYNAMIC SYMBOL TABLE:
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.3 __ctype_toupper_loc
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 __uflow
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 getenv
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 sigprocmask
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.3.4 __snprintf_chk
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 raise
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 free
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 abort
etc.
The C library developers go to great lengths to ensure that the C library remains backwards compatible. The above output means that ls needs __ctype_toupper_loc from version 2.3 or later of the C library, etc. Any C library which provides all the required symbols will be able to run a given binary; and any given version of the GNU C library provides implementations of all the symbols which have ever been provided by an older version of the C library (going back to 1997).
Another way of handling things, used by most libraries on Linux-based systems (in fact, ELF-based systems and others), is the soname. Each library defines not only its name, but a version number, which is changed whenever breaking changes are introduced (in some cases, more often). Multiple versions of libraries, with different sonames, can be installed in parallel; for example
-rw-r--r-- 1 root root 2500416 Dec 16 21:07 libcrypto.so.1.0.2
-rw-r--r-- 1 root root 2711616 Nov 28 23:43 libcrypto.so.1.1
(This is also used by the C library, as evidenced by the dependency name, libc.so.6 — but the last GNU C library soname bump occurred many years ago.)
To address the question in your title, it is possible to statically link the C library, but it’s rarely necessary or useful (and can be confusing since some parts of the C library are dynamically linked even when the C library is statically linked). It can be useful to link other libraries statically. Other languages use different approaches, and for example Go programs are statically linked.
add a comment |
At least with the GNU C library, linking carries version information for every single symbol (function etc.) that’s used. You can see this with objdump -T; for example, on /bin/ls, I get
DYNAMIC SYMBOL TABLE:
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.3 __ctype_toupper_loc
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 __uflow
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 getenv
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 sigprocmask
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.3.4 __snprintf_chk
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 raise
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 free
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 abort
etc.
The C library developers go to great lengths to ensure that the C library remains backwards compatible. The above output means that ls needs __ctype_toupper_loc from version 2.3 or later of the C library, etc. Any C library which provides all the required symbols will be able to run a given binary; and any given version of the GNU C library provides implementations of all the symbols which have ever been provided by an older version of the C library (going back to 1997).
Another way of handling things, used by most libraries on Linux-based systems (in fact, ELF-based systems and others), is the soname. Each library defines not only its name, but a version number, which is changed whenever breaking changes are introduced (in some cases, more often). Multiple versions of libraries, with different sonames, can be installed in parallel; for example
-rw-r--r-- 1 root root 2500416 Dec 16 21:07 libcrypto.so.1.0.2
-rw-r--r-- 1 root root 2711616 Nov 28 23:43 libcrypto.so.1.1
(This is also used by the C library, as evidenced by the dependency name, libc.so.6 — but the last GNU C library soname bump occurred many years ago.)
To address the question in your title, it is possible to statically link the C library, but it’s rarely necessary or useful (and can be confusing since some parts of the C library are dynamically linked even when the C library is statically linked). It can be useful to link other libraries statically. Other languages use different approaches, and for example Go programs are statically linked.
add a comment |
At least with the GNU C library, linking carries version information for every single symbol (function etc.) that’s used. You can see this with objdump -T; for example, on /bin/ls, I get
DYNAMIC SYMBOL TABLE:
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.3 __ctype_toupper_loc
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 __uflow
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 getenv
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 sigprocmask
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.3.4 __snprintf_chk
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 raise
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 free
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 abort
etc.
The C library developers go to great lengths to ensure that the C library remains backwards compatible. The above output means that ls needs __ctype_toupper_loc from version 2.3 or later of the C library, etc. Any C library which provides all the required symbols will be able to run a given binary; and any given version of the GNU C library provides implementations of all the symbols which have ever been provided by an older version of the C library (going back to 1997).
Another way of handling things, used by most libraries on Linux-based systems (in fact, ELF-based systems and others), is the soname. Each library defines not only its name, but a version number, which is changed whenever breaking changes are introduced (in some cases, more often). Multiple versions of libraries, with different sonames, can be installed in parallel; for example
-rw-r--r-- 1 root root 2500416 Dec 16 21:07 libcrypto.so.1.0.2
-rw-r--r-- 1 root root 2711616 Nov 28 23:43 libcrypto.so.1.1
(This is also used by the C library, as evidenced by the dependency name, libc.so.6 — but the last GNU C library soname bump occurred many years ago.)
To address the question in your title, it is possible to statically link the C library, but it’s rarely necessary or useful (and can be confusing since some parts of the C library are dynamically linked even when the C library is statically linked). It can be useful to link other libraries statically. Other languages use different approaches, and for example Go programs are statically linked.
At least with the GNU C library, linking carries version information for every single symbol (function etc.) that’s used. You can see this with objdump -T; for example, on /bin/ls, I get
DYNAMIC SYMBOL TABLE:
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.3 __ctype_toupper_loc
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 __uflow
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 getenv
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 sigprocmask
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.3.4 __snprintf_chk
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 raise
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 free
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 abort
etc.
The C library developers go to great lengths to ensure that the C library remains backwards compatible. The above output means that ls needs __ctype_toupper_loc from version 2.3 or later of the C library, etc. Any C library which provides all the required symbols will be able to run a given binary; and any given version of the GNU C library provides implementations of all the symbols which have ever been provided by an older version of the C library (going back to 1997).
Another way of handling things, used by most libraries on Linux-based systems (in fact, ELF-based systems and others), is the soname. Each library defines not only its name, but a version number, which is changed whenever breaking changes are introduced (in some cases, more often). Multiple versions of libraries, with different sonames, can be installed in parallel; for example
-rw-r--r-- 1 root root 2500416 Dec 16 21:07 libcrypto.so.1.0.2
-rw-r--r-- 1 root root 2711616 Nov 28 23:43 libcrypto.so.1.1
(This is also used by the C library, as evidenced by the dependency name, libc.so.6 — but the last GNU C library soname bump occurred many years ago.)
To address the question in your title, it is possible to statically link the C library, but it’s rarely necessary or useful (and can be confusing since some parts of the C library are dynamically linked even when the C library is statically linked). It can be useful to link other libraries statically. Other languages use different approaches, and for example Go programs are statically linked.
answered 1 hour ago
Stephen KittStephen Kitt
175k24400478
175k24400478
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- 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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f505868%2fstatic-linking-libc-possible-or-not-recommended-or-not%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
-glibc, linux
You can read this for some intro link
– Tryna Learn Somethin
1 hour ago
that answers nothing about versioning and so on, I'm not asking some basic question ala 'what is the libc'. I'm asking exactly why there is such hard coupling and whether this can result in silent runtime problems as I suspect it can if I run the executable on a machine that has an incompatible libc
– Blub
1 hour ago
If you use some function from libc in your code. The fucntion parameters etc will be the same accross different version of libc. The only thing that is different is implementation of those function inside of libc which generally shouldn't be of interest to you
– Tryna Learn Somethin
1 hour ago