Re: static library and dynamic library




"Even" <szhang@xxxxxxxxxxx> wrote in message news:1192697933.197259.227200@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi all,

As far as I know, relative address will be assigned by program at link
time.Right? Ok, here we go.


'relative' is not a good term here.


So if we use a static library, it will give the program an relative
address(i mean the function address) at link time.
Also the code of the library will load into the program. Go on.


yeah, at link time, all the code and data from the library goes into the binary, which is part of why using lots of static libs tends to produce large binaries...

the code in the app is linked directly to the code in the library, just the same as with local code.


Now if we use a dynamic library, what it will give the program?
A symbolic? or Address ?


it depends.


if it is a symbolic, when does the symbolic change to an address? and
How does it load its code to the program?


this depends on the OS.

note that there may be errors here, all this is not something I have looked into in too much detail.


on linux and friends, it will produce a binary that is like "oh well, I am not fully linked, load these libraries on loading". so, the loader will also grab the libraries, and resolve the addresses to the addresses in the library (internally, this will look about the same as if the app had used a static library).

the exact mechanics of this process are not something I will really go into.

note that in linux, these libs tend to use position-independent-code, which is fun, since the same library pages can be shared between different processes, and located at different locations in each (GOT magic...). in windows, however, DLLs are typically fixed-address to allow sharing (relocating DLLs is also possible, but they end up having their own pages in each process...).


now, I think, DLLs are a little different.
as far as I understand it, with DLLs you end up with a number of proxy functions, which jump into the function through a jump table.

so, at load time, the app is loaded, and either the loader (or part of the app's runtime, or at least, I think this is how it worked at one time) sees that a DLL is needed, so it loads the DLL and fills in the various slots in the table.

in the past, this was done via import libraries (a special tool was used to make a static library from the DLL), but (at least for GNU-ld), all this magic is done by the linker itself.

but, none of this is anything I have really looked into in too much detail...



Thanks
Even


.



Relevant Pages

  • Re: Linux, X, ld, gcc, linking, shared libraries and stuff
    ... all the dependent DLLs (and all their dependent DLLs and all their ... DLL, though, this triggers the OS to actual load and link that DLL...hence, ... if your libraries are accessed almost immediately and ... As noted, though, most OSes out there are anything but "toolmaker's view" ...
    (alt.lang.asm)
  • Re: C++ dlls not loading with WM 6, worked with WM5.0
    ... I need to build C and C++ libs and dlls that are linked in to by other ... The C++ libraries link in the C libraries. ... I have those built for Windows Mobile 5.0 and working fine. ... LoadLibrary(), and while it is able to load the C dll, it fails to load ...
    (microsoft.public.windowsce.app.development)
  • Re: Mex vs. Generic DLLs
    ... and only load the appropriate libraries ... I'd have to load the ... to dynamic libraries. ... The overhead of actually finding, opening, parsing, etc. multiple DLLs ...
    (comp.soft-sys.matlab)
  • Re: EncryptMessage Memory leak
    ... You are correct about the dlls, ... I should say in any case that these two libraries are the main difference ... Yet memory continues to be leaked in the EncryptMessage call (I've proved ... these two dlls then I could see how you'd leak memory. ...
    (microsoft.public.platformsdk.security)
  • Re: How does Require deal with multiple files of the same name in different directories
    ... IMHO, once it is decided to load the file, this is required to happen, so it is not ... A program written for older W32F versions is available somewhere. ... As the old libraries won't work with the new W32F anyway, ... downloaded apps, which means checking any downloadable apps I (and ...
    (comp.lang.forth)