Problem with loading 64-bit ELF image with multiboot2
Hello,
I use x86 64-bit GRUB2 under EFI and would like to load 64-bit ELF image. The image looks as following:
$ objdump -h Image
Image: file format elf64-x86-64
Sections:
Idx Name Size VMA LMA File off Algn 0 .text 0019d870 ffffffff90008000 0000000010008000
00000120 2**5
CONTENTS, ALLOC, LOAD, CODE
1 .wrs_build_vars 00000150 ffffffff901a5870 00000000101a58700019d990 2**0
CONTENTS, ALLOC, LOAD, READONLY, DATA
2 .data 0000db50 ffffffff901a59c0 00000000101a59c00019db00 2**6
CONTENTS, ALLOC, LOAD, DATA
3 .bss 01016e40 ffffffff901b3520 00000000101b3520001ab660 2**5
ALLOC
$ objdump -f Image
Image: file format elf64-x86-64
architecture: i386:x86-64, flags 0x00000012:EXEC_P, HAS_SYMS
start address 0xffffffff90008000
I tried to load it via GRUB2, but unfortunately it displays 'invalid entry point for ELF64'. The problem is that for 64-bit ELF images the multiboot_elfxx.c library still requires 32-bit virtual address:
#ifdef MULTIBOOT_LOAD_ELF64
# if defined( __mips)
/* We still in 32-bit mode. */
if (ehdr->e_entry < 0xffffffff80000000ULL)
return grub_error (GRUB_ERR_BAD_OS, "invalid entry point for ELF64");
# else
/* We still in 32-bit mode. */
if (ehdr->e_entry > 0xffffffff)
return grub_error (GRUB_ERR_BAD_OS, "invalid entry point for ELF64");
# endif
#endifCould you tell me why this assumption is required? The virtual address (e_entry is virtual following ELF specification) is related to the image itself, how it setup MMU, not the loader (GRUB2). GRUB2 should check only if the physical location of loaded image is in 32-bit physical memory.
Besides if we skip thich e_entry check, the image is properly loaded, because grub_multiboot_payload_eip is properly computed few lines below.
grub_multiboot_payload_eip = (ehdr->e_entry - phdr(i)->p_vaddr)
+ phdr(i)->p_paddr;
Could you tell me why GRUB2 checks for 64-bit images this e_entry virtual address (which can be everywhere in the 64-bit address space) and requires it to be 32-bit address space only?
Regards
Pawel Wojtalczyk
Quoted 5 lines · Pawel Wojtalczyk
Hello,
I use x86 64-bit GRUB2 under EFI and would like to load 64-bit ELF image. The image looks as following:
Rather than bringing the issue once more time in a different place, look that this was already fixed in trunk.
Quoted 65 lines
$ objdump -h ImageImage: file format elf64-x86-64
Sections:
Idx Name Size VMA LMA File
off Algn
0 .text0019d870ffffffff900080000000000010008000
00000120 2**5
CONTENTS, ALLOC, LOAD, CODE
1 .wrs_build_vars 00000150ffffffff901a587000000000101a58700019d9902**0
CONTENTS, ALLOC, LOAD, READONLY, DATA
2 .data0000db50ffffffff901a59c000000000101a59c00019db002**6
CONTENTS, ALLOC, LOAD, DATA
3 .bss01016e40ffffffff901b352000000000101b3520001ab6602**5
ALLOC$ objdump -f ImageImage: file format elf64-x86-64
architecture: i386:x86-64, flags0x00000012:EXEC_P,HAS_SYMS
start address0xffffffff90008000I tried to load it via GRUB2, but unfortunately it displays 'invalid entry point for ELF64'. The problem is that for 64-bit ELF images the
multiboot_elfxx.clibrary still requires 32-bit virtual address:#ifdef
MULTIBOOT_LOAD_ELF64# if defined( __mips) /* We still in 32-bit mode. */ if (ehdr->e_entry < 0xffffffff80000000ULL) return grub_error (GRUB_ERR_BAD_OS, "invalid entry point for ELF64"); # else /* We still in 32-bit mode. */ if (ehdr->e_entry > 0xffffffff) return grub_error (GRUB_ERR_BAD_OS, "invalid entry point for ELF64"); # endif #endifCould you tell me why this assumption is required? The virtual address (
e_entryis virtual following ELF specification) is related to the image itself, how it setup MMU, not the loader (GRUB2). GRUB2 should check only if the physical location of loaded image is in 32-bit physical memory.Besides if we skip thich
e_entrycheck, the image is properly loaded, becausegrub_multiboot_payload_eipis properly computed few lines below.
grub_multiboot_payload_eip= (ehdr->e_entry- phdr(i)->p_vaddr)
+ phdr(i)->p_paddr;Could you tell me why GRUB2 checks for 64-bit images this
e_entryvirtual address (which can be everywhere in the 64-bit address space) and requires it to be 32-bit address space only?Regards
Pawel Wojtalczyk_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Hello Vladimir,
I just do not understand current implementation and would not discuss as a bug, because you rejected this issue as a bug.
But I see that you have modified the code to allow loading 64-bit ELFs linked in high address and did not received the notification about it.
Thank you.
Regards
Pawel
Quoted 80 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 5 lines · Pawel Wojtalczyk
Hello,
I use x86 64-bit GRUB2 under EFI and would like to load 64-bit ELF image. The image looks as following:
Rather than bringing the issue once more time in a different place, look that this was already fixed in trunk.
Quoted 57 lines
$ objdump -h ImageImage: file format elf64-x86-64
Sections:
Idx Name Size VMA LMA File
off Algn
0 .text0019d870ffffffff900080000000000010008000 00000120 2**5
CONTENTS, ALLOC, LOAD, CODE
1 .wrs_build_vars 00000150ffffffff901a587000000000101a58700019d9902**0
CONTENTS, ALLOC, LOAD, READONLY, DATA
2 .data0000db50ffffffff901a59c000000000101a59c00019db002**6
CONTENTS, ALLOC, LOAD, DATA
3 .bss01016e40ffffffff901b352000000000101b3520001ab6602**5
ALLOC$ objdump -f ImageImage: file format elf64-x86-64
architecture: i386:x86-64, flags0x00000012:EXEC_P,HAS_SYMS
start address0xffffffff90008000I tried to load it via GRUB2, but unfortunately it displays 'invalid entry point for ELF64'. The problem is that for 64-bit ELF images the
multiboot_elfxx.clibrary still requires 32-bit virtual address:#ifdef
MULTIBOOT_LOAD_ELF64# if defined( __mips) /* We still in 32-bit mode. */ if (ehdr->e_entry < 0xffffffff80000000ULL) return grub_error (GRUB_ERR_BAD_OS, "invalid entry point for ELF64"); # else /* We still in 32-bit mode. */ if (ehdr->e_entry > 0xffffffff) return grub_error (GRUB_ERR_BAD_OS, "invalid entry point for ELF64"); # endif #endifCould you tell me why this assumption is required? The virtual address (
e_entryis virtual following ELF specification) is related to the image itself, how it setup MMU, not the loader (GRUB2). GRUB2 should check only if the physical location of loaded image is in 32-bit physical memory.Besides if we skip thich
e_entrycheck, the image is properly loaded, becausegrub_multiboot_payload_eipis properly computed few lines below.
grub_multiboot_payload_eip= (ehdr->e_entry- phdr(i)->p_vaddr)
+ phdr(i)->p_paddr;Could you tell me why GRUB2 checks for 64-bit images this
e_entryvirtual address (which can be everywhere in the 64-bit address space) and requires it to be 32-bit address space only?Quoted 8 lines
Regards
Pawel Wojtalczyk_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel