Page 1 of 1
Error loading uncompressed kernel without PVH ELF Note
Posted: Thu Apr 11, 2019 5:24 am
by mephostophilez
So I followed the Bare Bones tutorial (using nasm as the assembler). Using GNU make for building.
Everything builds fine, but when trying to run qemu with the built kernel binary, this happens:
Code: Select all
$ qemu-system-i386 -kernel bin/kernel.bin
C:\Program Files\qemu\qemu-system-i386.exe: Error loading uncompressed kernel without PVH ELF Note
I have very little to none experience with OS Development.
There's no results when searching this error message. Help would be much appreciated.
Re: Error loading uncompressed kernel without PVH ELF Note
Posted: Fri Apr 12, 2019 2:24 am
by glauxosdever
Hi,
How are you building the kernel? Specifically, are you using a cross compiler? I'd assume your system compiler creates PE output (as you seem to be on Windows), and probably does other things that don't work for a freestanding executable.
Regards,
glauxosdever
Re: Error loading uncompressed kernel without PVH ELF Note
Posted: Fri Apr 12, 2019 6:30 am
by songziming
`-kernel` requires bzImage or multiboot format kernel. Either make it ELF or provide your address fields of multiboot header.
Use `-f elf` to make NASM generate ELF format objects, and use ld to link them.
Re: Error loading uncompressed kernel without PVH ELF Note
Posted: Fri Apr 12, 2019 9:36 am
by mephostophilez
glauxosdever wrote:
How are you building the kernel? Specifically, are you using a cross compiler? I'd assume your system compiler creates PE output (as you seem to be on Windows), and probably does other things that don't work for a freestanding executable.
I'm using the precompiled i686-elf toolchain thing (
https://github.com/lordmilko/i686-elf-tools). I don't know if that's ok, but it seems to run fine.
My Makefile:
Code: Select all
GCCPARAMS = -std=gnu99 -ffreestanding -O2 -Wall -Wextra
NASMPARAMS = -f elf32
LINKERPARAMS = -ffreestanding -O2 -nostdlib -lgcc
cobjects = $(patsubst src/%.c,objects/%.o,$(wildcard src/*.c))
asmobjects = $(patsubst src/%.asm,objects/%.o,$(wildcard src/*.asm))
objects = $(cobjects) $(asmobjects)
objects/%.o: src/%.c
i686-elf/bin/i686-elf-gcc $(GCCPARAMS) -o $@ -c $<
objects/%.o: src/%.asm
nasm $(NASMPARAMS) $< -o $@
bin/kernel.bin: src/linker.ld $(objects)
i686-elf/bin/i686-elf-gcc -T $< -o $@ $(objects) $(LINKERPARAMS)
songziming wrote:
`-kernel` requires bzImage or multiboot format kernel. Either make it ELF or provide your address fields of multiboot header.
I'm confused. So it's either make it ELF
or have the multiboot header? I have the multiboot header defined so it should be there.
I don't know what you mean by "provide address fields".
songziming wrote:
Use `-f elf` to make NASM generate ELF format objects, and use ld to link them.
I'm doing just that. I've originally had a typo in the nasm command, I was using `-felf32` (without the space) but it doesn't seem to behave any different now that I've changed it.
Should I use ld for linking though? The tutorial suggests using i686-elf-gcc.
Sorry if I'm missing some obvious points and thanks for understanding. I've thrown myself into OS development with little background.
Re: Error loading uncompressed kernel without PVH ELF Note
Posted: Fri Apr 12, 2019 11:24 am
by pistachio
If you are building using a cross-compiler toolchain, ensure that you are using the same to link the format. I see you have a linker script, it'd be helpful to post that as well.
If you do have a valid multi boot header declared, you can either link it as a flat binary or as an ELF file. Use "i686-elf-ld" to link, and then make sure that nasm is using the correct ELF format.
Re: Error loading uncompressed kernel without PVH ELF Note
Posted: Fri Apr 12, 2019 12:26 pm
by mephostophilez
My linker script is just the tutorial code:
Code: Select all
ENTRY(_start)
SECTIONS
{
. = 1M;
.text BLOCK(4K) : ALIGN(4K)
{
*(.multiboot)
*(.text)
}
.rodata BLOCK(4K) : ALIGN(4K)
{
*(.rodata)
}
.data BLOCK(4K) : ALIGN(4K)
{
*(.data)
}
.bss BLOCK(4K) : ALIGN(4K)
{
*(COMMON)
*(.bss)
}
}
Re: Error loading uncompressed kernel without PVH ELF Note
Posted: Sat Apr 13, 2019 1:31 am
by Octocontrabass
mephostophilez wrote:Should I use ld for linking though? The tutorial suggests using i686-elf-gcc.
Some versions of GCC recommend using gcc to link instead of ld due to limitations in binutils. I can't think of any reason why you would ever need to use ld instead of gcc to link, so it's fine to keep doing what you're doing.
Based on the error message from QEMU, it sounds like your kernel doesn't have a working multiboot header. How did you define your multiboot header?
Re: Error loading uncompressed kernel without PVH ELF Note
Posted: Sun Apr 28, 2019 10:54 pm
by theDude
DISCLAIMER: I am dumb and may be missing the obvious.
This is not a multiboot entry issue.
This looks like an issue due to a somewhat recent change in the Qemu code base. From what I can tell in the source code, they are looking for a special PT_NOTE entry within the list of Program Header entries, I think...
They (Qemu) have glue code magic to generate the 32/64-bit elf decode functions, i.e., load_elf32(), which makes finding the source code quite difficult, but it's there.
https://github.com/qemu/qemu/blob/3e29d ... /elf_ops.h
I originally thought they were just looking for a general PT_NOTE Section with their magic value (0x12), but I think they are targeting the Program Header list of entries.
I'm not savvy enough to specify this new entry minimally through the link script/boot file(?).
This operation is apparently performed in the Linux source, but that ELFNOTE macro makes a fool of me.
Re: Error loading uncompressed kernel without PVH ELF Note
Posted: Tue Apr 30, 2019 11:22 pm
by theDude
If you are running QEMU on Windows, install the i386 emulator built before 2019. I used the Nov. 28 '18 build.
https://www.qemu.org/download/#windows
These versions don't include the new PVH/ABI changes and will run correctly with the '-kernel' flag with your ELF binary.
I don't know what is up with those newer Windows QEMU binaries. I was able to add the correct PT_NOTE entry in my kernel bin, with the correct entry address, but QEMU would fail to find the note about 25% of the time, and when it did, it looked liked the processor just kept resetting.
Re: Error loading uncompressed kernel without PVH ELF Note
Posted: Fri Jul 26, 2019 10:34 am
by devin122
Just wanted to post an update here for people like me who find this thread trying to fix the issue. The broken PVH ELF Note handling can be bypassed by passing
on the commandline
Re: Error loading uncompressed kernel without PVH ELF Note
Posted: Wed Sep 04, 2019 10:27 pm
by theDude
Haven't checked the spec, but is there a flag to specify that this image shouldn't load unless the host understands all NOTES?
Re: Error loading uncompressed kernel without PVH ELF Note
Posted: Tue May 20, 2025 6:00 am
by nekosu
In my case, it is because some sections are not mentioned in my linker script, causing them to be placed before .text section. Thus grub cannot find .multiboot, as it is not in the first 8K of the image.
Use `readelf -WSl your-kernel` to check the sections.
The kernel that fails before:
Code: Select all
.rodata : ALIGN(4K)
{
*(.rodata) <---- .rodata not matching .rodata.str1.1, at least for llvm lld.
}
Code: Select all
$ llvm-readelf -WSl kernel
There are 19 section headers, starting at offset 0x4274:
Section Headers:
[Nr] Name Type Address Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .rodata.str1.1 PROGBITS 00100000 001000 00001a 01 AMS 0 0 1 <---- .rodata section misplaced here
[ 2] .text PROGBITS 00101000 002000 0001c7 00 AX 0 0 4096
[ 3] .text._ZN6kernel4copyIPtEEvT_S2_S2_ PROGBITS 001011d0 0021d0 000034 00 AX 0 0 16
[ 4] .bss NOBITS 00102000 003000 004010 00 WA 0 0 4096
[ 5] .debug_abbrev PROGBITS 00000000 003000 0001a8 00 0 0 1
...
Then, according to this post, I change it as follow.
viewtopic.php?t=13331&start=45
Code: Select all
.rodata : ALIGN(4K)
{
*(.rodata*)
}
Code: Select all
$ llvm-readelf -WSl kernel
There are 19 section headers, starting at offset 0x4270:
Section Headers:
[Nr] Name Type Address Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .text PROGBITS 00100000 001000 0001c7 00 AX 0 0 4096 <---- ok, .text is the first one
[ 2] .text._ZN6kernel4copyIPtEEvT_S2_S2_ PROGBITS 001001d0 0011d0 000034 00 AX 0 0 16
[ 3] .rodata PROGBITS 00101000 002000 00001a 01 AMS 0 0 4096
After applying this fix, I've been able to boot my kernel even without the option mentioned above.
Re: Error loading uncompressed kernel without PVH ELF Note
Posted: Fri May 23, 2025 6:13 am
by AnotherIdiot
Using -kernel does not work for multiboot2 or 1 images for me even with that, but I would recommend just making a grub image or something else with grub-mkrescue or the equ for whatever that bootloader does.