Understanding dynamic linker
up vote
-2
down vote
favorite
I am wondering why dynamic linker have to search which function in which library.
Can this information be put into elf file by the compile time linker?
If this is done, dynamic linker can find a function directly instead searching.
linker elf
|
show 1 more comment
up vote
-2
down vote
favorite
I am wondering why dynamic linker have to search which function in which library.
Can this information be put into elf file by the compile time linker?
If this is done, dynamic linker can find a function directly instead searching.
linker elf
1
Well that wouldn't be dynamic anymore, would it?
– Cyber Niki
Nov 8 at 15:45
No. Just linker will know which function in which shared library. Linking still be done run time.
– overlord
Nov 8 at 15:51
That's literally what dynamic linking does.
– Cyber Niki
Nov 8 at 15:55
If I say about ld.so; Maps a shared library to excutable address space.If lazy binding is active, when a function is called, linker finds where that function and update the global offset table
– overlord
Nov 8 at 16:02
You can't just call lazy loading "dynamic linking" and expect anyone to understand what you're talking about. Anyway, the main purpose is to speed up the startup time and reduce memory consumption. Of course calling the function is a bit slower as a tradeoff.
– Cyber Niki
Nov 8 at 16:25
|
show 1 more comment
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
I am wondering why dynamic linker have to search which function in which library.
Can this information be put into elf file by the compile time linker?
If this is done, dynamic linker can find a function directly instead searching.
linker elf
I am wondering why dynamic linker have to search which function in which library.
Can this information be put into elf file by the compile time linker?
If this is done, dynamic linker can find a function directly instead searching.
linker elf
linker elf
edited Nov 8 at 15:44
Neil Butterworth
26.7k54679
26.7k54679
asked Nov 8 at 15:43
overlord
114213
114213
1
Well that wouldn't be dynamic anymore, would it?
– Cyber Niki
Nov 8 at 15:45
No. Just linker will know which function in which shared library. Linking still be done run time.
– overlord
Nov 8 at 15:51
That's literally what dynamic linking does.
– Cyber Niki
Nov 8 at 15:55
If I say about ld.so; Maps a shared library to excutable address space.If lazy binding is active, when a function is called, linker finds where that function and update the global offset table
– overlord
Nov 8 at 16:02
You can't just call lazy loading "dynamic linking" and expect anyone to understand what you're talking about. Anyway, the main purpose is to speed up the startup time and reduce memory consumption. Of course calling the function is a bit slower as a tradeoff.
– Cyber Niki
Nov 8 at 16:25
|
show 1 more comment
1
Well that wouldn't be dynamic anymore, would it?
– Cyber Niki
Nov 8 at 15:45
No. Just linker will know which function in which shared library. Linking still be done run time.
– overlord
Nov 8 at 15:51
That's literally what dynamic linking does.
– Cyber Niki
Nov 8 at 15:55
If I say about ld.so; Maps a shared library to excutable address space.If lazy binding is active, when a function is called, linker finds where that function and update the global offset table
– overlord
Nov 8 at 16:02
You can't just call lazy loading "dynamic linking" and expect anyone to understand what you're talking about. Anyway, the main purpose is to speed up the startup time and reduce memory consumption. Of course calling the function is a bit slower as a tradeoff.
– Cyber Niki
Nov 8 at 16:25
1
1
Well that wouldn't be dynamic anymore, would it?
– Cyber Niki
Nov 8 at 15:45
Well that wouldn't be dynamic anymore, would it?
– Cyber Niki
Nov 8 at 15:45
No. Just linker will know which function in which shared library. Linking still be done run time.
– overlord
Nov 8 at 15:51
No. Just linker will know which function in which shared library. Linking still be done run time.
– overlord
Nov 8 at 15:51
That's literally what dynamic linking does.
– Cyber Niki
Nov 8 at 15:55
That's literally what dynamic linking does.
– Cyber Niki
Nov 8 at 15:55
If I say about ld.so; Maps a shared library to excutable address space.If lazy binding is active, when a function is called, linker finds where that function and update the global offset table
– overlord
Nov 8 at 16:02
If I say about ld.so; Maps a shared library to excutable address space.If lazy binding is active, when a function is called, linker finds where that function and update the global offset table
– overlord
Nov 8 at 16:02
You can't just call lazy loading "dynamic linking" and expect anyone to understand what you're talking about. Anyway, the main purpose is to speed up the startup time and reduce memory consumption. Of course calling the function is a bit slower as a tradeoff.
– Cyber Niki
Nov 8 at 16:25
You can't just call lazy loading "dynamic linking" and expect anyone to understand what you're talking about. Anyway, the main purpose is to speed up the startup time and reduce memory consumption. Of course calling the function is a bit slower as a tradeoff.
– Cyber Niki
Nov 8 at 16:25
|
show 1 more comment
1 Answer
1
active
oldest
votes
up vote
0
down vote
I am wondering why dynamic linker have to search which function in which library.
As opposed to recording at static link time which shared library the symbol was defined in, and searching only that library, similar to what happens on Windows?
There are a few reasons:
- Originally, shared libraries were designed to emulate archive libraries, and it was common to have several archive libraries define the same symbol.
- It turns out that not recording the library name allows for symbol interpositioning at runtime, especially with
LD_PRELOAD
. - In the usual case of a few shared libraries, searching the additional libraries doesn't cost that much (searching is done via hash table, not linearly).
For (1), you could still record the first library the symbol was defined in.
For (3), it turns out that some build systems violate the usual case (with 10,000 shared libraries), and the overhead of searching them all becomes significant. There are ways to avoid that overhead without invalidating the usual symbol lookup rules though.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I am wondering why dynamic linker have to search which function in which library.
As opposed to recording at static link time which shared library the symbol was defined in, and searching only that library, similar to what happens on Windows?
There are a few reasons:
- Originally, shared libraries were designed to emulate archive libraries, and it was common to have several archive libraries define the same symbol.
- It turns out that not recording the library name allows for symbol interpositioning at runtime, especially with
LD_PRELOAD
. - In the usual case of a few shared libraries, searching the additional libraries doesn't cost that much (searching is done via hash table, not linearly).
For (1), you could still record the first library the symbol was defined in.
For (3), it turns out that some build systems violate the usual case (with 10,000 shared libraries), and the overhead of searching them all becomes significant. There are ways to avoid that overhead without invalidating the usual symbol lookup rules though.
add a comment |
up vote
0
down vote
I am wondering why dynamic linker have to search which function in which library.
As opposed to recording at static link time which shared library the symbol was defined in, and searching only that library, similar to what happens on Windows?
There are a few reasons:
- Originally, shared libraries were designed to emulate archive libraries, and it was common to have several archive libraries define the same symbol.
- It turns out that not recording the library name allows for symbol interpositioning at runtime, especially with
LD_PRELOAD
. - In the usual case of a few shared libraries, searching the additional libraries doesn't cost that much (searching is done via hash table, not linearly).
For (1), you could still record the first library the symbol was defined in.
For (3), it turns out that some build systems violate the usual case (with 10,000 shared libraries), and the overhead of searching them all becomes significant. There are ways to avoid that overhead without invalidating the usual symbol lookup rules though.
add a comment |
up vote
0
down vote
up vote
0
down vote
I am wondering why dynamic linker have to search which function in which library.
As opposed to recording at static link time which shared library the symbol was defined in, and searching only that library, similar to what happens on Windows?
There are a few reasons:
- Originally, shared libraries were designed to emulate archive libraries, and it was common to have several archive libraries define the same symbol.
- It turns out that not recording the library name allows for symbol interpositioning at runtime, especially with
LD_PRELOAD
. - In the usual case of a few shared libraries, searching the additional libraries doesn't cost that much (searching is done via hash table, not linearly).
For (1), you could still record the first library the symbol was defined in.
For (3), it turns out that some build systems violate the usual case (with 10,000 shared libraries), and the overhead of searching them all becomes significant. There are ways to avoid that overhead without invalidating the usual symbol lookup rules though.
I am wondering why dynamic linker have to search which function in which library.
As opposed to recording at static link time which shared library the symbol was defined in, and searching only that library, similar to what happens on Windows?
There are a few reasons:
- Originally, shared libraries were designed to emulate archive libraries, and it was common to have several archive libraries define the same symbol.
- It turns out that not recording the library name allows for symbol interpositioning at runtime, especially with
LD_PRELOAD
. - In the usual case of a few shared libraries, searching the additional libraries doesn't cost that much (searching is done via hash table, not linearly).
For (1), you could still record the first library the symbol was defined in.
For (3), it turns out that some build systems violate the usual case (with 10,000 shared libraries), and the overhead of searching them all becomes significant. There are ways to avoid that overhead without invalidating the usual symbol lookup rules though.
answered Nov 11 at 2:08
Employed Russian
121k19163232
121k19163232
add a comment |
add a comment |
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%2fstackoverflow.com%2fquestions%2f53211207%2funderstanding-dynamic-linker%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
1
Well that wouldn't be dynamic anymore, would it?
– Cyber Niki
Nov 8 at 15:45
No. Just linker will know which function in which shared library. Linking still be done run time.
– overlord
Nov 8 at 15:51
That's literally what dynamic linking does.
– Cyber Niki
Nov 8 at 15:55
If I say about ld.so; Maps a shared library to excutable address space.If lazy binding is active, when a function is called, linker finds where that function and update the global offset table
– overlord
Nov 8 at 16:02
You can't just call lazy loading "dynamic linking" and expect anyone to understand what you're talking about. Anyway, the main purpose is to speed up the startup time and reduce memory consumption. Of course calling the function is a bit slower as a tradeoff.
– Cyber Niki
Nov 8 at 16:25