grub/grub-core/loader
Daniel Kiper a620876e3b multiboot2: Add support for relocatable images
Currently multiboot2 protocol loads image exactly at address specified in
ELF or multiboot2 header. This solution works quite well on legacy BIOS
platforms. It is possible because memory regions are placed at predictable
addresses (though I was not able to find any spec which says that it is
strong requirement, so, it looks that it is just a goodwill of hardware
designers). However, EFI platforms are more volatile. Even if required
memory regions live at specific addresses then they are sometimes simply
not free (e.g. used by boot/runtime services on Dell PowerEdge R820 and
OVMF). This means that you are not able to just set up final image
destination on build time. You have to provide method to relocate image
contents to real load address which is usually different than load address
specified in ELF and multiboot2 headers.

This patch provides all needed machinery to do self relocation in image code.
First of all GRUB2 reads min_addr (min. load addr), max_addr (max. load addr),
align (required image alignment), preference (it says which memory regions are
preferred by image, e.g. none, low, high) from multiboot_header_tag_relocatable
header tag contained in binary (at this stage load addresses from multiboot2
and/or ELF headers are ignored). Later loader tries to fulfill request (not only
that one) and if it succeeds then it informs image about real load address via
multiboot_tag_load_base_addr tag. At this stage GRUB2 role is finished. Starting
from now executable must cope with relocations itself using whole static and
dynamic knowledge provided by boot loader.

This patch does not provide functionality which could do relocations using
ELF relocation data. However, I was asked by Konrad Rzeszutek Wilk and Vladimir
'phcoder' Serbinenko to investigate that thing. It looks that relevant machinery
could be added to existing code (including this patch) without huge effort.
Additionally, ELF relocation could live in parallel with self relocation provided
by this patch. However, during research I realized that first of all we should
establish the details how ELF relocatable image should look like and how it should
be build. At least to build proper test/example files.

So, this patch just provides support for self relocatable images. If ELF file
with relocs is loaded then GRUB2 complains loudly and ignores it. Support for
such files will be added later.

This patch was tested with Xen image which uses that functionality. However, this Xen
feature is still under development and new patchset will be released in about 2-3 weeks.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Vladimir Serbinenko <phcoder@gmail.com>
2016-10-27 15:55:16 +02:00
..
arm Use full initializer for initrd_ctx to avoid fatal warnings with older GCC 2014-10-14 20:12:15 +04:00
arm64 xen_boot: Remove obsolete module type distinctions. 2016-01-22 10:18:47 +01:00
efi chainloader: fix resoource leak 2015-06-26 09:25:30 +03:00
i386 multiboot2: Add support for relocatable images 2016-10-27 15:55:16 +02:00
ia64/efi Use full initializer for initrd_ctx to avoid fatal warnings with older GCC 2014-10-14 20:12:15 +04:00
mips Use full initializer for initrd_ctx to avoid fatal warnings with older GCC 2014-10-14 20:12:15 +04:00
powerpc/ieee1275 Use full initializer for initrd_ctx to avoid fatal warnings with older GCC 2014-10-14 20:12:15 +04:00
sparc64/ieee1275 OBP available region contains grub. Start at grub_phys_end. 2016-02-12 23:16:03 +01:00
aout.c Implement automatic module license checking according to new GNU 2011-04-11 23:01:51 +02:00
linux.c loader/linux: Make trailer initrd entry aligned again. 2015-07-20 19:07:20 +03:00
lzss.c Add LZSS Mach-O support (needed for new xnu kernelcache). 2012-02-29 13:26:13 +01:00
macho.c Add missing license section in macbless.mod and macho.mod. 2013-12-18 17:11:11 +01:00
macho32.c * grub-core/loader/machoXX.c: Fix compilation on non-i386. 2013-12-17 22:44:46 +01:00
macho64.c * grub-core/loader/machoXX.c: Fix compilation on non-i386. 2013-12-17 22:44:46 +01:00
machoXX.c Simplify few strings. 2013-05-07 11:44:15 +02:00
multiboot.c multiboot2: Add support for relocatable images 2016-10-27 15:55:16 +02:00
multiboot_elfxx.c multiboot2: Add support for relocatable images 2016-10-27 15:55:16 +02:00
multiboot_mbi2.c multiboot2: Add support for relocatable images 2016-10-27 15:55:16 +02:00
xnu.c loader/xnu: fix memory leak. 2015-01-27 22:12:06 +03:00
xnu_resume.c * grub-core/loader/xnu_resume.c (grub_xnu_resume): Reject empty images. 2013-10-28 14:25:22 +01:00