Page 1 of 1

Switching from LD to LLD causes QEMU to crash.

Posted: Wed Apr 23, 2025 11:26 pm
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?

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

Posted: Mon Apr 28, 2025 11:02 am
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.