Converting linker script from DJGPP LD to GNU LD

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
User avatar
Revelation
Member
Member
Posts: 47
Joined: Sat Jun 21, 2008 8:15 am

Converting linker script from DJGPP LD to GNU LD

Post by Revelation »

While studying some code I ran into a real weird problem: the linker script gets interpreted differently if I use GNU LD instead of the DJGPP version.

This is the script:

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)

SECTIONS
{

  .text  0xFF800000 : {
    *(.text)
  }

  .data  : {
    *(.data)
  }

  .bss  :
  { 					
    *(.bss)
  }

}

If I use this script on linux, I get a 4gb kernel! Somehow gnu ld interprets 0xFF800000 as the kernel size :|

I tried this fix:

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)

SECTIONS
{
 .= 0xFF800000;
  .text   : {
    *(.text)
  }

  .data  : {
    *(.data)
  }

  .bss  :
  { 					
    *(.bss)
  }

}

Now the filesize is ok, but the order in the file is messed up. If I view the output with a hex editor, I see the string constants first.

Can somebody help me?
Last edited by Revelation on Tue Jul 08, 2008 3:41 pm, edited 1 time in total.
Now is the winter of my disk content.
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

Re: Converting linker script from DJGPP LD to GNU LD

Post by suthers »

Try this:

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)

SECTIONS
{
.text 0xFF800000 : AT(0xFF800000) {
*(.text)
}

.data : AT(0x100000 + (data - code)){
*(.data)
}

.bss : AT(0x100000 + (bss - code)){
*(.bss)
}

}
Jules
User avatar
Revelation
Member
Member
Posts: 47
Joined: Sat Jun 21, 2008 8:15 am

Re: Converting linker script from DJGPP LD to GNU LD

Post by Revelation »

I get an error: kernel.ld:10: nonconstant expression for load base.

Also, why are you using 0x100000?
Now is the winter of my disk content.
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

Re: Converting linker script from DJGPP LD to GNU LD

Post by suthers »

Revelation wrote:I get an error: kernel.ld:10: nonconstant expression for load base.

Also, why are you using 0x100000?
#-o , sorry, I copied that out of my script, replace it by your load address sorry....
Jules
User avatar
Revelation
Member
Member
Posts: 47
Joined: Sat Jun 21, 2008 8:15 am

Re: Converting linker script from DJGPP LD to GNU LD

Post by Revelation »

Well, it doesn't matter what I put there, I still get the error :(

And btw, I think 0x100000 is right, because the image is loaded and copied to 1mb physical and then mapped to FFF80000 linear.
Now is the winter of my disk content.
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

Re: Converting linker script from DJGPP LD to GNU LD

Post by suthers »

Well shouldn't you load your kernel at 0x100000, but before you jump to it map it to your address by changing the base address of the GDT selector you use to jump to it....
Jules
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Re: Converting linker script from DJGPP LD to GNU LD

Post by pcmattman »

The wiki has an article on a Higher Half Kernel which may or may not be what you're looking for.
User avatar
Revelation
Member
Member
Posts: 47
Joined: Sat Jun 21, 2008 8:15 am

Re: Converting linker script from DJGPP LD to GNU LD

Post by Revelation »

Well shouldn't you load your kernel at 0x100000, but before you jump to it map it to your address by changing the base address of the GDT selector you use to jump to it....
That's all set up correctly.The only thing that is not working is the port of that script to gnu's ld. I've tested it using the djgpp ld (in Windows) and that did work.

So my question is the same: what should I do to convert the code? suther's code doesn't compile unfortunately.
Now is the winter of my disk content.
User avatar
Revelation
Member
Member
Posts: 47
Joined: Sat Jun 21, 2008 8:15 am

Re: Converting linker script from DJGPP LD to GNU LD

Post by Revelation »

I've found the error! The DJPP's LD does not see rodata as a different type of data, so it just puts it in data. GNU's LD does see rodata as a different type, so I had to put it there:

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)

SECTIONS
{
.text 0xFF800000 :  {
*(.text)
}

.data  :{
*(.data)
*(.rodata)
}

.bss :{
*(.bss)
}
}
I got the idea that this was the problem because the string constants were in the beginning of the file. Apparently, if you don't say where to put rodata, it will put in before text, thus making a 4gb file.
Now is the winter of my disk content.
Post Reply