[Main]
Title=__ld_insert_kernel_libs
See Also=insert_fargo020_libs: __ld_insert_fargo020_libs, insert_fargo021_libs: __ld_insert_fargo021_libs
[Top]
__ld_insert_kernel_libs can be used to handle
library calls. It inserts references
to libraries in the format used by kernels:
- For each referenced library...
- For each referenced library (again)...
- 2 bytes: number of imported functions/variables minus 1
- For each imported function/variable...
- 2 bytes: index of the function/variable
- Relocation table for this function/variable:
- For each reference...
- 2 bytes: location (may not be 0)
- 2 bytes: 0
If a program uses this insertion, it must process it as follows:
- For each library...
- Do whatever is necessary to check the version and load it into the
program's address space;
- For each relocation entry...
- Get the starting address of the program (via
__ld_entry_point);
- Add the location value;
- Modify the 4-byte value (offset) at the resulting address:
- Get the address of the library function/variable indexed by
index;
- Add the value of offset;
- Write the resulting address to the 4-byte space covered by
offset.
Before program termination, this process has to be reverted, so that it can
be repeated the next time the program starts. Since programs and libraries
may be moved in memory while they are not executed, they may not
simply deactivate the relocation code. This would also prevent programs from
being transferred between devices.