[PATCH 1/2] x86_64: Reflect the relocatability of the kernel in the ELF header.

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Andrew Morton <akpm@...>, Andi Kleen <ak@...>
Cc: <vgoyal@...>, Jurriaan <thunder7@...>, Helge Hafting <helgehaf@...>, <linux-kernel@...>, Magnus Damm <magnus@...>, Horms <horms@...>, <fastboot@...>, Kexec Mailing List <kexec@...>
Date: Monday, April 23, 2007 - 1:12 am

Currently because vmlinux does not reflect that the kernel is relocatable
we still have to support CONFIG_PHYSICAL_START.  So this patch adds a small
c program to do what we cannot do with a linker script, set the elf header
type to ET_DYN.

This should remove the last obstacle to removing CONFIG_PHYSICAL_START
on x86_64.

Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
---
 arch/x86_64/Kconfig  |    4 +++
 arch/x86_64/Makefile |   10 +++++++
 scripts/Makefile     |   11 ++++---
 scripts/mketrel.c    |   70 ++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 90 insertions(+), 5 deletions(-)
 create mode 100644 scripts/mketrel.c

diff --git a/arch/x86_64/Kconfig b/arch/x86_64/Kconfig
index 16d9bf3..773b487 100644
--- a/arch/x86_64/Kconfig
+++ b/arch/x86_64/Kconfig
@@ -121,6 +121,10 @@ config ARCH_HAS_ILOG2_U64
 	bool
 	default n
 
+config ELF_RELOCATABLE
+	bool
+	default y
+
 source "init/Kconfig"
 
 
diff --git a/arch/x86_64/Makefile b/arch/x86_64/Makefile
index 9dd91b2..5ae79ab 100644
--- a/arch/x86_64/Makefile
+++ b/arch/x86_64/Makefile
@@ -124,6 +124,16 @@ define archhelp
   echo  '  isoimage     - Create a boot CD-ROM image'
 endef
 
+ifeq ($(CONFIG_RELOCATABLE),y)
+define cmd_vmlinux__
+      $(LD) $(LDFLAGS) $(LDFLAGS_vmlinux) -o $@ \
+      -T $(vmlinux-lds) $(vmlinux-init)		\
+      --start-group $(vmlinux-main) --end-group	\
+      $(filter-out $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) FORCE ,$^) \
+      && scripts/mketrel $@
+endef
+endif
+
 CLEAN_FILES += arch/$(ARCH)/boot/fdimage \
 	       arch/$(ARCH)/boot/image.iso \
 	       arch/$(ARCH)/boot/mtools.conf
diff --git a/scripts/Makefile b/scripts/Makefile
index 1c73c5a..ddba550 100644
--- a/scripts/Makefile
+++ b/scripts/Makefile
@@ -7,11 +7,12 @@
 # conmakehash:   Create chartable
 # conmakehash:	 Create arrays for initializing the kernel console tables
 
-hostprogs-$(CONFIG_KALLSYMS)     += kallsyms
-hostprogs-$(CONFIG_LOGO)         += pnmtologo
-hostprogs-$(CONFIG_VT)           += conmakehash
-hostprogs-$(CONFIG_PROM_CONSOLE) += conmakehash
-hostprogs-$(CONFIG_IKCONFIG)     += bin2c
+hostprogs-$(CONFIG_KALLSYMS)        += kallsyms
+hostprogs-$(CONFIG_LOGO)            += pnmtologo
+hostprogs-$(CONFIG_VT)              += conmakehash
+hostprogs-$(CONFIG_PROM_CONSOLE)    += conmakehash
+hostprogs-$(CONFIG_IKCONFIG)        += bin2c
+hostprogs-$(CONFIG_ELF_RELOCATABLE) += mketrel
 
 always		:= $(hostprogs-y) $(hostprogs-m)
 
diff --git a/scripts/mketrel.c b/scripts/mketrel.c
new file mode 100644
index 0000000..effa312
--- /dev/null
+++ b/scripts/mketrel.c
@@ -0,0 +1,70 @@
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <elf.h>
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdlib.h>
+
+static int fd;
+unsigned char e_ident[EI_NIDENT];
+
+void die(const char * str, ...)
+{
+	va_list args;
+	va_start(args, str);
+	vfprintf(stderr, str, args);
+	fputc('\n', stderr);
+	exit(1);
+}
+
+void file_open(const char *name)
+{
+	if ((fd = open(name, O_RDWR, 0)) < 0)
+		die("Unable to open `%s': %m", name);
+}
+
+static void mketrel(void)
+{
+	unsigned char e_type[2];
+	if (read(fd, &e_ident, sizeof(e_ident)) != sizeof(e_ident))
+		die("Cannot read ELF header: %s\n", strerror(errno));
+
+	if (memcmp(e_ident, ELFMAG, 4) != 0)
+		die("No ELF magic\n");
+
+	if ((e_ident[EI_CLASS] != ELFCLASS64) &&
+	    (e_ident[EI_CLASS] != ELFCLASS32))
+		die("Unrecognized ELF class: %x\n", e_ident[EI_CLASS]);
+	
+	if ((e_ident[EI_DATA] != ELFDATA2LSB) &&
+	    (e_ident[EI_DATA] != ELFDATA2MSB))
+		die("Unrecognized ELF data encoding: %x\n", e_ident[EI_DATA]);
+
+	if (e_ident[EI_VERSION] != EV_CURRENT)
+		die("Unknown ELF version: %d\n", e_ident[EI_VERSION]);
+
+	if (e_ident[EI_DATA] == ELFDATA2LSB) {
+		e_type[0] = ET_REL & 0xff;
+		e_type[1] = ET_REL >> 8;
+	} else {
+		e_type[1] = ET_REL & 0xff;
+		e_type[0] = ET_REL >> 8;
+	}
+
+	if (write(fd, &e_type, sizeof(e_type)) != sizeof(e_type))
+		die("Cannot write ELF type: %s\n", strerror(errno));
+}
+
+int main(int argc, char **argv)
+{
+	if (argc != 2)
+		die("Usage: mketrel: vmlinux");
+	file_open(argv[1]);
+	mketrel();
+	close(fd);
+	return 0;
+}
-- 
1.5.1.1.181.g2de0

-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
2.6.21-rc5-mm3, Andrew Morton, (Fri Mar 30, 4:05 am)
Re: 2.6.21-rc5-mm3, Dmitry Torokhov, (Fri Mar 30, 12:38 pm)
Re: 2.6.21-rc5-mm3, Andrew Morton, (Fri Mar 30, 12:59 pm)
Re: 2.6.21-rc5-mm3, Michal Piotrowski, (Fri Mar 30, 12:31 pm)
Re: 2.6.21-rc5-mm3, Ingo Molnar, (Fri Mar 30, 12:55 pm)
Re: 2.6.21-rc5-mm3, Michal Piotrowski, (Fri Mar 30, 1:19 pm)
Re: 2.6.21-rc5-mm3, Michal Piotrowski, (Sun Apr 1, 12:00 pm)
Re: 2.6.21-rc5-mm3, Andrew Morton, (Sun Apr 1, 3:03 pm)
Re: 2.6.21-rc5-mm3, Rafael J. Wysocki, (Sun Apr 1, 4:39 pm)
Re: 2.6.21-rc5-mm3, Rafael J. Wysocki, (Sun Apr 1, 5:59 pm)
Re: 2.6.21-rc5-mm3, Rafael J. Wysocki, (Sun Apr 1, 4:56 pm)
Re: [2.6 patch] remove the config option for the cs5530a_war..., Jeremy Fitzhardinge, (Sat Mar 31, 5:05 pm)
Re: [2.6 patch] remove the config option for the cs5530a_war..., Jeremy Fitzhardinge, (Sat Mar 31, 5:17 pm)
2.6.21-rc5-mm3: Why was my vioc cleanup patch dropped?, Adrian Bunk, (Sat Mar 31, 3:25 pm)
Re: 2.6.21-rc5-mm3 - no boot, "address not 2M aligned", Helge Hafting, (Sat Mar 31, 3:12 am)
Re: 2.6.21-rc5-mm3 - no boot, "address not 2M aligned", Andrew Morton, (Sat Mar 31, 3:53 am)
Re: 2.6.21-rc5-mm3 - no boot, "address not 2M aligned", Eric W. Biederman, (Sat Mar 31, 4:14 am)
Re: 2.6.21-rc5-mm3 - no boot, "address not 2M aligned", Helge Hafting, (Mon Apr 9, 6:09 pm)
Re: 2.6.21-rc5-mm3 - no boot, "address not 2M aligned", Helge Hafting, (Tue Apr 10, 12:48 am)
Re: 2.6.21-rc5-mm3 - no boot, "address not 2M aligned", Eric W. Biederman, (Sun Apr 1, 2:15 am)
Re: 2.6.21-rc5-mm3 - no boot, "address not 2M aligned", Andrew Morton, (Sun Apr 1, 2:29 am)
Re: 2.6.21-rc5-mm3 - no boot, "address not 2M aligned", Eric W. Biederman, (Mon Apr 2, 4:43 am)
Re: 2.6.21-rc5-mm3 - no boot, "address not 2M aligned", Eric W. Biederman, (Mon Apr 2, 1:26 pm)
Re: 2.6.21-rc5-mm3 - no boot, "address not 2M aligned", Vivek Goyal, (Tue Apr 3, 12:01 am)
Re: 2.6.21-rc5-mm3 - no boot, "address not 2M aligned", Eric W. Biederman, (Tue Apr 3, 1:23 am)
[PATCH 1/2] x86_64: Reflect the relocatability of the kernel..., Eric W. Biederman, (Mon Apr 23, 1:12 am)
Re: [PATCH 1/2] x86_64: Reflect the relocatability of the ke..., Eric W. Biederman, (Tue Apr 24, 3:21 am)
[PATCH 2/2] x86_64: Remove CONFIG_PHYSICAL_START and CONFIG_..., Eric W. Biederman, (Mon Apr 23, 1:15 am)
Re: [PATCH 2/2] x86_64: Remove CONFIG_PHYSICAL_START and CON..., Eric W. Biederman, (Mon Apr 23, 2:17 am)
Re: 2.6.21-rc5-mm3 - no boot, "address not 2M aligned", Vivek Goyal, (Tue Apr 3, 12:05 am)
Re: 2.6.21-rc5-mm3, , (Fri Mar 30, 1:23 pm)
Re: 2.6.21-rc5-mm3, Johannes Berg, (Fri Mar 30, 2:58 pm)
Re: 2.6.21-rc5-mm3, Rafael J. Wysocki, (Fri Mar 30, 7:00 am)