Skip to contentSkip to conversation

generic ELF loading (updated)

PATCH In review Hollis Blanchard 2 participants 5 messages Oct 27, 2006 – Oct 30, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 generic ELF loading (updated)

Here is the updated ELF loading infrastructure. A couple notes:

It is now a module, which will be auto-loaded by loaders that need it. However, I don't know where to put elf.c. The only similar files are io/gzio.c and fs/fshelp.c, but clearly elf.c doesn't belong in either of those directories.

I have not updated i386/pc/multiboot.c to use this. That file needs refactoring for multiboot2 anyways, so the work I'm doing for multiboot2 will replace that loader.

Comments please. Also see next mail to see how the PPC Linux loader uses it.

(Sorry about the .mk noise.)

-Hollis

conf/i386-efi.mk +3 -3
Index: grub2-cvs/conf/i386-efi.mk
===================================================================
@@ -486,9 +486,9 @@ fs-kernel_mod-disk_efi_efidisk.lst: disk
 	set -e; 	  $(TARGET_CC) -Idisk/efi -I$(srcdir)/disk/efi $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) $(kernel_mod_CFLAGS) -E $< 	  | sh $(srcdir)/genfslist.sh kernel > $@ || (rm -f $@; exit 1)
 
 
-kernel_mod_HEADERS = arg.h boot.h device.h disk.h dl.h elf.h env.h err.h \
-	file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h partition.h \
-	pc_partition.h rescue.h symbol.h term.h types.h \
+kernel_mod_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h \
+	env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \
+	partition.h pc_partition.h rescue.h symbol.h term.h types.h \
 	i386/efi/time.h efi/efi.h efi/time.h efi/disk.h
 kernel_mod_CFLAGS = $(COMMON_CFLAGS)
 kernel_mod_ASFLAGS = $(COMMON_ASFLAGS)
conf/i386-efi.rmk +5 -4
Index: grub2-cvs/conf/i386-efi.rmk
===================================================================
@@ -43,7 +43,8 @@ grub_emu_SOURCES = commands/boot.c comma
 	fs/affs.c fs/ext2.c fs/fat.c fs/fshelp.c fs/hfs.c fs/iso9660.c	\
 	fs/jfs.c fs/minix.c fs/sfs.c fs/ufs.c fs/xfs.c fs/hfsplus.c	\
 	io/gzio.c							\
-	kern/device.c kern/disk.c kern/dl.c kern/env.c kern/err.c 	\
+	kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c	\
+	kern/err.c							\
 	normal/execute.c kern/file.c kern/fs.c normal/lexer.c 		\
 	kern/loader.c kern/main.c kern/misc.c kern/parser.c		\
 	grub_script.tab.c kern/partition.c kern/rescue.c kern/term.c	\
@@ -76,9 +77,9 @@ kernel_mod_SOURCES = kern/i386/efi/start
 	kern/i386/dl.c kern/i386/efi/init.c kern/parser.c kern/partition.c \
 	kern/env.c symlist.c kern/efi/efi.c kern/efi/init.c kern/efi/mm.c \
 	term/efi/console.c disk/efi/efidisk.c
-kernel_mod_HEADERS = arg.h boot.h device.h disk.h dl.h elf.h env.h err.h \
-	file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h partition.h \
-	pc_partition.h rescue.h symbol.h term.h types.h \
+kernel_mod_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h \
+	env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \
+	partition.h pc_partition.h rescue.h symbol.h term.h types.h \
 	i386/efi/time.h efi/efi.h efi/time.h efi/disk.h
 kernel_mod_CFLAGS = $(COMMON_CFLAGS)
 kernel_mod_ASFLAGS = $(COMMON_ASFLAGS)
conf/i386-pc.mk +3 -3
Index: grub2-cvs/conf/i386-pc.mk
===================================================================
@@ -162,9 +162,9 @@ kernel_img-symlist.o: symlist.c
 	$(TARGET_CC) -I. -I$(srcdir)/. $(TARGET_CPPFLAGS)  $(TARGET_CFLAGS) $(kernel_img_CFLAGS) -MD -c -o $@ $<
 -include kernel_img-symlist.d
 
-kernel_img_HEADERS = arg.h boot.h device.h disk.h dl.h elf.h env.h err.h \
-	file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h partition.h \
-	pc_partition.h rescue.h symbol.h term.h types.h \
+kernel_img_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h \
+	env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \
+	partition.h pc_partition.h rescue.h symbol.h term.h types.h \
 	machine/biosdisk.h machine/boot.h machine/console.h machine/init.h \
 	machine/memory.h machine/loader.h machine/time.h machine/vga.h \
 	machine/vbe.h
conf/i386-pc.rmk +5 -4
Index: grub2-cvs/conf/i386-pc.rmk
===================================================================
@@ -30,9 +30,9 @@ kernel_img_SOURCES = kern/i386/pc/startu
 	kern/env.c disk/i386/pc/biosdisk.c \
 	term/i386/pc/console.c \
 	symlist.c
-kernel_img_HEADERS = arg.h boot.h device.h disk.h dl.h elf.h env.h err.h \
-	file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h partition.h \
-	pc_partition.h rescue.h symbol.h term.h types.h \
+kernel_img_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h \
+	env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \
+	partition.h pc_partition.h rescue.h symbol.h term.h types.h \
 	machine/biosdisk.h machine/boot.h machine/console.h machine/init.h \
 	machine/memory.h machine/loader.h machine/time.h machine/vga.h \
 	machine/vbe.h
@@ -89,7 +89,8 @@ grub_emu_SOURCES = commands/boot.c comma
 	fs/affs.c fs/ext2.c fs/fat.c fs/fshelp.c fs/hfs.c fs/iso9660.c	\
 	fs/jfs.c fs/minix.c fs/sfs.c fs/ufs.c fs/xfs.c fs/hfsplus.c	\
 	io/gzio.c							\
-	kern/device.c kern/disk.c kern/dl.c kern/env.c kern/err.c 	\
+	kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c	\
+	kern/err.c							\
 	normal/execute.c kern/file.c kern/fs.c normal/lexer.c 		\
 	kern/loader.c kern/main.c kern/misc.c kern/parser.c		\
 	grub_script.tab.c kern/partition.c kern/rescue.c kern/term.c	\
conf/powerpc-ieee1275.mk +25 -21

95 lines not on this page · raw message

conf/powerpc-ieee1275.rmk +9 -9
Index: grub2-cvs/conf/powerpc-ieee1275.rmk
===================================================================
@@ -10,11 +10,10 @@ COMMON_LDFLAGS += -nostdlib
 MOSTLYCLEANFILES += kernel_elf_symlist.c kernel_syms.lst
 DEFSYMFILES += kernel_syms.lst
 
-kernel_elf_HEADERS = arg.h boot.h device.h disk.h dl.h elf.h env.h err.h \
-	file.h fs.h kernel.h misc.h mm.h net.h parser.h rescue.h symbol.h \
-	term.h types.h powerpc/libgcc.h loader.h \
-	partition.h pc_partition.h ieee1275/ieee1275.h machine/time.h \
-	machine/kernel.h
+kernel_elf_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h \
+	env.h err.h file.h fs.h kernel.h misc.h mm.h net.h parser.h rescue.h \
+	symbol.h term.h types.h powerpc/libgcc.h loader.h partition.h \
+	pc_partition.h ieee1275/ieee1275.h machine/time.h machine/kernel.h
 
 kernel_elf_symlist.c: $(addprefix include/grub/,$(kernel_elf_HEADERS)) config.h gensymlist.sh
 	/bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1)
@@ -45,9 +44,10 @@ grub_emu_SOURCES = commands/boot.c comma
 	fs/affs.c fs/ext2.c fs/fat.c fs/fshelp.c fs/hfs.c fs/iso9660.c	\
 	fs/jfs.c fs/minix.c fs/sfs.c fs/ufs.c fs/xfs.c fs/hfsplus.c	\
 	io/gzio.c							\
-	kern/device.c kern/disk.c kern/dl.c kern/env.c kern/err.c 	\
-	kern/file.c kern/fs.c kern/loader.c kern/main.c kern/misc.c	\
-	kern/parser.c kern/partition.c kern/rescue.c kern/term.c	\
+	kern/device.c kern/disk.c kern/dl.c kern/elf.c kern/env.c	\
+	kern/err.c kern/file.c kern/fs.c kern/loader.c kern/main.c	\
+	kern/misc.c kern/parser.c kern/partition.c kern/rescue.c	\
+	kern/term.c							\
 	normal/arg.c normal/cmdline.c normal/command.c			\
 	normal/completion.c normal/execute.c		 		\
 	normal/function.c normal/lexer.c normal/main.c normal/menu.c 	\
@@ -62,7 +62,7 @@ grub_emu_LDFLAGS = $(LIBCURSES)
 
 kernel_elf_SOURCES = kern/powerpc/ieee1275/crt0.S kern/powerpc/ieee1275/cmain.c \
 	kern/ieee1275/ieee1275.c kern/main.c kern/device.c 		\
-	kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c 		\
+	kern/disk.c kern/dl.c kern/err.c kern/file.c kern/fs.c 		\
 	kern/misc.c kern/mm.c kern/loader.c kern/rescue.c kern/term.c 	\
 	kern/powerpc/ieee1275/init.c term/ieee1275/ofconsole.c 		\
 	kern/powerpc/ieee1275/openfw.c disk/ieee1275/ofdisk.c 		\
conf/sparc64-ieee1275.mk +4 -5
Index: grub2-cvs/conf/sparc64-ieee1275.mk
===================================================================
@@ -10,11 +10,10 @@ COMMON_LDFLAGS = -melf64_sparc -nostdlib
 MOSTLYCLEANFILES += kernel_elf_symlist.c kernel_syms.lst
 DEFSYMFILES += kernel_syms.lst
 
-kernel_elf_HEADERS = arg.h boot.h device.h disk.h dl.h elf.h env.h err.h \
-	file.h fs.h kernel.h misc.h mm.h net.h parser.h rescue.h symbol.h \
-	term.h types.h sparc64/libgcc.h loader.h \
-	partition.h pc_partition.h ieee1275/ieee1275.h machine/time.h \
-	machine/kernel.h
+kernel_elf_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h \
+	env.h err.h file.h fs.h kernel.h misc.h mm.h net.h parser.h rescue.h \
+	symbol.h term.h types.h sparc64/libgcc.h loader.h partition.h \
+	pc_partition.h ieee1275/ieee1275.h machine/time.h machine/kernel.h
 
 kernel_elf_symlist.c: $(addprefix include/grub/,$(kernel_elf_HEADERS)) config.h gensymlist.sh
 	/bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1)
conf/sparc64-ieee1275.rmk +4 -5
Index: grub2-cvs/conf/sparc64-ieee1275.rmk
===================================================================
@@ -10,11 +10,10 @@ COMMON_LDFLAGS = -melf64_sparc -nostdlib
 MOSTLYCLEANFILES += kernel_elf_symlist.c kernel_syms.lst
 DEFSYMFILES += kernel_syms.lst
 
-kernel_elf_HEADERS = arg.h boot.h device.h disk.h dl.h elf.h env.h err.h \
-	file.h fs.h kernel.h misc.h mm.h net.h parser.h rescue.h symbol.h \
-	term.h types.h sparc64/libgcc.h loader.h \
-	partition.h pc_partition.h ieee1275/ieee1275.h machine/time.h \
-	machine/kernel.h
+kernel_elf_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h \
+	env.h err.h file.h fs.h kernel.h misc.h mm.h net.h parser.h rescue.h \
+	symbol.h term.h types.h sparc64/libgcc.h loader.h partition.h \
+	pc_partition.h ieee1275/ieee1275.h machine/time.h machine/kernel.h
 
 kernel_elf_symlist.c: $(addprefix include/grub/,$(kernel_elf_HEADERS)) config.h gensymlist.sh
 	/bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1)
include/grub/elfload.h new file +58 -0

58 lines not on this page · raw message

kern/elf.c new file +289 -0

289 lines not on this page · raw message

conf/common.rmk +6 -1
Index: grub2-cvs/conf/common.rmk
===================================================================
@@ -213,7 +213,12 @@ blocklist_mod_CFLAGS = $(COMMON_CFLAGS)
 blocklist_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
 # Misc.
-pkgdata_MODULES += gzio.mod 
+pkgdata_MODULES += gzio.mod elf.mod
+
+# For elf.mod.
+elf_mod_SOURCES = kern/elf.c
+elf_mod_CFLAGS = $(COMMON_CFLAGS)
+elf_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
 # For gzio.mod.
 gzio_mod_SOURCES = io/gzio.c
#1 lore raw
Quoted 2 lines · Hollis Blanchard

Comments please. Also see next mail to see how the PPC Linux loader uses it.

So this still loads an image to paddr directly, right?

I think we need these features:

- an ability to pass an address to load an image

- an ability to pass the size of a loading area

- an ability to get the size of a loaded image

Okuji

#2 lore raw
Quoted 6 lines · Yoshinori K. Okuji
Quoted 2 lines · Hollis Blanchard

Comments please. Also see next mail to see how the PPC Linux loader uses it.

So this still loads an image to paddr directly, right?

Quoted 7 lines

I think we need these features:

- an ability to pass an address to load an image

- an ability to pass the size of a loading area

- an ability to get the size of a loaded image

The PowerPC loader patch I sent already does 1 and 3, and you can easily see how 2 can be done in the exact same way. Please look at that code, in particular 'calcsize' and 'offset_paddr'.

-Hollis

#3 lore raw
Quoted 11 lines · Hollis Blanchard
Quoted 10 lines · Yoshinori K. Okuji
Quoted 2 lines · Hollis Blanchard

Comments please. Also see next mail to see how the PPC Linux loader uses it.

So this still loads an image to paddr directly, right?

I think we need these features:

- an ability to pass an address to load an image

Quoted 7 lines
Quoted 3 lines

- an ability to pass the size of a loading area

- an ability to get the size of a loaded image

The PowerPC loader patch I sent already does 1 and 3, and you can easily see how 2 can be done in the exact same way. Please look at that code, in particular 'calcsize' and 'offset_paddr'.

As for calcsize, I do not think it is a good idea to put this to architecture-specific code. We always need this feature, so it should be a part of the API.

As for offset_paddr, I do not like modifying a member of a header. This changes a read value, so the state of a header changes after calling grub_elf*_load. This kind of side effect often makes debugging harder. I prefer to specify an address more explicitly.

Okuji

#4 lore raw
Quoted 20 lines · Yoshinori K. Okuji
Quoted 11 lines · Hollis Blanchard
Quoted 10 lines · Yoshinori K. Okuji
Quoted 2 lines · Hollis Blanchard

Comments please. Also see next mail to see how the PPC Linux loader uses it.

So this still loads an image to paddr directly, right?

I think we need these features:

- an ability to pass an address to load an image

Quoted 7 lines
Quoted 3 lines

- an ability to pass the size of a loading area

- an ability to get the size of a loaded image

The PowerPC loader patch I sent already does 1 and 3, and you can easily see how 2 can be done in the exact same way. Please look at that code, in particular 'calcsize' and 'offset_paddr'.

Quoted 8 lines

As for calcsize, I do not think it is a good idea to put this to architecture-specific code. We always need this feature, so it should be a part of the API.

As for offset_paddr, I do not like modifying a member of a header. This changes a read value, so the state of a header changes after calling grub_elf*_load. This kind of side effect often makes debugging harder. I prefer to specify an address more explicitly.

What exactly would you suggest? Using a hook to modify the struct phdr (or veto it) seems quite elegant to me.

-Hollis