Page 1 of 1
GrUB; Selected item cannot fit into memory
Posted: Mon Jan 19, 2009 3:17 pm
by computafreak
I've now got another linking problem. My kernel compiles fine, but GrUB doesn't boot it. The error is 28: Selected item cannot fit into memory. Based on my research, I've found that what it actually means is that I have a weird load address, caused by a bad linker script. But this doesn't seem right, since this only happened when I added a class, Stream, which only contains virtual methods. Is the problem with my code, or my linker script (below)?
Code: Select all
OUTPUT_FORMAT("elf32-i386")
ENTRY(start)
SECTIONS
{
.text 0x1000000 :
{
code = .; _code = .; __code = .;
*(.multiboot)
*(.text)
. = ALIGN(4096);
}
.data :
{
_CTOR_LIST__ = .; LONG((_CTOR_END__ - _CTOR_LIST__) / 4 - 2) * (.ctors) LONG(0) _CTOR_END__ = .;
_DTOR_LIST__ = .; LONG((_DTOR_END__ - _DTOR_LIST__) / 4 - 2) * (.dtors) LONG(0) _DTOR_END__ = .;
data = .; _data = .; __data = .;
*(.data)
*(.rodata)
. = ALIGN(4096);
}
.bss :
{
bss = .; _bss = .; __bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .; _end = .; __end = .;
}
Re: GrUB; Selected item cannot fit into memory
Posted: Mon Jan 19, 2009 4:05 pm
by finarfin
Probably you have to change your text (too 0's
):
with something like that:
This way, should work.
Re: GrUB; Selected item cannot fit into memory
Posted: Tue Jan 20, 2009 12:43 am
by computafreak
Thanks for the reply. I've changed text to the address you suggested, and GrUB still reports an error. I did an objdump on the file, and got these results:
Code: Select all
File format: elf32-i386
Program header:
LOAD off 0x00000000 vaddr 0x00000000 paddr 0x00000000 align 2**12
filesz 0x00000168 memsz 0x00000168 flags r--
LOAD off 0x00001000 vaddr 0x00100000 paddr 0x00100000 align 2**12
filesz 0x00004000 memsz 0x00005000 flags rwx
Presumably, this means that it's getting loaded at address 0x00000000 in memory, which is reserved. Is this correct?
Re: GrUB; Selected item cannot fit into memory
Posted: Tue Jan 20, 2009 3:28 am
by finarfin
hi,
if you are developing on Linux you should try the command: Mbchk
You have to launch it passing your kernel image as argument. It check if your MultibootHeader has something wrong
Now i don't know why objdump give you that values, but When i do an objdump of my kernel i have that:
Code: Select all
Program Header:
LOAD off 0x00001000 vaddr 0x00100000 paddr 0x00100000 align 2**12
filesz 0x00006000 memsz 0x00006000 flags r-x
LOAD off 0x00007000 vaddr 0x00106000 paddr 0x00106000 align 2**12
filesz 0x00002000 memsz 0x00035ffc flags rw-
STACK off 0x00000000 vaddr 0x00000000 paddr 0x00000000 align 2**2
filesz 0x00000000 memsz 0x00000000 flags rwx
Here is my kernel.lds script:
Code: Select all
OUTPUT_FORMAT("binary")
OUTPUT_ARCH(i386)
ENTRY(start)
SECTIONS
{
.text 0x100000 :
{
code = .; _code = .; __code = .;
*(.text)
. = ALIGN(4096);
}
.data :
{
data = .; _data = .; __data = .;
*(.data)
*(.rodata)
. = ALIGN(4096);
}
.bss :
{
bss = .; _bss = .; __bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .; _end = .; __end = .;
}
i don't know if that could help you.
Bye
Re: GrUB; Selected item cannot fit into memory
Posted: Tue Jan 20, 2009 10:31 am
by computafreak
I'm running in Cygwin on Windows, but I found the mbchk application. It returned these results:
Multiboot header at offset 4096
Page alignment on
Memory information on
Address fields off
All checks passed
I've tried the linker script you posted, and GrUB won't load the file (error 13, unsupported file format), and neither will objdump. Incidentally, this error began to occur only when I began to use inheritance. Does that change anything?
Re: GrUB; Selected item cannot fit into memory
Posted: Tue Jan 20, 2009 11:28 am
by finarfin
Try to change output format of my script, with:
(taken from your code)
The error 13 probably depend on the fact that your grub doesn't support my format (binary). Searching on google i found that:
13 : Invalid or unsupported executable format
This error is returned if the kernel image being loaded is not recognized as Multiboot or one of the supported native formats (Linux zImage or bzImage, FreeBSD, or NetBSD).
Re: GrUB; Selected item cannot fit into memory
Posted: Tue Jan 20, 2009 3:32 pm
by computafreak
Unfortunately, that doesn't work either, regardless of which script I'm using. Would it help if I attached the code which somehow altered GrUB? It's mostly a virtual class (Stream) with several Write methods, and a Console class which inherits from this class
Re: GrUB; Selected item cannot fit into memory
Posted: Tue Jan 20, 2009 3:39 pm
by Love4Boobies
computafreak wrote:Based on my research, I've found that what it actually means is that I have a weird load address, caused by a bad linker script.
The rules state that you're not supposed to tell us what you think
Anyway, I'm not sure it's the linker script. Perhaps you should show us the beginning of your kernel (the part with the Multiboot header I am most interested in).
Re: GrUB; Selected item cannot fit into memory
Posted: Wed Jan 21, 2009 12:57 am
by computafreak
Code: Select all
MBOOT_PAGE_ALIGN equ 1 << 0
MBOOT_MEM_INFO equ 1 << 1
MBOOT_HEADER_MAGIC equ 0x1BADB002 ;
MBOOT_HEADER_FLAGS equ MBOOT_PAGE_ALIGN | MBOOT_MEM_INFO
MBOOT_CHECKSUM equ -(MBOOT_HEADER_MAGIC + MBOOT_HEADER_FLAGS)
[BITS 32]
[GLOBAL mboot]
[EXTERN code]
[EXTERN bss]
[EXTERN end]
mboot:
dd MBOOT_HEADER_MAGIC
dd MBOOT_HEADER_FLAGS
dd MBOOT_CHECKSUM
dd mboot
dd code
dd bss
dd end
dd start
Start is just the entry point for my OS, with a loadConstructors call before Main and a loadDestructors call after. The contents of these two functions are fairly standard (get constructors from link script, iterate through and invoke)
Re: GrUB; Selected item cannot fit into memory
Posted: Wed Jan 21, 2009 5:35 am
by goku
Try changing
to
I was getting the same error 13 by grub. I am not exactly sure but i think this fixed my problem
Anyways i guess there is no harm in trying.
Cheers.
Re: GrUB; Selected item cannot fit into memory
Posted: Wed Jan 21, 2009 10:32 am
by computafreak
I've tried altering the output format, still nothing. I think my cross-compiler isn't set up for that, since it didn't even recognise elf as a valid output format in my linker script. Besides, my GrUB error is 28: Selected item cannot fit into memory. I'm seeing if GrUB 2 fixes this
Re: GrUB; Selected item cannot fit into memory
Posted: Fri Jan 23, 2009 12:55 am
by computafreak
First, sorry for the double post, but this is something which is fairly different. I changed my link script to this
Code: Select all
OUTPUT_FORMAT("elf32-i386")
ENTRY(start)
virt = 0xC0000000;
phys = 0x102000;
SECTIONS
{
.text phys : AT(phys)
{
code = .;
*(.text)
*(.rodata*)
. = ALIGN(4096);
}
.data : AT(phys + (data - code))
{
_CTOR_LIST__ = .; LONG((_CTOR_END__ - _CTOR_LIST__) / 4 - 2) * (.ctors) LONG(0) _CTOR_END__ = .;
_DTOR_LIST__ = .; LONG((_DTOR_END__ - _DTOR_LIST__) / 4 - 2) * (.dtors) LONG(0) _DTOR_END__ = .;
data = .;
*(.data)
. = ALIGN(4096);
}
.bss : AT(phys + (bss - code))
{
bss = .;
*(.bss)
*(COMMON)
. = ALIGN(4096);
}
end = .;
}
I then got these results from objdump
Code: Select all
kernelbin: file format elf32-i386
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 00003000 00100000 00100000 00001000 2**4
CONTENTS, ALLOC, LOAD, READONLY, CODE
1 .gnu.linkonce.t._ZN6StreamC2Ev 0000000e 00103000 00103000 00004000 2**1
CONTENTS, ALLOC, LOAD, READONLY, CODE, LINK_ONCE_DISCARD
2 .data 00000fe0 00103020 00103020 00004020 2**5
CONTENTS, ALLOC, LOAD, DATA
3 .bss 00001000 00104000 00104000 00005000 2**5
ALLOC
4 .comment 000000f6 00000000 00000000 00005000 2**0
CONTENTS, READONLY
5 .gnu.linkonce.r._ZTV6Stream 00000028 00000100 00000100 00000100 2**5
CONTENTS, ALLOC, LOAD, READONLY, DATA, LINK_ONCE_DISCARD
6 .gnu.linkonce.r._ZTV7Console 00000028 00000140 00000140 00000140 2**5
CONTENTS, ALLOC, LOAD, READONLY, DATA, LINK_ONCE_DISCARD
I'm fairly certain that the .gnu.linkonce.* is what's causing the problem. If it is, how would I merge these into the relevant sections?