2008-02-12 13:34:35

by Edgar E. Iglesias

[permalink] [raw]
Subject: [PATCH] Use ELF_CORE_EFLAGS for kcore ELF header flags.

ELF_CORE_EFLAGS is already used by the binfmt_elf coredumper to set correct
arch specific ELF header flags on coredumps. Use it for kcore aswell.
This corrects kcore files for the CRIS arch and I beleive it corrects
ordinary coredumps for the H8/300.

Signed-off-by: Edgar E. Iglesias <[email protected]>

---

diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
index e78c81f..c2370c7 100644
--- a/fs/proc/kcore.c
+++ b/fs/proc/kcore.c
@@ -23,6 +23,10 @@

#define CORE_STR "CORE"

+#ifndef ELF_CORE_EFLAGS
+#define ELF_CORE_EFLAGS 0
+#endif
+
static int open_kcore(struct inode * inode, struct file * filp)
{
return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
@@ -164,11 +168,7 @@ static void elf_kcore_store_hdr(char *bufp, int nphdr, int dataoff)
elf->e_entry = 0;
elf->e_phoff = sizeof(struct elfhdr);
elf->e_shoff = 0;
-#if defined(CONFIG_H8300)
- elf->e_flags = ELF_FLAGS;
-#else
- elf->e_flags = 0;
-#endif
+ elf->e_flags = ELF_CORE_EFLAGS;
elf->e_ehsize = sizeof(struct elfhdr);
elf->e_phentsize= sizeof(struct elf_phdr);
elf->e_phnum = nphdr;
diff --git a/include/asm-h8300/elf.h b/include/asm-h8300/elf.h
index 26bfc7e..806f20b 100644
--- a/include/asm-h8300/elf.h
+++ b/include/asm-h8300/elf.h
@@ -32,6 +32,8 @@ typedef unsigned long elf_fpregset_t;
#define ELF_FLAGS 0x820000
#endif

+#define ELF_CORE_EFLAGS ELF_FLAGS
+
#define ELF_PLAT_INIT(_r) _r->er1 = 0

#define USE_ELF_CORE_DUMP


2008-02-14 00:41:56

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH] Use ELF_CORE_EFLAGS for kcore ELF header flags.

On Tue, 12 Feb 2008 14:34:23 +0100
"Edgar E. Iglesias" <[email protected]> wrote:

> ELF_CORE_EFLAGS is already used by the binfmt_elf coredumper to set correct
> arch specific ELF header flags on coredumps. Use it for kcore aswell.
> This corrects kcore files for the CRIS arch and I beleive it corrects
> ordinary coredumps for the H8/300.
>
> Signed-off-by: Edgar E. Iglesias <[email protected]>
>
> ---
>
> diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
> index e78c81f..c2370c7 100644
> --- a/fs/proc/kcore.c
> +++ b/fs/proc/kcore.c
> @@ -23,6 +23,10 @@
>
> #define CORE_STR "CORE"
>
> +#ifndef ELF_CORE_EFLAGS
> +#define ELF_CORE_EFLAGS 0
> +#endif
> +
> static int open_kcore(struct inode * inode, struct file * filp)
> {
> return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
> @@ -164,11 +168,7 @@ static void elf_kcore_store_hdr(char *bufp, int nphdr, int dataoff)
> elf->e_entry = 0;
> elf->e_phoff = sizeof(struct elfhdr);
> elf->e_shoff = 0;
> -#if defined(CONFIG_H8300)
> - elf->e_flags = ELF_FLAGS;
> -#else
> - elf->e_flags = 0;
> -#endif
> + elf->e_flags = ELF_CORE_EFLAGS;
> elf->e_ehsize = sizeof(struct elfhdr);
> elf->e_phentsize= sizeof(struct elf_phdr);
> elf->e_phnum = nphdr;
> diff --git a/include/asm-h8300/elf.h b/include/asm-h8300/elf.h
> index 26bfc7e..806f20b 100644
> --- a/include/asm-h8300/elf.h
> +++ b/include/asm-h8300/elf.h
> @@ -32,6 +32,8 @@ typedef unsigned long elf_fpregset_t;
> #define ELF_FLAGS 0x820000
> #endif
>
> +#define ELF_CORE_EFLAGS ELF_FLAGS
> +
> #define ELF_PLAT_INIT(_r) _r->er1 = 0
>
> #define USE_ELF_CORE_DUMP

This will change behaviour on mips, which does

./arch/mips/kernel/binfmt_elfn32.c:#define ELF_CORE_EFLAGS EF_MIPS_ABI2

Ralf, does this fix mips, or break it?

Thanks.

2008-02-14 01:36:49

by Yoshinori Sato

[permalink] [raw]
Subject: Re: [PATCH] Use ELF_CORE_EFLAGS for kcore ELF header flags.

At Tue, 12 Feb 2008 14:34:23 +0100,
Edgar E. Iglesias wrote:
>
> ELF_CORE_EFLAGS is already used by the binfmt_elf coredumper to set correct
> arch specific ELF header flags on coredumps. Use it for kcore aswell.
> This corrects kcore files for the CRIS arch and I beleive it corrects
> ordinary coredumps for the H8/300.
>
> Signed-off-by: Edgar E. Iglesias <[email protected]>
>
> ---
>
> diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
> index e78c81f..c2370c7 100644
> --- a/fs/proc/kcore.c
> +++ b/fs/proc/kcore.c
> @@ -23,6 +23,10 @@
>
> #define CORE_STR "CORE"
>
> +#ifndef ELF_CORE_EFLAGS
> +#define ELF_CORE_EFLAGS 0
> +#endif
> +
> static int open_kcore(struct inode * inode, struct file * filp)
> {
> return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
> @@ -164,11 +168,7 @@ static void elf_kcore_store_hdr(char *bufp, int nphdr, int dataoff)
> elf->e_entry = 0;
> elf->e_phoff = sizeof(struct elfhdr);
> elf->e_shoff = 0;
> -#if defined(CONFIG_H8300)
> - elf->e_flags = ELF_FLAGS;
> -#else
> - elf->e_flags = 0;
> -#endif
> + elf->e_flags = ELF_CORE_EFLAGS;
> elf->e_ehsize = sizeof(struct elfhdr);
> elf->e_phentsize= sizeof(struct elf_phdr);
> elf->e_phnum = nphdr;
> diff --git a/include/asm-h8300/elf.h b/include/asm-h8300/elf.h
> index 26bfc7e..806f20b 100644
> --- a/include/asm-h8300/elf.h
> +++ b/include/asm-h8300/elf.h
> @@ -32,6 +32,8 @@ typedef unsigned long elf_fpregset_t;
> #define ELF_FLAGS 0x820000
> #endif
>
> +#define ELF_CORE_EFLAGS ELF_FLAGS
> +
> #define ELF_PLAT_INIT(_r) _r->er1 = 0
>
> #define USE_ELF_CORE_DUMP

Hmm...
I think more simple.

--- include/asm-h8300/elf.h~ 2008-02-12 17:42:50.000000000 -0500
+++ include/asm-h8300/elf.h 2008-02-13 20:26:58.000000000 -0500
@@ -26,10 +26,10 @@
#define ELF_DATA ELFDATA2MSB
#define ELF_ARCH EM_H8_300
#if defined(__H8300H__)
-#define ELF_FLAGS 0x810000
+#define ELF_CORE_FLAGS 0x810000
#endif
#if defined(__H8300S__)
-#define ELF_FLAGS 0x820000
+#define ELF_CORE_FLAGS 0x820000
#endif

#define ELF_PLAT_INIT(_r) _r->er1 = 0

--
Yoshinori Sato
<[email protected]>

2008-02-14 09:03:46

by Edgar E. Iglesias

[permalink] [raw]
Subject: Re: [PATCH] Use ELF_CORE_EFLAGS for kcore ELF header flags.

On Wed, Feb 13, 2008 at 04:40:45PM -0800, Andrew Morton wrote:
> On Tue, 12 Feb 2008 14:34:23 +0100
> "Edgar E. Iglesias" <[email protected]> wrote:
>
> > ELF_CORE_EFLAGS is already used by the binfmt_elf coredumper to set correct
> > arch specific ELF header flags on coredumps. Use it for kcore aswell.
> > This corrects kcore files for the CRIS arch and I beleive it corrects
> > ordinary coredumps for the H8/300.
> >
> > Signed-off-by: Edgar E. Iglesias <[email protected]>
> >
> > ---
> >
> > diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
> > index e78c81f..c2370c7 100644
> > --- a/fs/proc/kcore.c
> > +++ b/fs/proc/kcore.c
> > @@ -23,6 +23,10 @@
> >
> > #define CORE_STR "CORE"
> >
> > +#ifndef ELF_CORE_EFLAGS
> > +#define ELF_CORE_EFLAGS 0
> > +#endif
> > +
> > static int open_kcore(struct inode * inode, struct file * filp)
> > {
> > return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
> > @@ -164,11 +168,7 @@ static void elf_kcore_store_hdr(char *bufp, int nphdr, int dataoff)
> > elf->e_entry = 0;
> > elf->e_phoff = sizeof(struct elfhdr);
> > elf->e_shoff = 0;
> > -#if defined(CONFIG_H8300)
> > - elf->e_flags = ELF_FLAGS;
> > -#else
> > - elf->e_flags = 0;
> > -#endif
> > + elf->e_flags = ELF_CORE_EFLAGS;
> > elf->e_ehsize = sizeof(struct elfhdr);
> > elf->e_phentsize= sizeof(struct elf_phdr);
> > elf->e_phnum = nphdr;
> > diff --git a/include/asm-h8300/elf.h b/include/asm-h8300/elf.h
> > index 26bfc7e..806f20b 100644
> > --- a/include/asm-h8300/elf.h
> > +++ b/include/asm-h8300/elf.h
> > @@ -32,6 +32,8 @@ typedef unsigned long elf_fpregset_t;
> > #define ELF_FLAGS 0x820000
> > #endif
> >
> > +#define ELF_CORE_EFLAGS ELF_FLAGS
> > +
> > #define ELF_PLAT_INIT(_r) _r->er1 = 0
> >
> > #define USE_ELF_CORE_DUMP
>
> This will change behaviour on mips, which does
>
> ./arch/mips/kernel/binfmt_elfn32.c:#define ELF_CORE_EFLAGS EF_MIPS_ABI2

IIUC, It will not change anything for MIPS. Please note that kcore.c was changed, not fs/binfmt_elf.c.
But I think the mips port should be defining ELF_CORE_EFLAGS in it's asm/elf.h to create kcore files that indicate the correct ABI for n32 kernels.

At the moment, I think a mips n32 kernel will dump cores for userspace programs with the correct EF_MIPS_ABI2 flag but the same kernel will create kcore files with zero eflags (o32).

Best regards
--
Edgar E. Iglesias
Axis Communications AB

2008-02-14 09:40:49

by Edgar E. Iglesias

[permalink] [raw]
Subject: Re: [PATCH] Use ELF_CORE_EFLAGS for kcore ELF header flags.

On Wed, Feb 13, 2008 at 08:36:36PM -0500, Yoshinori Sato wrote:
> At Tue, 12 Feb 2008 14:34:23 +0100,
> Edgar E. Iglesias wrote:
> >
> > ELF_CORE_EFLAGS is already used by the binfmt_elf coredumper to set correct
> > arch specific ELF header flags on coredumps. Use it for kcore aswell.
> > This corrects kcore files for the CRIS arch and I beleive it corrects
> > ordinary coredumps for the H8/300.
>
> Hmm...
> I think more simple.
>
> --- include/asm-h8300/elf.h~ 2008-02-12 17:42:50.000000000 -0500
> +++ include/asm-h8300/elf.h 2008-02-13 20:26:58.000000000 -0500
> @@ -26,10 +26,10 @@
> #define ELF_DATA ELFDATA2MSB
> #define ELF_ARCH EM_H8_300
> #if defined(__H8300H__)
> -#define ELF_FLAGS 0x810000
> +#define ELF_CORE_FLAGS 0x810000
> #endif
> #if defined(__H8300S__)
> -#define ELF_FLAGS 0x820000
> +#define ELF_CORE_FLAGS 0x820000
> #endif

Thanks. In case you already applied this somewhere, please note that it should be ELF_CORE_EFLAGS and not ELF_CORE_FLAGS.

Here's a new patch.

Best regards
--
Edgar E. Iglesias
Axis Communications AB

[PATCH] Use ELF_CORE_EFLAGS for kcore dumps.

ELF_CORE_EFLAGS is already used by the binfmt_elf coredumper to set correct
arch specific ELF header flags on coredumps. Use it for kcore dumps aswell. At
the moment, this affects the CRIS and the H8300 arch.

Signed-off-by: Edgar E. Iglesias <[email protected]>

---

diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
index e78c81f..c2370c7 100644
--- a/fs/proc/kcore.c
+++ b/fs/proc/kcore.c
@@ -23,6 +23,10 @@

#define CORE_STR "CORE"

+#ifndef ELF_CORE_EFLAGS
+#define ELF_CORE_EFLAGS 0
+#endif
+
static int open_kcore(struct inode * inode, struct file * filp)
{
return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
@@ -164,11 +168,7 @@ static void elf_kcore_store_hdr(char *bufp, int nphdr, int dataoff)
elf->e_entry = 0;
elf->e_phoff = sizeof(struct elfhdr);
elf->e_shoff = 0;
-#if defined(CONFIG_H8300)
- elf->e_flags = ELF_FLAGS;
-#else
- elf->e_flags = 0;
-#endif
+ elf->e_flags = ELF_CORE_EFLAGS;
elf->e_ehsize = sizeof(struct elfhdr);
elf->e_phentsize= sizeof(struct elf_phdr);
elf->e_phnum = nphdr;
diff --git a/include/asm-h8300/elf.h b/include/asm-h8300/elf.h
index 26bfc7e..a8b57d1 100644
--- a/include/asm-h8300/elf.h
+++ b/include/asm-h8300/elf.h
@@ -26,10 +26,10 @@ typedef unsigned long elf_fpregset_t;
#define ELF_DATA ELFDATA2MSB
#define ELF_ARCH EM_H8_300
#if defined(__H8300H__)
-#define ELF_FLAGS 0x810000
+#define ELF_CORE_EFLAGS 0x810000
#endif
#if defined(__H8300S__)
-#define ELF_FLAGS 0x820000
+#define ELF_CORE_EFLAGS 0x820000
#endif

#define ELF_PLAT_INIT(_r) _r->er1 = 0