Skip to contentSkip to conversation

cleanup elf_core_dump(): remove ELF_CORE_EXTRA_* macro

RFC PATCH In review Daisuke HATAYAMA 4 participants 6 messages Dec 15, 2009 – Dec 16, 2009

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

RFC PATCH 1/4 cleanup elf_core_dump(): remove ELF_CORE_EXTRA_* macro

elf_core_dump() uses #ifdef and the corresponding macro for hiding _multiline_ logics in functions. This patch removes #ifdef and replaces ELF_CORE_EXTRA_* by corresponding functions. For architectures not implemeonting ELF_CORE_EXTRA_*, we use weak functions in order to reduce a range of modification.

This cleanup is for my next patches, but I think this cleanup itself is worth doing regardless of my firnal purpose.

---
 arch/ia64/kernel/Makefile  |    2 +
 arch/ia64/kernel/elfcore.c |   75 ++++++++++++++++++++++++++++++++++++++++++
 arch/um/sys-i386/Makefile  |    2 +
 arch/um/sys-i386/elfcore.c |   78 ++++++++++++++++++++++++++++++++++++++++++++
 fs/binfmt_elf.c            |   36 +++++++++++++++-----
 include/linux/elf.h        |    2 +
 6 files changed, 186 insertions(+), 9 deletions(-)
 create mode 100644 arch/ia64/kernel/elfcore.c
 create mode 100644 arch/um/sys-i386/elfcore.c
arch/ia64/kernel/Makefile +2 -0
index 6b7edca..5e8d09a 100644
@@ -51,6 +51,8 @@ endif
 obj-$(CONFIG_DMAR)		+= pci-dma.o
 obj-$(CONFIG_SWIOTLB)		+= pci-swiotlb.o
 
+obj-$(CONFIG_BINFMT_ELF)	+= elfcore.o
+
 # fp_emulate() expects f2-f5,f16-f31 to contain the user-level state.
 CFLAGS_traps.o  += -mfixed-range=f2-f5,f16-f31
 
arch/ia64/kernel/elfcore.c new file +75 -0

75 lines not on this page · raw message

arch/um/sys-i386/Makefile +2 -0
index 1b549bc..804b28d 100644
@@ -6,6 +6,8 @@ obj-y = bug.o bugs.o checksum.o delay.o fault.o ksyms.o ldt.o ptrace.o \
 	ptrace_user.o setjmp.o signal.o stub.o stub_segv.o syscalls.o sysrq.o \
 	sys_call_table.o tls.o
 
+obj-$(CONFIG_BINFMT_ELF) += elfcore.o
+
 subarch-obj-y = lib/semaphore_32.o lib/string_32.o
 subarch-obj-$(CONFIG_HIGHMEM) += mm/highmem_32.o
 subarch-obj-$(CONFIG_MODULES) += kernel/module.o
arch/um/sys-i386/elfcore.c new file +78 -0

78 lines not on this page · raw message

fs/binfmt_elf.c +27 -9
index b9b3bb5..5f7be51 100644
@@ -1900,6 +1900,28 @@ static struct vm_area_struct *next_vma(struct vm_area_struct *this_vma,
 }
 
 /*
+ * It's been implemented that some architectures write out some extra
+ * data into segments. On the other hand, other architechtures use
+ * these dummy functions and hence do nothing.
+ */
+Elf_Half __weak elf_core_extra_phdrs(void)
+{
+	return 0;
+}
+
+int __weak elf_core_write_extra_phdrs(struct file *file, loff_t offset,
+				      size_t *size, unsigned long limit)
+{
+	return 1;
+}
+
+int __weak elf_core_write_extra_data(struct file *file, size_t *size,
+				     unsigned long limit)
+{
+	return 1;
+}
+
+/*
  * Actual dumper
  *
  * This is a two-pass process; first we find the offsets of the bits,
@@ -1939,9 +1961,7 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un
 	 * Please check DEFAULT_MAX_MAP_COUNT definition when you modify here.
 	 */
 	segs = current->mm->map_count;
-#ifdef ELF_CORE_EXTRA_PHDRS
-	segs += ELF_CORE_EXTRA_PHDRS;
-#endif
+	segs += elf_core_extra_phdrs();
 
 	gate_vma = get_gate_vma(current);
 	if (gate_vma != NULL)
@@ -2009,9 +2029,8 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un
 		DUMP_WRITE(&phdr, sizeof(phdr));
 	}
 
-#ifdef ELF_CORE_WRITE_EXTRA_PHDRS
-	ELF_CORE_WRITE_EXTRA_PHDRS;
-#endif
+	if (!elf_core_write_extra_phdrs(file, offset, &size, limit))
+		goto end_coredump;
 
  	/* write out the notes section */
 	if (!write_note_info(&info, file, &foffset))
@@ -2049,9 +2068,8 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un
 		}
 	}
 
-#ifdef ELF_CORE_WRITE_EXTRA_DATA
-	ELF_CORE_WRITE_EXTRA_DATA;
-#endif
+	if (!elf_core_write_extra_data(file, &size, limit))
+		goto end_coredump;
 
 end_coredump:
 	set_fs(fs);
include/linux/elf.h +2 -0
index 90a4ed0..d103127 100644
@@ -386,6 +386,7 @@ extern Elf32_Dyn _DYNAMIC [];
 #define elf_phdr	elf32_phdr
 #define elf_note	elf32_note
 #define elf_addr_t	Elf32_Off
+#define Elf_Half	Elf32_Half
 
 #else
 
@@ -394,6 +395,7 @@ extern Elf64_Dyn _DYNAMIC [];
 #define elf_phdr	elf64_phdr
 #define elf_note	elf64_note
 #define elf_addr_t	Elf64_Off
+#define Elf_Half	Elf64_Half
 
 #endif
 
Signature · 1 line
1.6.5.1
#1 lore raw
Quoted 10 lines · Daisuke HATAYAMA

elf_core_dump() uses #ifdef and the corresponding macro for hiding _multiline_ logics in functions. This patch removes #ifdef and replaces ELF_CORE_EXTRA_* by corresponding functions. For architectures not implemeonting ELF_CORE_EXTRA_*, we use weak functions in order to reduce a range of modification.

This cleanup is for my next patches, but I think this cleanup itself is worth doing regardless of my firnal purpose.

Good patch! I like it!

Just one problem below.

arch/um/sys-i386/elfcore.c line 10

Quoted 13 lines
arch/um/sys-i386/elfcore.c new file +10 -0
@@ -0,0 +1,78 @@
+#include <linux/elf.h>
+#include <linux/fs.h>
+#include <linux/mm.h>
+
+#include <asm/elf.h>
+
+static int dump_write(struct file *file, const void *addr, int nr)
+{
+       return file->f_op->write(file, addr, nr, &file->f_pos) == nr;
+}

We already have the same dump_write() in fs/binfmt_elf.c, can't we reuse it? e.g. moving it to a header and make it staic inline.

Thanks!

#2 lore raw
Quoted 19 lines
Quoted 10 lines · Daisuke HATAYAMA

elf_core_dump() uses #ifdef and the corresponding macro for hiding _multiline_ logics in functions. This patch removes #ifdef and replaces ELF_CORE_EXTRA_* by corresponding functions. For architectures not implemeonting ELF_CORE_EXTRA_*, we use weak functions in order to reduce a range of modification.

This cleanup is for my next patches, but I think this cleanup itself is worth doing regardless of my firnal purpose.

Good patch! I like it!

Just one problem below.

Quoted 16 lines

arch/um/sys-i386/elfcore.c line 10

Quoted 13 lines
arch/um/sys-i386/elfcore.c new file +10 -0
@@ -0,0 +1,78 @@
+#include <linux/elf.h>
+#include <linux/fs.h>
+#include <linux/mm.h>
+
+#include <asm/elf.h>
+
+static int dump_write(struct file *file, const void *addr, int nr)
+{
+       return file->f_op->write(file, addr, nr, &file->f_pos) == nr;
+}

We already have the same dump_write() in fs/binfmt_elf.c, can't we reuse it? e.g. moving it to a header and make it staic inline.

Thanks for you comment.

I understand what you say.

I think now I will move it to include/linux/elfcore.h.

Quoted 2 lines

Thanks!

#3 lore raw
In reply to Daisuke HATAYAMA

arch/um/sys-i386/elfcore.c

Quoted 6 lines · Daisuke HATAYAMA

subarch-obj-$(CONFIG_MODULES) += kernel/module.o

arch/um/sys-i386/elfcore.c new file +0 -0
new file mode 100644
index 0000000..4e320f0

No code for real x86?

-Andi

Signature · 1 line
[email protected] -- Speaking for myself only.
#4 lore raw
In reply to Daisuke HATAYAMA
Quoted 9 lines · Daisuke HATAYAMA

elf_core_dump() uses #ifdef and the corresponding macro for hiding _multiline_ logics in functions. This patch removes #ifdef and replaces ELF_CORE_EXTRA_* by corresponding functions. For architectures not implemeonting ELF_CORE_EXTRA_*, we use weak functions in order to reduce a range of modification.

This cleanup is for my next patches, but I think this cleanup itself is worth doing regardless of my firnal purpose.

Quoted 8 lines
---
 arch/ia64/kernel/Makefile  |    2 +
 arch/ia64/kernel/elfcore.c |   75 ++++++++++++++++++++++++++++++++++++++++++
 arch/um/sys-i386/Makefile  |    2 +
 arch/um/sys-i386/elfcore.c |   78 ++++++++++++++++++++++++++++++++++++++++++++
 fs/binfmt_elf.c            |   36 +++++++++++++++-----
 include/linux/elf.h        |    2 +

Hmm, why don't you remove ELF_CORE_EXTRA_* macros too?? And also, you have to update fs/binfmt_elf_fdpic.c too.

Thank you,

Signature · 7 lines
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America), Inc.
Software Solutions Division

e-mail: [email protected]
#5 lore raw

From: Masami Hiramatsu <[email protected]>
Subject: Re: [RFC, PATCH 1/4] cleanup elf_core_dump(): remove ELF_CORE_EXTRA_* macro
Date: Tue, 15 Dec 2009 10:14:21 -0500

Quoted 20 lines
Quoted 9 lines · Daisuke HATAYAMA

elf_core_dump() uses #ifdef and the corresponding macro for hiding _multiline_ logics in functions. This patch removes #ifdef and replaces ELF_CORE_EXTRA_* by corresponding functions. For architectures not implemeonting ELF_CORE_EXTRA_*, we use weak functions in order to reduce a range of modification.

This cleanup is for my next patches, but I think this cleanup itself is worth doing regardless of my firnal purpose.

Quoted 8 lines
---
 arch/ia64/kernel/Makefile  |    2 +
 arch/ia64/kernel/elfcore.c |   75 ++++++++++++++++++++++++++++++++++++++++++
 arch/um/sys-i386/Makefile  |    2 +
 arch/um/sys-i386/elfcore.c |   78 ++++++++++++++++++++++++++++++++++++++++++++
 fs/binfmt_elf.c            |   36 +++++++++++++++-----
 include/linux/elf.h        |    2 +
Quoted 4 lines

Hmm, why don't you remove ELF_CORE_EXTRA_* macros too?? And also, you have to update fs/binfmt_elf_fdpic.c too.

Thank you,

The reason relates to the fact that elf_core_extra_* functions for architectures with no extra data are defined as the weak ones. As I've written in the patch description, they are useful to reduce a range of modification.

If I modify fs/binfmt_elf.c, I need to prepare another file in order for binfmt_elf{,_fdpic}.c to share the weak functions. (Now the week functions are defined in fs/binfmt_elf.c.)

The problem is that I don't know where to put new file elfcore.c for weak functions. I am not familiar with such convension.

For example, is it right to put fs/elfcore.c or kernel/elfcore.c?

Thanks.