In Linux, why are stubs required for standard libraries?
相关问题
- Multiple sockets for clients to connect to
- Is shmid returned by shmget() unique across proces
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- how to get running process information in java?
stubs are required to ensure proper linking of an executable across various linux releases without building the object files.
For example: Let a be the executable we are building:
In the above case executable a has a dependency on the libz.so (
-lz
is to link with libz.so). The linker resolves libz.so using the LD_LIBRARY_PATH.Now let us see the problem:
In RHEL5, we see an undefined symbol in the libz.so. Unless we pass libc to the linker after lz in the above command, this cannot be resolved.
Stubs: If we generate the stub for libz.so, packing all the symbols of libz.so in to a stub library and link with the stub library instead of the real library, we don't see any errors:
Modified link line:
In the /home/lib/stubs directory, we have a stub library for libz.so by name libzstub.so.
Linker gives higher priority to the path given in the link command than LD_LIBRARY_PATH.
Now even if we link in the RHEL5 release, the linker resolves the symbols for the libz.so from the /home/lib/stubs directory.
Here the configuration details of the boxes i have used.
Loader takes care of loading the coresponding function at runtime.
RHEL5:
RHEL4: