Subject: Re: New idea on ELF prebinding
From: David Laight <email@example.com>
Date: 11/22/2002 20:04:40
> - Actual prebinding and prerelocation is done by ld.elf_so(1). After
> ld.elf_so(1) loads a binary for the first time, it creates a disk
> file in /usr/libexec/reloc (say it "cache") and writes all of the
> relocated GOT and PLT sections in memory to the file (checksum and
> other necessary information as well). In any subsequent execution
> of the same binary, ld.elf_so(1) no longer performs relocation.
> Instead it loads cache from the disk file previously created and
> compares cache information and in-memory data. If they don't differ,
> it patches GOT/PLT pointers so that they point to locations in the
> cache. But if they differ, ld.elf_so(1) will do the same job.
Could you take this one stage further?
For a program  you wish to 'prebind' generate a file that contains:
- the names of each elf object that makes it up with the offset,
size and address of each area that need mmap()ing readonly shared
- a data area containing all the writable area of the entire program
(including the shared libraries that will be loaded) already fixed
up for the addresses the libraries will be mapped to
- symbol tables for each namespace (for dlsym)
This would be an executable file that is basically elf, but uses
a special interpreter to find the correct files and map segments
of them to the correct addresses.
Executing this version of the program would not require any
code or data fixups.
(clearly you need to be able to detect whether any of the files
have been overwritten since you generated the image)
 you have to do this far each program, not shared library due to
the symbol lookup rules.
David Laight: firstname.lastname@example.org