0

Quoted from a reply to a post

3.The calling module will then either statically or dynamically bind to the shared library.

4.Once your calling library is bound to the shared library it can then specify it wants to bind to a particular entry point. This is generally done by name, however most platforms also offer the option of binding by index (faster, yet more brittle if your module changes and entry points are reordered).

5.You will also generally declare the function you want to call in your module somewhere so that your language can do static type checking, knows what the calling convention is etc.

I was wondering

  1. what does "a module statically or dynamically binds to the shared library" mean? Does it mean name binding, i.e. association of identity in some module to objects (code or data) in the shared library, or linking from some module to the share library?
  2. Where I can find a more wikipedia-like description on binding by name and by index?

Thanks and regards!

Community
  • 1
  • 1
Tim
  • 1
  • 141
  • 372
  • 590
  • Looking at your questions I feel that you need some real source of information instead of asking every time. So if you tell what you really want to achieve I can advice you a good source to read. – xappymah Mar 27 '11 at 20:30
  • @xappymah: Thanks! I want to achieve/understand a lot of things: mixed language programming (FFI), meaning/difference of run-time (environment) and virtual machine, learning functional language, understand compilation and ABI, a big picture/survey of features existing in most programming languages, .... From my questions, I guess you might already understand. – Tim Mar 27 '11 at 20:33
  • then you really need the Wikipedia, the best source of pure information:) Or to get a job in some system software company. For the beginning I recommend you to read this article http://msdn.microsoft.com/en-us/magazine/bb985992.aspx (and the second part http://msdn.microsoft.com/en-us/magazine/cc301808.aspx) It is about PE format but also describes all this linking-binding routine on Windows. Also try links from articles in wikipedia which are related to the stuff you are interested in. – xappymah Mar 27 '11 at 20:50

2 Answers2

3

Dynamic and static linking are methods of sharing library code in modern computer operating systems.

Dynamic linking happens at runtime. It trades a little bit of extra work at startup time for some nice features like allowing the library to be patched/replaced which in turn can fix or add features to applications which are linked (bound) to it.

Static linking is where portions of the library are copied into the executable. This is faster for startup and sometimes more convenient for distribution because you don't have to worry about whether the recipient has all the shared libraries. It can also save space in some cases. It's common for embedded applications.

http://en.wikipedia.org/wiki/Dynamic-link_library http://en.wikipedia.org/wiki/Static_library

The binding by name refers to the process of linking functions, variables, and constants from a library into an application, module of an application, or another library. Basically a library is an archive of code and there's a table which points to each compiled bit of code's location in the library, and the linker uses the names to look up where the bits are that are needed. Like a phonebook =)

Binding and Linking are used interchangeably in a lot of contexts.

Think of it this way: Binding by name the reference remains by name, lookups will have to search some sort of namespace to resolve accesses. With linking the name is converted into an address, generally just the one time, and then the name is no longer required. Linking is fast for multiple accesses.

Some binding systems may implement an address cache to speed up lookups. A good example is your desktop's ARP cache, which caches IP addresses which were looked up by name using a DNS server (coincidentally, the most-used DNS server is called "bind".)

Scripting languages often bind things by name instead of linking, because the overhead of doing name-based lookups isn't as big a penalty when the language itself is interpreted.

Wil
  • 757
  • 9
  • 12
  • Thanks! (1) what does binding by index mean then? (2) So I guess this binding (by name or by index) here is a concept in linking, and different from name binding as in http://en.wikipedia.org/wiki/Name_binding? Is name binding a concept only for compilation not for linking, as I figured out from this reply http://stackoverflow.com/questions/5449876/dynamic-binding-and-dynamic-linking/5451273#5451273 ? – Tim Mar 27 '11 at 20:44
  • I will add the response to my reponse above because it's too big for here ;-) – Wil Mar 27 '11 at 22:00
  • Thanks! Are "binding by name" here and "name binding" in http://en.wikipedia.org/wiki/Name_binding the same thing? – Tim Mar 27 '11 at 22:24
  • I need to know a little bit more about the context of your quote before I can answer that. Where did you come by it? – Wil Mar 27 '11 at 22:39
  • (1) In my original post, the quote containing binding by name and binding by index to a shared library comes from http://stackoverflow.com/questions/840888/how-does-code-written-in-one-language-get-called-from-another-language/840946#840946; "name binding" comes from http://en.wikipedia.org/wiki/Name_binding . (2) Is binding by index same as binding by address in your reply? Thanks – Tim Mar 27 '11 at 22:48
  • Okay, that post is in regards to linking C++ libraries with Scheme. I don't have any practical experience with Scheme, so I will cop out and point you at the developers' mailing list for specific implementation information: http://mail.gnu.org/mailman/listinfo/mit-scheme-devel – Wil Mar 27 '11 at 23:13
  • Sorry, and index and address are very closely related but not identical. In systems with relative addressing they are functionally the same - you have a base address and the index is added to the base address to produce the target address. In other systems, the index can be the address. For example with software interrupts where a function is called by passing an index in a register, as is done in the Linux Kernel. In yet other systems, the index can be an offset into a lookup table, etc. etc. – Wil Mar 27 '11 at 23:22
2

Binding means loading and getting an address for the shared library. Normally, the program will be make a reference to the shared library at compiled time, this called static binding.

A dynamic bind is when the program determines at run-time the name of shared library and loads it then

Richard Schneider
  • 34,944
  • 9
  • 57
  • 73
  • Thanks! I was wondering whether it is talking about linking to a library (http://en.wikipedia.org/wiki/Linker_%28computing%29), or name binding (http://en.wikipedia.org/wiki/Name_binding), or both? – Tim Mar 27 '11 at 20:30
  • Linking to a library is a specific form of binding. In general, binding means mapping a name to its value. – Richard Schneider Mar 27 '11 at 20:32
  • Thanks! From http://stackoverflow.com/questions/5449876/dynamic-binding-and-dynamic-linking/5451273#5451273, it looks like binding and linking are not at all related. I am confused. – Tim Mar 27 '11 at 20:39
  • @Tim they are related, one is a specific form of the other more general term. – David Heffernan Mar 27 '11 at 22:33