Page 1 of 1

error compiling Multiboot 2 bootloader: expected relocatable

Posted: Tue Jul 26, 2022 8:02 am
by xtex
I am writing a bootloader with Multiboot2. I referenced the example code from the specification.

Code: Select all

multiboot_header: // Multiboot Header
    .long   MULTIBOOT2_HEADER_MAGIC
    .long   MULTIBOOT_ARCHITECTURE_I386
    .long   multiboot_header_end - multiboot_header
    .long   -(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT_ARCHITECTURE_I386 + (multiboot_header_end - multiboot_header))
When I am trying to compile it with clang, a error happened on the last line: "error: expected relocatable expression"

Is there any way to solve it?

Thanks.

Re: error compiling Multiboot 2 bootloader: expected relocat

Posted: Tue Jul 26, 2022 8:22 am
by Octocontrabass
That error happens when Clang doesn't know the numeric value of one or more of the labels in that line. That can happen if you've made a mistake in copying the code, or if you're trying to assemble it without the C preprocessor.

Make sure your file has the correct extension. It must be ".S" or ".sx", not ".s".

Re: error compiling Multiboot 2 bootloader: expected relocat

Posted: Tue Jul 26, 2022 8:25 am
by iansjack
Have you defined multiboot_header_end somewhere in the code that you don't show?

Re: error compiling Multiboot 2 bootloader: expected relocat

Posted: Tue Jul 26, 2022 8:28 am
by xtex
Thanks everyone!