Page 1 of 2

ELF Linker script quick question

Posted: Fri May 26, 2006 8:42 am
by Neo
Does anyone have a ELF linker script for a kernel to be loaded at the 3 Gig virtual address?

Re:ELF Linker script quick question

Posted: Fri May 26, 2006 8:57 am
by paulbarker

Re:ELF Linker script quick question

Posted: Fri May 26, 2006 9:01 am
by Neo
I am using this one right now,

Code: Select all

OUTPUT_FORMAT("elf32-i386")

ENTRY(start)

physical = 0x100000 ;    /* 1 meg */
virtual = 0xC0000000;    /* 3 gig */

SECTIONS
{
  .text virtual : AT(physical)
  {
    code = .; _code = .;
    *(.text)
    *(.rodata*)
    . = ALIGN(4096);
  }

  .bss (ADDR(.text) + SIZEOF(.text)) : /*AT(physical  + (code - bss))*/
  {
    bss = .; _bss = .;
    *(.bss)
    *(COMMON)
    . = ALIGN(4096);
    _bssend = .;
  }
    
  .data (ADDR(.bss) + SIZEOF(.bss)) : /*AT(physical + (code - data))*/
  {
    data = .; _data = .;
    
    start_ctors = .;
    *(.ctors*)
    end_ctors = .;
    
    start_dtors = .;
    *(.dtors)
    end_dtors = .;
    
    *(.data)
    . = ALIGN(0x1000);    
  }
  

  . = ALIGN(4);
  end = .; _end = .;
}
but GRUB is complaining with
Error 28: Selected item cannot fit into memory
and I seem to have forgotten a lot. :)

Re:ELF Linker script quick question

Posted: Fri May 26, 2006 9:04 am
by Neo
That gives me
elf.ld:39 non constant expression for load base

Re:ELF Linker script quick question

Posted: Sat May 27, 2006 3:00 am
by Neo
Ok has anyone used the linker script given at the link? and if so have you faced any problems?
Would be nice to know if you were able to workaround them.

Re:ELF Linker script quick question

Posted: Sat May 27, 2006 3:09 am
by Pype.Clicker
any chance you're using a too old version of GRUB ? iirc, previous version had a bug in the way physical/virtual addresses were used that prevented things like higher-half OSes to be executed directly.

HigherHalfBareBones compiles like a charm on Linux with GNU ld 2.16.1 and gcc 4.0.2.

Re:ELF Linker script quick question

Posted: Sun May 28, 2006 12:50 am
by Neo
I am using CYGWIN with ld 2.16.91 and gcc 4.0.2.
Are there any special linker options that should be passed on?
I am using only the -no-undefined right now.

Re:ELF Linker script quick question

Posted: Sun May 28, 2006 8:41 am
by Neo
Ok, noticed something funny right now.
I replaced all the phsyical address expressions (AT(....)) with constant addresses but I get the same error
elf.ld:58 non constant expression for load base
Am begginning to think there is somethin wrong with ld. ::)


<edit>
Tried with ld 2.16.1. Still same result.
Any ideas??
Has anyone used an ELF kernel that is booted by GRUB to the 3 gig virtual address??
</edit>

Re:ELF Linker script quick question

Posted: Mon May 29, 2006 4:12 am
by Pype.Clicker
googling for the error message pointed me to http://www.skyfree.org/linux/references/ld.pdf ...

Sec. 3.10.5 may help ... maybe not. sorry: i don't have any cygwin at hand here, so i fear i cannot help more. Maybe changelogs will help...

Re:ELF Linker script quick question

Posted: Mon May 29, 2006 6:18 am
by Neo
Thanks Pype. I had seen something similar somewhere on the net (think it was the ld manual) when I searched, but it wasn't of much use.

Also this problem occurs only when the OUTPUT_FORMAT is set to "elf-i386" when I changed this to "binary" it linked properly (of course GRUB couldn't load it).

Not sure what else to do. :(

Re:ELF Linker script quick question

Posted: Mon May 29, 2006 6:28 am
by mystran
Do you have some specific reason to put .bss before .data? That seems a bit weird to me..

Anyway...

I remember having similar issues when I tried to give addresses to sections. Instead adding a .=loadaddress before .text section (like in the FAQ sample script) loads fine with me.

I'm not trying to put my kernel to upper half though, so YMMV.

Re:ELF Linker script quick question

Posted: Mon May 29, 2006 9:04 am
by Neo
I was moving the sections around trying to see what if it was causing the probelms.

Re:ELF Linker script quick question

Posted: Mon May 29, 2006 1:32 pm
by Mark
In my little OS I use:
Note, I located my boot code seperately so I can reclaim the code once booted.

OUTPUT_FORMAT("elf32-i386")
ENTRY (_loader)
SECTIONS
{
. = 0x00100000;
   .boot :
{
   src/obj/startup.o(.text)
   src/obj/boot.o(.text)
      src/obj/bootscreen.o(.text)
      src/obj/startup.o(.rodata)
   src/obj/boot.o(.rodata)
      src/obj/bootscreen.o(.rodata)
}
   .boot_bss ALIGN(0x1000) :
   {
      src/obj/startup.o(.bss)
   src/obj/boot.o(.bss)
      src/obj/bootscreen.o(.bss)
}
   .boot_data ALIGN(0x1000) :
   {
      src/obj/startup.o(.data)
   }
   .bss 0xD0000000 : AT(0x0010c000)
{
   *(.bss)
}
   .data 0xD0001000 : AT (0x0010d000)
{
*(.data)
}
   .text 0xC0000000 : AT(0x00110000)
{
      *(.text)
      *(.rodata)
}
}   

Re:ELF Linker script quick question

Posted: Tue May 30, 2006 6:50 am
by Neo
@Mark: Your script gave the same ld error (non constant expression for load base).

This definitely looks like an 'ld' bug now.

Just out of curiosity. Hasn't anyone here used an ELF kernel that is loaded at some virtual address different from the phsyical address? :o

Re:ELF Linker script quick question

Posted: Tue May 30, 2006 9:36 am
by Colonel Kernel
Neo wrote:Just out of curiosity. Hasn't anyone here used an ELF kernel that is loaded at some virtual address different from the phsyical address? :o
Yes -- the HigherHalfBareBones tutorial, when I was writing it. It worked for me. <shrug/>