Page 1 of 1

grub not liking ". = ALIGN (0x1000);" in ld script

Posted: Tue Sep 04, 2012 10:14 pm
by bradbobak
Here is my ld script where grub outputs "Error 13: Invalid or unsupported executable format'".

Code: Select all

ENTRY (loaded)

SECTIONS
{
  . = 0x00100000;

  .text ALIGN (0x1000) :
  {
    syscall.o (.text)

    . = ALIGN (0x1000);

    * (.text)
  }
}
The other sections are standard (.rodata, .data, .bss) and work fine as-is.

Removing the ". = ALIGN(0x1000);" works fine, but I'd like syscall.o aligned on its own pages (just so I can mark those pages as accessible from ring 3). Possibly there is another way to do this?

Re: grub not liking ". = ALIGN (0x1000);" in ld script

Posted: Wed Sep 05, 2012 1:56 am
by xenos
Looks like a typical case of pushing your multiboot header beyond the first 8k of your kernel executable. Make sure that the multiboot header comes close to the beginning of your kernel.

Re: grub not liking ". = ALIGN (0x1000);" in ld script

Posted: Wed Sep 05, 2012 1:57 am
by Kevin
The multiboot header must be within the first 8k of the binary. You're probably moving it too far to the end this way. Make sure to have the object file with the multiboot header first. Then aligning syscall.o should work fine.

Re: grub not liking ". = ALIGN (0x1000);" in ld script

Posted: Wed Sep 05, 2012 7:18 pm
by bradbobak
Excellent, works like a charm now. Thanks for the help.