2006-11-14 13:01:00

by Magnus Damm

[permalink] [raw]
Subject: [PATCH 00/03] Elf: Various fixes

elf: various note fixes - the best of the 64-bit alignment patch

It seems like most people want 32-bit aligment on 64-bit platforms, so I've
given in and removed the alignment code but kept the fixes. The patches are
now refreshed to rc5 and updated to reflect the comments from Jakub, thanks!

/ magnus


2006-11-14 13:01:41

by Magnus Damm

[permalink] [raw]
Subject: [PATCH 02/03] Elf: Include terminating zero in n_namesz

elf: Include terminating zero in n_namesz

The ELF32 spec says we should plus we include the zero on other platforms.

Signed-off-by: Magnus Damm <[email protected]>
---

arch/mips/kernel/irixelf.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

--- 0003/arch/mips/kernel/irixelf.c
+++ work/arch/mips/kernel/irixelf.c 2006-11-14 20:56:54.000000000 +0900
@@ -1009,7 +1009,7 @@ static int notesize(struct memelfnote *e
int sz;

sz = sizeof(struct elf_note);
- sz += roundup(strlen(en->name), 4);
+ sz += roundup(strlen(en->name) + 1, 4);
sz += roundup(en->datasz, 4);

return sz;
@@ -1028,7 +1028,7 @@ static int writenote(struct memelfnote *
{
struct elf_note en;

- en.n_namesz = strlen(men->name);
+ en.n_namesz = strlen(men->name) + 1;
en.n_descsz = men->datasz;
en.n_type = men->type;

2006-11-14 13:01:08

by Magnus Damm

[permalink] [raw]
Subject: [PATCH 01/03] Elf: Always define elf_addr_t in linux/elf.h

elf: Always define elf_addr_t in linux/elf.h

This patch defines elf_addr_t in linux/elf.h. The size of the type is
determined using ELF_CLASS. This allows us to remove the defines that
today are spread all over .c and .h files.

Signed-off-by: Magnus Damm <[email protected]>
---

arch/ia64/ia32/ia32priv.h | 2 --
arch/mips/kernel/binfmt_elfn32.c | 1 -
arch/mips/kernel/binfmt_elfo32.c | 1 -
arch/mips/kernel/irixelf.c | 4 ----
arch/parisc/kernel/binfmt_elf32.c | 1 -
arch/s390/kernel/binfmt_elf32.c | 1 -
arch/sparc64/kernel/binfmt_elf32.c | 1 -
arch/x86_64/ia32/ia32_binfmt.c | 2 --
fs/binfmt_elf.c | 4 ----
fs/binfmt_elf_fdpic.c | 3 ---
include/asm-powerpc/elf.h | 2 --
include/linux/elf.h | 2 ++
12 files changed, 2 insertions(+), 22 deletions(-)

--- 0001/arch/ia64/ia32/ia32priv.h
+++ work/arch/ia64/ia32/ia32priv.h 2006-11-14 16:28:37.000000000 +0900
@@ -330,8 +330,6 @@ struct old_linux32_dirent {
void ia64_elf32_init(struct pt_regs *regs);
#define ELF_PLAT_INIT(_r, load_addr) ia64_elf32_init(_r)

-#define elf_addr_t u32
-
/* This macro yields a bitmask that programs can use to figure out
what instruction set this CPU supports. */
#define ELF_HWCAP 0
--- 0001/arch/mips/kernel/binfmt_elfn32.c
+++ work/arch/mips/kernel/binfmt_elfn32.c 2006-11-14 16:28:37.000000000 +0900
@@ -90,7 +90,6 @@ struct elf_prpsinfo32
char pr_psargs[ELF_PRARGSZ]; /* initial part of arg list */
};

-#define elf_addr_t u32
#define elf_caddr_t u32
#define init_elf_binfmt init_elfn32_binfmt

--- 0001/arch/mips/kernel/binfmt_elfo32.c
+++ work/arch/mips/kernel/binfmt_elfo32.c 2006-11-14 16:28:37.000000000 +0900
@@ -92,7 +92,6 @@ struct elf_prpsinfo32
char pr_psargs[ELF_PRARGSZ]; /* initial part of arg list */
};

-#define elf_addr_t u32
#define elf_caddr_t u32
#define init_elf_binfmt init_elf32_binfmt

--- 0001/arch/mips/kernel/irixelf.c
+++ work/arch/mips/kernel/irixelf.c 2006-11-14 16:28:37.000000000 +0900
@@ -52,10 +52,6 @@ static struct linux_binfmt irix_format =
irix_core_dump, PAGE_SIZE
};

-#ifndef elf_addr_t
-#define elf_addr_t unsigned long
-#endif
-
#ifdef DEBUG
/* Debugging routines. */
static char *get_elf_p_type(Elf32_Word p_type)
--- 0002/arch/parisc/kernel/binfmt_elf32.c
+++ work/arch/parisc/kernel/binfmt_elf32.c 2006-11-14 16:28:37.000000000 +0900
@@ -75,7 +75,6 @@ struct elf_prpsinfo32
char pr_psargs[ELF_PRARGSZ]; /* initial part of arg list */
};

-#define elf_addr_t unsigned int
#define init_elf_binfmt init_elf32_binfmt

#define ELF_PLATFORM ("PARISC32\0")
--- 0001/arch/s390/kernel/binfmt_elf32.c
+++ work/arch/s390/kernel/binfmt_elf32.c 2006-11-14 16:28:37.000000000 +0900
@@ -176,7 +176,6 @@ struct elf_prpsinfo32

#include <linux/highuid.h>

-#define elf_addr_t u32
/*
#define init_elf_binfmt init_elf32_binfmt
*/
--- 0001/arch/sparc64/kernel/binfmt_elf32.c
+++ work/arch/sparc64/kernel/binfmt_elf32.c 2006-11-14 16:28:37.000000000 +0900
@@ -141,7 +141,6 @@ cputime_to_compat_timeval(const cputime_
value->tv_sec = jiffies / HZ;
}

-#define elf_addr_t u32
#undef start_thread
#define start_thread start_thread32
#define init_elf_binfmt init_elf32_binfmt
--- 0002/arch/x86_64/ia32/ia32_binfmt.c
+++ work/arch/x86_64/ia32/ia32_binfmt.c 2006-11-14 16:28:37.000000000 +0900
@@ -305,8 +305,6 @@ MODULE_AUTHOR("Eric Youngdale, Andi Klee
#undef MODULE_DESCRIPTION
#undef MODULE_AUTHOR

-#define elf_addr_t __u32
-
static void elf32_init(struct pt_regs *);

#define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
--- 0002/fs/binfmt_elf.c
+++ work/fs/binfmt_elf.c 2006-11-14 16:28:37.000000000 +0900
@@ -47,10 +47,6 @@ static int load_elf_binary(struct linux_
static int load_elf_library(struct file *);
static unsigned long elf_map (struct file *, unsigned long, struct elf_phdr *, int, int);

-#ifndef elf_addr_t
-#define elf_addr_t unsigned long
-#endif
-
/*
* If we don't support core dumping, then supply a NULL so we
* don't even try.
--- 0002/fs/binfmt_elf_fdpic.c
+++ work/fs/binfmt_elf_fdpic.c 2006-11-14 16:28:37.000000000 +0900
@@ -40,9 +40,6 @@
#include <asm/pgalloc.h>

typedef char *elf_caddr_t;
-#ifndef elf_addr_t
-#define elf_addr_t unsigned long
-#endif

#if 0
#define kdebug(fmt, ...) printk("FDPIC "fmt"\n" ,##__VA_ARGS__ )
--- 0001/include/asm-powerpc/elf.h
+++ work/include/asm-powerpc/elf.h 2006-11-14 16:28:37.000000000 +0900
@@ -124,12 +124,10 @@ typedef elf_greg_t32 elf_gregset_t32[ELF
# define ELF_DATA ELFDATA2MSB
typedef elf_greg_t64 elf_greg_t;
typedef elf_gregset_t64 elf_gregset_t;
-# define elf_addr_t unsigned long
#else
/* Assumption: ELF_ARCH == EM_PPC and ELF_CLASS == ELFCLASS32 */
typedef elf_greg_t32 elf_greg_t;
typedef elf_gregset_t32 elf_gregset_t;
-# define elf_addr_t __u32
#endif /* ELF_ARCH */

/* Floating point registers */
--- 0001/include/linux/elf.h
+++ work/include/linux/elf.h 2006-11-14 16:31:22.000000000 +0900
@@ -358,6 +358,7 @@ extern Elf32_Dyn _DYNAMIC [];
#define elfhdr elf32_hdr
#define elf_phdr elf32_phdr
#define elf_note elf32_note
+#define elf_addr_t Elf32_Off

#else

@@ -365,6 +366,7 @@ extern Elf64_Dyn _DYNAMIC [];
#define elfhdr elf64_hdr
#define elf_phdr elf64_phdr
#define elf_note elf64_note
+#define elf_addr_t Elf64_Off

#endif

2006-11-14 13:01:24

by Magnus Damm

[permalink] [raw]
Subject: [PATCH 03/03] Elf: Fix kcore note size calculation

elf: fix kcore note size calculation

- Define "CORE" string as CORE_STR in single common place.
- Include terminating zero in CORE_STR length calculation for elf_buflen.
- Use roundup(,4) to include alignment in elf_buflen calculation.

Signed-off-by: Magnus Damm <[email protected]>
---

fs/proc/kcore.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)

--- 0002/fs/proc/kcore.c
+++ work/fs/proc/kcore.c 2006-11-14 21:17:16.000000000 +0900
@@ -22,6 +22,7 @@
#include <asm/uaccess.h>
#include <asm/io.h>

+#define CORE_STR "CORE"

static int open_kcore(struct inode * inode, struct file * filp)
{
@@ -82,10 +83,11 @@ static size_t get_kcore_size(int *nphdr,
}
*elf_buflen = sizeof(struct elfhdr) +
(*nphdr + 2)*sizeof(struct elf_phdr) +
- 3 * (sizeof(struct elf_note) + 4) +
- sizeof(struct elf_prstatus) +
- sizeof(struct elf_prpsinfo) +
- sizeof(struct task_struct);
+ 3 * ((sizeof(struct elf_note)) +
+ roundup(strlen(CORE_STR) + 1, 4)) +
+ roundup(sizeof(struct elf_prstatus), 4) +
+ roundup(sizeof(struct elf_prpsinfo), 4) +
+ roundup(sizeof(struct task_struct), 4);
*elf_buflen = PAGE_ALIGN(*elf_buflen);
return size + *elf_buflen;
}
@@ -210,7 +212,7 @@ static void elf_kcore_store_hdr(char *bu
nhdr->p_offset = offset;

/* set up the process status */
- notes[0].name = "CORE";
+ notes[0].name = CORE_STR;
notes[0].type = NT_PRSTATUS;
notes[0].datasz = sizeof(struct elf_prstatus);
notes[0].data = &prstatus;
@@ -221,7 +223,7 @@ static void elf_kcore_store_hdr(char *bu
bufp = storenote(&notes[0], bufp);

/* set up the process info */
- notes[1].name = "CORE";
+ notes[1].name = CORE_STR;
notes[1].type = NT_PRPSINFO;
notes[1].datasz = sizeof(struct elf_prpsinfo);
notes[1].data = &prpsinfo;
@@ -238,7 +240,7 @@ static void elf_kcore_store_hdr(char *bu
bufp = storenote(&notes[1], bufp);

/* set up the task structure */
- notes[2].name = "CORE";
+ notes[2].name = CORE_STR;
notes[2].type = NT_TASKSTRUCT;
notes[2].datasz = sizeof(struct task_struct);
notes[2].data = current;