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_target_properties(${KERNEL_BIN} PROPERTIES LINK_FLAGS "-T ${CMAKE_SOURCE_DIR}/${LINKER} -ffreestanding -nostdlib")
This works in QEMU.

I want to use LLD with:

Code: Select all

set_target_properties(${KERNEL_BIN} PROPERTIES LINK_FLAGS "-Wl,-T,${CMAKE_SOURCE_DIR}/${LINKER} -fuse-ld=lld -ffreestanding -nostdlib -static")
In my linker.ld, (default linker.ld from https://wiki.osdev.org/Bare_Bones#Linking_the_Kernel) LLD requires me to change the BLOCK(4K) directives to ALIGN(4K) directives because BLOCK() isn't supported by LLD (I have been told that BLOCK() and ALIGN() are equivalent) This completely bricks my kernel with the QEMU message:

Code: Select all

qemu-system-i386: Error loading uncompressed kernel without PVH ELF Note logout
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: Wed Apr 23, 2025 11:55 pm
by ffexl
I actually used the ALIGN() replacements for BLOCK() with LD, and it still ran in QEMU. The problem seems to be with the arguments passed to LLD, not the replacements made in linker.ld.