Skip to contentSkip to conversation

ELF64 header on i386

PATCH In review Bernhard Walle 4 participants 6 messages Jul 2, 2007 – Jul 27, 2007

Subsystems (2)
lore
Share & tools
lore
#1 lore raw
Quoted 7 lines · Bernhard Walle

Hello,

why creates kexec-tools ELF64 headers per default on i386? Wouldn't it make more sense to look if a physical address exceeds the 32-bit limit and then switch to ELF64 automatically if the user doesn't have specified an option?

I am aware of one issue, that gdb on i386 is not able to analyse ELF64 formatted kdump though "crash" can.

Thanks
Maneesh

Signature · 9 lines
Maneesh Soni
Linux Technology Center,
IBM India Systems and Technology Lab, 
Bangalore, India

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#2 lore raw

PATCH 1/1 Determine ELF32/ELF64 automatically on i386

In reply to Bernhard Walle

On i386, kexec generates ELF64 core headers by default if the user doesn't override this via a command line option. Because GDB cannot analyse ELF64 core dumps on 32 bit platforms, it's a bad idea to use ELF64 if it's not needed.

This patch selects ELF32 if the biggest memory address fits in 32 bit address space, which should be the case on non PAE systems. If the user specifies a command line option, that option overrides the detection.

---
 kexec/arch/i386/crashdump-x86.c |   26 ++++++++++++++++++++++++++
 kexec/arch/i386/kexec-x86.c     |    2 +-
 kexec/arch/i386/kexec-x86.h     |   20 ++++++++++++--------
 3 files changed, 39 insertions(+), 9 deletions(-)
kexec/arch/i386/crashdump-x86.c +26 -0
@@ -486,6 +486,23 @@ static struct crash_elf_info elf_info32 
 	get_note_info: get_crash_notes,
 };
 
+static enum CoreType get_core_type(struct kexec_info *info,
+				   struct memory_range *range, int ranges)
+{
+	if (info->kexec_flags & KEXEC_ARCH_X86_64)
+		return CORE_TYPE_ELF64;
+	else {
+		/* fall back to default */
+		if (ranges == 0)
+			return CORE_TYPE_ELF64;
+
+		if (range[ranges].end > 0xFFFFFFFFUL)
+			return CORE_TYPE_ELF64;
+		else
+			return CORE_TYPE_ELF32;
+	}
+}
+
 /* Loads additional segments in case of a panic kernel is being loaded.
  * One segment for backup region, another segment for storing elf headers
  * for crash memory image.
@@ -501,6 +518,15 @@ int load_crashdump_segments(struct kexec
 	if (get_crash_memory_ranges(&mem_range, &nr_ranges) < 0)
 		return -1;
 
+	/*
+	 * if the core type has not been set on command line, set it here
+	 * automatically
+	 */
+	if (arch_options.core_header_type == CORE_TYPE_UNDEF) {
+		arch_options.core_header_type =
+			get_core_type(info, mem_range, nr_ranges);
+	}
+
 	/* Memory regions which panic kernel can safely use to boot into */
 	sz = (sizeof(struct memory_range) * (KEXEC_MAX_SEGMENTS + 1));
 	memmap_p = xmalloc(sz);
kexec/arch/i386/kexec-x86.c +1 -1
@@ -145,7 +145,7 @@ struct arch_options_t arch_options = {
 	.serial_baud = 0,
 	.console_vga = 0,
 	.console_serial = 0,
-	.core_header_type = CORE_TYPE_ELF64,
+	.core_header_type = CORE_TYPE_UNDEF,
 };
 
 int arch_process_options(int argc, char **argv)
kexec/arch/i386/kexec-x86.h +12 -8
@@ -2,8 +2,12 @@
 #define KEXEC_X86_H
 
 #define MAX_MEMORY_RANGES 64
-#define CORE_TYPE_ELF32 1
-#define CORE_TYPE_ELF64 2
+
+enum CoreType {
+	CORE_TYPE_UNDEF = 0,
+	CORE_TYPE_ELF32 = 1,
+	CORE_TYPE_ELF64 = 2
+};
 
 extern unsigned char compat_x86_64[];
 extern uint32_t compat_x86_64_size, compat_x86_64_entry32;
@@ -40,12 +44,12 @@ struct entry16_regs {
 };
 
 struct arch_options_t {
-	uint8_t  reset_vga;
-	uint16_t serial_base;
-	uint32_t serial_baud;
-	uint8_t  console_vga;
-	uint8_t  console_serial;
-	int	 core_header_type;
+	uint8_t  	reset_vga;
+	uint16_t 	serial_base;
+	uint32_t 	serial_baud;
+	uint8_t  	console_vga;
+	uint8_t  	console_serial;
+	enum CoreType	core_header_type;
 };
 
 int multiboot_x86_probe(const char *buf, off_t len);

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#3 lore raw

Re: [PATCH] Determine ELF32/ELF64 automatically on i386

Quoted 9 lines · Bernhard Walle

On i386, kexec generates ELF64 core headers by default if the user doesn't override this via a command line option. Because GDB cannot analyse ELF64 core dumps on 32 bit platforms, it's a bad idea to use ELF64 if it's not needed.

This patch selects ELF32 if the biggest memory address fits in 32 bit address space, which should be the case on non PAE systems. If the user specifies a command line option, that option overrides the detection.

Makes sense to me. No need to generate 64bit ELF headers on systems having less than 4G of memory. gdb runs into issues with 64bit ELF headers on 32bit machines.

Quoted 4 lines

+++ b/kexec/arch/i386/kexec-x86.h

kexec/arch/i386/kexec-x86.h +0 -0
@@ -2,8 +2,12 @@
 #define KEXEC_X86_H
 

kexec/arch/i386/kexec-x86.h line 11

Quoted 10 lines
kexec/arch/i386/kexec-x86.h +6 -2
 #define MAX_MEMORY_RANGES 64
-#define CORE_TYPE_ELF32 1
-#define CORE_TYPE_ELF64 2
+
+enum CoreType {
+	CORE_TYPE_UNDEF = 0,
+	CORE_TYPE_ELF32 = 1,
+	CORE_TYPE_ELF64 = 2
+};
 

I think we can avoid mixed case in "CoreType" and use something like "coretype".

Thanks
Vivek

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#4 lore raw

Re: [PATCH] Determine ELF32/ELF64 automatically on i386

Quoted 6 lines · Vivek Goyal
Quoted 5 lines · Bernhard Walle

On i386, kexec generates ELF64 core headers by default if the user doesn't override this via a command line option. Because GDB cannot analyse ELF64 core dumps on 32 bit platforms, it's a bad idea to use ELF64 if it's not needed.

Quoted 8 lines
Quoted 4 lines

This patch selects ELF32 if the biggest memory address fits in 32 bit address space, which should be the case on non PAE systems. If the user specifies a command line option, that option overrides the detection.

Makes sense to me. No need to generate 64bit ELF headers on systems having less than 4G of memory. gdb runs into issues with 64bit ELF headers on 32bit machines.

Exaclty that was my point.

Quoted 2 lines

I think we can avoid mixed case in "CoreType" and use something like "coretype".

Of course:

----

[PATCH] Determine ELF32/ELF64 automatically on i386

On i386, kexec generates ELF64 core headers by default if the user doesn't override this via a command line option. Because GDB cannot analyse ELF64 core dumps on 32 bit platforms, it's a bad idea to use ELF64 if it's not needed.

This patch selects ELF32 if the biggest memory address fits in 32 bit address space, which should be the case on non PAE systems. If the user specifies a command line option, that option overrides the detection.

---
 kexec/arch/i386/crashdump-x86.c |   26 ++++++++++++++++++++++++++
 kexec/arch/i386/kexec-x86.c     |    2 +-
 kexec/arch/i386/kexec-x86.h     |   20 ++++++++++++--------
 3 files changed, 39 insertions(+), 9 deletions(-)
kexec/arch/i386/crashdump-x86.c +26 -0
@@ -486,6 +486,23 @@ static struct crash_elf_info elf_info32 
 	get_note_info: get_crash_notes,
 };
 
+static enum coretype get_core_type(struct kexec_info *info,
+				   struct memory_range *range, int ranges)
+{
+	if (info->kexec_flags & KEXEC_ARCH_X86_64)
+		return CORE_TYPE_ELF64;
+	else {
+		/* fall back to default */
+		if (ranges == 0)
+			return CORE_TYPE_ELF64;
+
+		if (range[ranges].end > 0xFFFFFFFFUL)
+			return CORE_TYPE_ELF64;
+		else
+			return CORE_TYPE_ELF32;
+	}
+}
+
 /* Loads additional segments in case of a panic kernel is being loaded.
  * One segment for backup region, another segment for storing elf headers
  * for crash memory image.
@@ -501,6 +518,15 @@ int load_crashdump_segments(struct kexec
 	if (get_crash_memory_ranges(&mem_range, &nr_ranges) < 0)
 		return -1;
 
+	/*
+	 * if the core type has not been set on command line, set it here
+	 * automatically
+	 */
+	if (arch_options.core_header_type == CORE_TYPE_UNDEF) {
+		arch_options.core_header_type =
+			get_core_type(info, mem_range, nr_ranges);
+	}
+
 	/* Memory regions which panic kernel can safely use to boot into */
 	sz = (sizeof(struct memory_range) * (KEXEC_MAX_SEGMENTS + 1));
 	memmap_p = xmalloc(sz);
kexec/arch/i386/kexec-x86.c +1 -1
@@ -145,7 +145,7 @@ struct arch_options_t arch_options = {
 	.serial_baud = 0,
 	.console_vga = 0,
 	.console_serial = 0,
-	.core_header_type = CORE_TYPE_ELF64,
+	.core_header_type = CORE_TYPE_UNDEF,
 };
 
 int arch_process_options(int argc, char **argv)
kexec/arch/i386/kexec-x86.h +12 -8
@@ -2,8 +2,12 @@
 #define KEXEC_X86_H
 
 #define MAX_MEMORY_RANGES 64
-#define CORE_TYPE_ELF32 1
-#define CORE_TYPE_ELF64 2
+
+enum coretype {
+	CORE_TYPE_UNDEF = 0,
+	CORE_TYPE_ELF32 = 1,
+	CORE_TYPE_ELF64 = 2
+};
 
 extern unsigned char compat_x86_64[];
 extern uint32_t compat_x86_64_size, compat_x86_64_entry32;
@@ -40,12 +44,12 @@ struct entry16_regs {
 };
 
 struct arch_options_t {
-	uint8_t  reset_vga;
-	uint16_t serial_base;
-	uint32_t serial_baud;
-	uint8_t  console_vga;
-	uint8_t  console_serial;
-	int	 core_header_type;
+	uint8_t  	reset_vga;
+	uint16_t 	serial_base;
+	uint32_t 	serial_baud;
+	uint8_t  	console_vga;
+	uint8_t  	console_serial;
+	enum coretype	core_header_type;
 };
 
 int multiboot_x86_probe(const char *buf, off_t len);

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#5 lore raw

Re: [PATCH] Determine ELF32/ELF64 automatically on i386

Quoted 27 lines · Bernhard Walle
Quoted 6 lines · Vivek Goyal
Quoted 5 lines · Bernhard Walle

On i386, kexec generates ELF64 core headers by default if the user doesn't override this via a command line option. Because GDB cannot analyse ELF64 core dumps on 32 bit platforms, it's a bad idea to use ELF64 if it's not needed.

Quoted 8 lines
Quoted 4 lines

This patch selects ELF32 if the biggest memory address fits in 32 bit address space, which should be the case on non PAE systems. If the user specifies a command line option, that option overrides the detection.

Makes sense to me. No need to generate 64bit ELF headers on systems having less than 4G of memory. gdb runs into issues with 64bit ELF headers on 32bit machines.

Exaclty that was my point.

Quoted 2 lines

I think we can avoid mixed case in "CoreType" and use something like "coretype".

Of course:

----

[PATCH] Determine ELF32/ELF64 automatically on i386

Quoted 8 lines

On i386, kexec generates ELF64 core headers by default if the user doesn't override this via a command line option. Because GDB cannot analyse ELF64 core dumps on 32 bit platforms, it's a bad idea to use ELF64 if it's not needed.

This patch selects ELF32 if the biggest memory address fits in 32 bit address space, which should be the case on non PAE systems. If the user specifies a command line option, that option overrides the detection.

Sorry for being slow, I missed the patch earlier as it wasn't CCed to me. I have applied it now.

Signature · 9 lines
Horms
  H: http://www.vergenet.net/~horms/
  W: http://www.valinux.co.jp/en/


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec