Page 1 of 1
Converting linker script from DJGPP LD to GNU LD
Posted: Tue Jul 08, 2008 3:07 pm
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?
Re: Converting linker script from DJGPP LD to GNU LD
Posted: Tue Jul 08, 2008 3:20 pm
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
Re: Converting linker script from DJGPP LD to GNU LD
Posted: Tue Jul 08, 2008 3:40 pm
by Revelation
I get an error: kernel.ld:10: nonconstant expression for load base.
Also, why are you using 0x100000?
Re: Converting linker script from DJGPP LD to GNU LD
Posted: Tue Jul 08, 2008 3:41 pm
by suthers
Revelation wrote:I get an error: kernel.ld:10: nonconstant expression for load base.
Also, why are you using 0x100000?
, sorry, I copied that out of my script, replace it by your load address sorry....
Jules
Re: Converting linker script from DJGPP LD to GNU LD
Posted: Tue Jul 08, 2008 4:10 pm
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.
Re: Converting linker script from DJGPP LD to GNU LD
Posted: Tue Jul 08, 2008 4:17 pm
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
Re: Converting linker script from DJGPP LD to GNU LD
Posted: Tue Jul 08, 2008 4:21 pm
by pcmattman
The wiki has an article on a
Higher Half Kernel which may or may not be what you're looking for.
Re: Converting linker script from DJGPP LD to GNU LD
Posted: Wed Jul 09, 2008 2:57 am
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.
Re: Converting linker script from DJGPP LD to GNU LD
Posted: Wed Jul 09, 2008 3:34 am
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.