Elfdiet patches for Linux kernel
April 21, 2004
The elfdiet patch reduces code space and time in the handling of execve() for binfmt_elf
executables such as C/C++ compiled programs. A subroutine read_elf_phdrs() replaces three
separate instances of open code to get the Elf_Phdr descriptors (load_elf_binary, load_elf_interp, load_elf_library). A
subroutine map_elf_LOAD()
replaces three separate instances of open code to mmap the PT_LOAD
segments. The space savings on x86 is about 1250 bytes out of
10,000, or about 12%. The time cost is about 2.5% slower for a
long loop of "int main() { return
0; }". Then, about 150 bytes of code are spent to improve
speed by using a fixed-size stack array [space cache] of Elf_Phdr when
possible. In common cases, this avoids calling kmalloc/kfree to access the Elf_Phrs for
both the main program and the Elf interpreter. The time savings
is about 5% compared to the smallest code patch, or about 2.5% compared
to the unpatched kernel.
The patch also handles .bss more generally. Every Elf_Phdr with p_filesz < p_memsz gets a "local" .bss, and
the p_flags apply (instead
of assuming PROT_READ|PROT_WRITE).
This allows programs such as Wine to reserve address space using
".bss" with no access allowed at all, and in particular with no
overcommit of memory.
As of March 15, the patch is BETA test quality. It is in daily
default use on my Fedora Core 2 Test 1 machine (Athlon x86).
Testing on other architectures, especially 64-bit machines, is
encouraged. Please report experiences to me (jreiser BitWagon
com).
bssprot-2.6.6-rc2-mm1.patch.gz
(6KB; just the .bss page protection fix)
elfdiet2-2.6.6-rc2-mm1.patch.gz
(8KB; elfdiet2 = elfdiet - bssprot)
bssprot-2.6.6-rc1-mm1.patch.gz
(6KB; just the .bss page protection fix)
elfdiet2-2.6.6-rc1-mm1.patch.gz
(8KB; elfdiet2 = elfdiet - bssprot)
elfdiet-2.6.5-1.327.patch.gz
(9KB; Fedora Core 2 Test 2)
bssprot-2.6.6-rc1.patch.gz
(6KB; just the .bss page protection fix)
elfdiet2-2.6.6-rc1.patch.gz
(8KB; elfdiet2 = elfdiet - bssprot)
bssprot-2.6.5-mm6.patch.gz
(6KB; just the .bss page protection fix)
elfdiet2-2.6.5-mm6.patch.gz
(8KB; elfdiet2 = elfdiet - bssprot)
elfdiet-2.4.26.patch.gz
(9KB)
bssprot-1-2.6.5-mm5-1.patch.gz
(6KB; just the .bss page protection fix)
elfdiet2-2.6.5-mm5-1.patch.gz
(8KB; elfdiet2 = elfdiet - bssprot)
elfdiet-2.6.5-mm5-1.patch.gz
(9KB)
elfdiet-2.6.5-1.319.patch.gz
(9KB; Fedora Core 2 Test 2)
elfdiet-2.6.5-mc4.patch.gz
(9KB)
elfdiet-2.6.5-mm2.patch.gz
(9KB)
elfdiet-2.6.5.patch.gz
(9KB)
elfdiet-2.6.4-1.305.patch.gz
(9KB; Fedora Core 2 Test 2)
elfdiet-2.6.4.patch.gz
(9KB)
elfdiet-2.6.4-mm2.patch.gz
(10KB)
elfdiet-2.6.3-2.1.253.patch.gz
(9KB; Fedora Core 2 Test 1)
elfdiet-2.4.25.patch.gz
(9KB)
elfdiet-2.4.22-1.2174.patch.gz
(10KB; Fedora Core 1)