qemu doesnt run .elf file, needs PVH ELF note

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
thegremlin
Posts: 1
Joined: Sun May 23, 2021 3:09 pm

qemu doesnt run .elf file, needs PVH ELF note

Post by thegremlin »

I am following Zesterer's Barebones tutorial (https://wiki.osdev.org/User:Zesterer/Bare_Bones)and i am now trying to run the .elf file produced using qemu

Whenever i run the command

Code: Select all

qemu-system-i386 -kernel mykernel.elf
i get the error

Code: Select all

qemu-system-i386: Error loading uncompressed kernel without PVH ELF Note
while i thing that i understand why this is happening, i do not know how to fix it, and the suggestions i found online about using the flag

Code: Select all

-machine type=pc-i440fx-3.1
had qemu try to boot from rom indefinitely

how can i solve this problem? thank you in advance
User avatar
acccidiccc
Member
Member
Posts: 38
Joined: Sun Mar 21, 2021 1:09 pm
Location: current location

Re: qemu doesnt run .elf file, needs PVH ELF note

Post by acccidiccc »

is your kernel mulitboot compliant? qemu caused the same message when I gave it a non multiboot kernel. I can replicate your problem with my own non multiboot compilant kernel. apparently pvh is a boot protocol. QEMU probably only supports some boot protocols. apparently somebody got the same message with the linux kernel, which uses its own protocol.

Code: Select all

grub-file --is-x86-multiboot mykernel.elf

put it in the makefile. if it cause an error 1. it is not compliant. did you copy paste or type from hand. maybe a typo?
probably this will return a negative code. if not, that is pretty weird.
iustitiae iniustos iudicat
f23yg
Posts: 1
Joined: Mon Aug 16, 2021 1:29 am

Re: qemu doesnt run .elf file, needs PVH ELF note

Post by f23yg »

I tried to slove this problem by modifying the link scritp file linker.ld and everything worked fine. If anybody know why, please tell me.I just simply move multiboot header from rodata area to text area. The version of binutil and gcc is 2.37 and 11.2.0 respectively.

Code: Select all

* The bootloader will start execution at the symbol designated as the entry point. In this case, that's 'start' (defined in start.s) */                                                                   
ENTRY(start)                                                                    
                                                                                
/* Tell the linker part of the compiler where the various sections of the kernel will be put in the final kernel executable. */
SECTIONS                                                                        
{                                                                               
    /* Begin putting sections at 1 Megabyte (1M), a good place for kernels to be loaded at by the bootloader. */
    /* This is because memory below 1 Megabyte is reserved for other x86-related things, so we can't use it */
    . = 1M;                                                                     
                                                                                
    /* We align all sections in the executable at multiples of 4 Kilobytes (4K). This will become useful later in development when we add paging */
                                                                                
    /* First put the multiboot header, as it's required to be near the start of the executable otherwise the bootloader won't find it */
    /* The Multiboot header is Read-Only data, so we can put it in a '.rodata' section. */
    .text BLOCK(4K) : ALIGN(4K)                                                 
    {                                                                           
        *(.multiboot)                                                           
        *(.text)                                                                
    }                                                                           
                                                                                
    /* Read-only data. */                                                       
    .rodata BLOCK(4K) : ALIGN(4K)                                               
    {                                                                           
        *(.rodata)                                                              
    }                                                                           
                                                                                
    /* Read-write data (initialized) */                                         
    .data BLOCK(4K) : ALIGN(4K)                                                 
    {                                                                           
        *(.data)                                                                
    }                                                                           
                                                                                
    /* Read-write data (uninitialized) and stack */                             
    .bss BLOCK(4K) : ALIGN(4K)                                                  
    {                                                                           
        *(COMMON)                                                               
        *(.bss)                                                                 
    }                                                                           
}                                                                               
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: qemu doesnt run .elf file, needs PVH ELF note

Post by Octocontrabass »

f23yg wrote:If anybody know why, please tell me.
The Multiboot header must be contained completely within the first 8192 bytes of the OS image. When you tried to move it to the .rodata section, it ended up outside the first 8192 bytes, so QEMU couldn't find it.
Post Reply