views:

82

answers:

3

How does linker know which symbols should be resolved at runtime? Particularly I'm interested what information shared object files carry that instruct linker to resolve symbols at runtime. How does the dynamic symbol resolution work at runtime, i.e. what executable will do to find the symbol and in case multiple symbols with the same name were defined which would be found?

What happens if the file was linked only statically, but then it's linked dynamically at run-time as part of a shared library? Which symbol will be used by the executable? In other words, is that possible to override symbols in an executable by linking those symbols into a shared library?

The platform in question is SUN OS.

+2  A: 

Try the below link. I hope it answers your question

http://www.linuxjournal.com/article/6463

Vaibhav
:O) Beat me to it. I referenced the same article in my answer. Up-vote for speed.
M. Tibbits
I actually use this article as an example for people starting with C++ programming and is quite effective.
Vaibhav
What happens if the file was linked **only** statically, but then it's linked dynamically at run-time as part of a shared library? Which symbol will be used by the executable? In other words, is that possible to override symbols in an executable by linking those symbols into a shared library?
Leonid
The library is only used to resolve symbols that have not been resolved in all the object files of the program. So, I believe static linkage will override.
Vaibhav
+1  A: 

Check out this article from Linux Journal. For more information -- perhaps specifically related to Windows, AIX, OSx, etc -- I would recommend the Wikipedia article on Linker (computing) and the references therein.

M. Tibbits
A: 

If a file is statically linked there is no run time resolution to speak of. If a shared object links to that same library either dynamically or statically, the version linked to the library will only effect code executed in the library. This can cause problems if you link to two different versions of the same library that are incompatible and shift data back and forth.

stonemetal