Switching from LD to LLD causes QEMU to crash.

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
ffexl
Posts: 1
Joined: Wed Apr 23, 2025 11:16 pm

Switching from LD to LLD causes QEMU to crash.

Post by ffexl »

For reference, I am using Clang for my toolchain.

In my CMake file, I am currently using LD with:

Code: Select all

set(CMAKE_EXE_LINKER_FLAGS "-v -T ${CMAKE_SOURCE_DIR}/${LINKER} -ffreestanding -fno-pie -nostdlib -z notext")
This works in QEMU.

I want to use LLD with:

Code: Select all

set(CMAKE_EXE_LINKER_FLAGS "-v -fuse-ld=lld -Wl,-T,${CMAKE_SOURCE_DIR}/${LINKER} -fno-pie -ffreestanding -nostdlib -Wl,-z,notext -static")
This completely bricks my kernel with the QEMU message:

Code: Select all

qemu-system-i386: Error loading uncompressed kernel without PVH ELF Note logout
(For some reason, CMake INSISTS on using gcc for the linking phase, and won't let me use clang, no matter what I do. While I can use LLD as my linker, I can't force CMake to execute LLD with clang.)

How do I fix this error and utilize LLD without it bricking the kernel?
Last edited by ffexl on Fri Apr 25, 2025 3:41 pm, edited 1 time in total.
Octocontrabass
Member
Member
Posts: 5822
Joined: Mon Mar 25, 2013 7:01 pm

Re: Switching from LD to LLD causes QEMU to crash.

Post by Octocontrabass »

That message means QEMU can't find your kernel's Multiboot header. Fixing it will depend on what's wrong, though.

If LLD has inserted a bunch of padding, add "-Wl,-z,max-page-size=0x1000" to the options you use for linking.

If LLD has moved or discarded the section containing the Multiboot header even though your linker script should prevent that from happening, make sure the section is marked allocatable in your source code.

If it's neither of those, we'll need more information.
Post Reply