Search code examples
buildld

ld - output file is empty


I am trying to write a kernel in assembly and C++ (I'm still on assembly right now), and I'm loading it with GRUB. So far, everything works fine, except for linking. I'm using ld, and even though the input files are not empty, it produces an empty binary.

Here is my build script:

@echo off
nasm -f elf64 multiboot_header.asm
nasm -f elf64 boot.asm
ld --nmagic --output=kernel.bin --script=linker.ld multiboot_header.o boot.o
move /Y kernel.bin isofiles/boot/kernel.bin
wsl grub-mkrescue -o os.iso isofiles
rem del *.o

and my linker.ld script:

ENTRY(start)

SECTIONS {
    . = 1M;

    .boot :
    {
        /* ensure that the multiboot header is at the beginning */
        *(.multiboot_header)
    }

    .text :
    {
        *(.text)
    }
}

EDIT: I was accidentally using ld from MinGW, instead of from Linux gcc.


Solution

  • As you said: Accidentally using ld.exe from MinGW can cause this to happen (as opposed to the ld.exe from Linux gcc)