LLVM's LD.LLD Doesn't Understand BLOCK(4K)

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
flyingplastic
Posts: 2
Joined: Thu Dec 10, 2020 10:51 am

LLVM's LD.LLD Doesn't Understand BLOCK(4K)

Post by flyingplastic »

Dear All,

I've been trying to rebuild the X86 Bare Bones tutorial, but this time using LLVM toolchain instead of using GCC. Boot.s & kernel.c compiled, but when using linker (ld.lld), it says it doesn't understand BLOCK(4K). I've tried removing the BLOCK(4K) to just ALIGN (4K) in the linker.ld, which compiled this time, but when booted by QEMU (using GRUB) it's not recognized as multiboot and not loaded.

PS: Building it all using GCC cross-compile i686-elf was successful, not fuss on that, and booted correctly. Only using LLVM toolchain (clang & ld.lld) didn't end up as well as GCC.
2nd note: I used ld.lld directly (and indeed ld when compiling with GCC) instead via clang because my clang keeps using the native linker (ld.lld) and not the directed one (using GCC_EXEC_PREFIX, using PATH, using -B, all to no avail).

Has anyone experience compiling with LLVM before? Any help I can get? Thanks.
nexos
Member
Member
Posts: 1081
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

Re: LLVM's LD.LLD Doesn't Understand BLOCK(4K)

Post by nexos »

For one thing, to make clang use LLD, pass -fuse-ld=lld to clang. Also, try this

Code: Select all

ENTRY(_start)

SECTIONS 
{
    . = 0x100000;
    .multiboot : {
        *(.multiboot)
    }
    .text ALIGN (4096) : {
        *(.text)
    }
    .data ALIGN (4096) : {
        *(.data)
    }
    .rodata ALIGN (4096) : {
        *(.rodata)
    }
    .bss ALIGN (4096) : {
        *(COMMON)
        *(.bss)
    }
    end = .; _end = .;
}
That's what I use, and it works everywhere for me.
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
flyingplastic
Posts: 2
Joined: Thu Dec 10, 2020 10:51 am

Re: LLVM's LD.LLD Doesn't Understand BLOCK(4K)

Post by flyingplastic »

nexos wrote:For one thing, to make clang use LLD, pass -fuse-ld=lld to clang. Also, try this

Code: Select all

ENTRY(_start)

SECTIONS 
{
    . = 0x100000;
    .multiboot : {
        *(.multiboot)
    }
    .text ALIGN (4096) : {
        *(.text)
    }
    .data ALIGN (4096) : {
        *(.data)
    }
    .rodata ALIGN (4096) : {
        *(.rodata)
    }
    .bss ALIGN (4096) : {
        *(COMMON)
        *(.bss)
    }
    end = .; _end = .;
}
That's what I use, and it works everywhere for me.
OK, now that confirms that it wasn't the linker file, it was how my clang's compile args getting messed up. Since I've messed up the whole toolchain (that's why I can't just use --fuse-ld=lld, it just use the native one and not my "specially-built" llvm in a separate folder, as is the GCC and the bits of libraries here and there) and basically confused myself, I'll retry with new, fresh debian VM (instead of WSL) and get back to square one first. I'll setup a new toolchain, and then report to see if the whole thing is fixed.

Thanks, Nexos :)
nexos
Member
Member
Posts: 1081
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

Re: LLVM's LD.LLD Doesn't Understand BLOCK(4K)

Post by nexos »

Your welcome! Personally, I would stick to GNU. I ran into more LLD problems a little bit ago, so I'll focus on supporting GNU :) .
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
Post Reply