ELF Linker script quick question
ELF Linker script quick question
Does anyone have a ELF linker script for a kernel to be loaded at the 3 Gig virtual address?
Only Human
Re:ELF Linker script quick question
I am using this one right now,
but GRUB is complaining with
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 = .;
}
and I seem to have forgotten a lot.Error 28: Selected item cannot fit into memory
Only Human
Re:ELF Linker script quick question
That gives mepaulbarker wrote: http://www.osdev.org/osfaq2/index.php/HigherHalfBareBones
elf.ld:39 non constant expression for load base
Only Human
Re:ELF Linker script quick question
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.
Would be nice to know if you were able to workaround them.
Only Human
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:ELF Linker script quick question
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.
HigherHalfBareBones compiles like a charm on Linux with GNU ld 2.16.1 and gcc 4.0.2.
Re:ELF Linker script quick question
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.
Are there any special linker options that should be passed on?
I am using only the -no-undefined right now.
Only Human
Re:ELF Linker script quick question
Ok, noticed something funny right now.
I replaced all the phsyical address expressions (AT(....)) with constant addresses but I get the same error
<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>
I replaced all the phsyical address expressions (AT(....)) with constant addresses but I get the same error
Am begginning to think there is somethin wrong with ld. ::)elf.ld:58 non constant expression for load base
<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>
Only Human
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:ELF Linker script quick question
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...
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
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.
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.
Only Human
Re:ELF Linker script quick question
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.
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
I was moving the sections around trying to see what if it was causing the probelms.
Only Human
Re:ELF Linker script quick question
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)
}
}
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
@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?
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?
Only Human
- Colonel Kernel
- Member
- Posts: 1437
- Joined: Tue Oct 17, 2006 6:06 pm
- Location: Vancouver, BC, Canada
- Contact:
Re:ELF Linker script quick question
Yes -- the HigherHalfBareBones tutorial, when I was writing it. It worked for me. <shrug/>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?
Top three reasons why my OS project died:
- Too much overtime at work
- Got married
- My brain got stuck in an infinite loop while trying to design the memory manager