[ Pobierz całość w formacie PDF ]
.out format was developed before shared library technology was developed, so shared libraries are not very cleanly supported.It is not impossible to design shared library implementations that work with a.out.ELF allows us to discard some ofthe hacks that were required to piggyback a shared library implementation onto a.out.Now let's look a little bit at what a shared library is.Non-shared libraries (also known as static libraries) contain common useful procedures callable from programs.When you link against a static library, the linker must extract all library functionsyou require and make them part of your executable making it bulky.A shared library lets you take a static version of library and pre-link it into some kind of special type of executable.When you link your program against the shared library, the linker does not extract the binary code from shared library into yourexecuteable, rather it simply adds a reference to the code's offset and the library to use.After linking, when the loader runs your program, it knows where to get the code from which library to fill in any memory gaps.With the current a.out scheme, shared libraries must be loaded in predefined locations in memory.ELF shared libraries are position independent.This means that you can load them at just about any location in memory to get them to work.ELF sharedlibraries have to be compiled with -fPIC switch to generate position independant code.When you compile something to be -fPIC, the compiler reserves one machine register (register ebx on the i386) to point to the start of a global offset table (GOT).Thecost is that this register is reserved by the compiler and results in less flexibility in optimizing code.ebx register in an i386 machine is not very popular so it's not that big a loss in speed.Another ELF feature is that its shared libraries resolve symbols and externals at run time by using a symbol table and a list of relocations.Symbol resolution is performed before the image executes.The ELF support in Linux makes it very efficientsince all symbols are referenced off the same global variable for the ELF library, rather than a fixed location in memory.Basically each global variable defined or referenced in the shared library means that the kernel uses the ebx register to compute andload the address of the variable from the GOT to get the address.The advantage of using one global variable is that when the loader ld moves an entire.text or.data section, you need only resolve one global address and do no address resolutions.A similar setup is used for functions with the use of a Procedure Link Table (PLT).The use of the PLT enables the programmer to redefine (override) functions which might be in the shared library.Then the PLT entry for the function can be used insteadof the regular library entry.A PLT is only an array of jump instructions, one for each function that you might need to go to.Thus if a particular function is called from many positions within the shared library, the call will always pass through one jumpinstruction.You can then control all calls to this file by setting or resetting this one location register.Efficient and clean.This chapter cannot possibly cover all you need to know about the ELF format.For more information about the ELF file format, obtain the ELF specifications from a number of sourcesfor example ftp.intel.com in pub/tis/elf11g.zip.The specifications are also available in a printed format.See SYSTEM V Application Binary Interface (ISBN 0-13-100439-5) and SYSTEM V Application Binary Interface, Intel386 Architecture Processor Supplement (ISBN 0-13-104670-5).SummaryRecompiling kernel source and adding new features to the kernel proceeds smoothly, as long as you know what you are doing.Don't let the process scare you, but always keep boot disks on hand.Follow instructions wherever available, because most newsoftware has special requirements for linking into the kernel or replacing existing systems
[ Pobierz całość w formacie PDF ]