Skip to contentSkip to conversation

ELF cleanup

PATCH New [email protected] 1 participant 3 messages Feb 10, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover ELF cleanup

These two patches do a simple cleaunp on ELF related code

o Use EI_NIDENT instead of numeric value in elf64_hdr structure
o Simplify fill_elf_header code by calling memset

Please review. Any comments are welcome.

#1 lore raw

PATCH 1/2 ELF: Use EI_NIDENT instead of numeric value

---

 elf.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/elf.h +1 -1
Index: linux-2.6.git/include/linux/elf.h
===================================================================
@@ -208,7 +208,7 @@ typedef struct elf32_hdr{
 } Elf32_Ehdr;
 
 typedef struct elf64_hdr {
-  unsigned char	e_ident[16];		/* ELF "magic number" */
+  unsigned char	e_ident[EI_NIDENT];	/* ELF "magic number" */
   Elf64_Half e_type;
   Elf64_Half e_machine;
   Elf64_Word e_version;
#2 lore raw

PATCH 2/2 BINFMT: fill_elf_header cleanup - use straigth memset first

In reply to [email protected]

This patch does simplify fill_elf_header function by setting to zero the whole elf header first. So we fillup the fields we really need only.

before:
text data bss dec hex filename
11735 80 0 11815 2e27 fs/binfmt_elf.o

after:
text data bss dec hex filename
11710 80 0 11790 2e0e fs/binfmt_elf.o

viola, 25 bytes of text is freed

---

 binfmt_elf.c |    9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
fs/binfmt_elf.c +3 -6
Index: linux-2.6.git/fs/binfmt_elf.c
===================================================================
@@ -1276,26 +1276,23 @@ static int writenote(struct memelfnote *
 static void fill_elf_header(struct elfhdr *elf, int segs,
 			    u16 machine, u32 flags, u8 osabi)
 {
+	memset(elf, 0, sizeof(*elf));
+
 	memcpy(elf->e_ident, ELFMAG, SELFMAG);
 	elf->e_ident[EI_CLASS] = ELF_CLASS;
 	elf->e_ident[EI_DATA] = ELF_DATA;
 	elf->e_ident[EI_VERSION] = EV_CURRENT;
 	elf->e_ident[EI_OSABI] = ELF_OSABI;
-	memset(elf->e_ident+EI_PAD, 0, EI_NIDENT-EI_PAD);
 
 	elf->e_type = ET_CORE;
 	elf->e_machine = machine;
 	elf->e_version = EV_CURRENT;
-	elf->e_entry = 0;
 	elf->e_phoff = sizeof(struct elfhdr);
-	elf->e_shoff = 0;
 	elf->e_flags = flags;
 	elf->e_ehsize = sizeof(struct elfhdr);
 	elf->e_phentsize = sizeof(struct elf_phdr);
 	elf->e_phnum = segs;
-	elf->e_shentsize = 0;
-	elf->e_shnum = 0;
-	elf->e_shstrndx = 0;
+
 	return;
 }