GrUB; Selected item cannot fit into memory

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
computafreak
Member
Member
Posts: 76
Joined: Sun Dec 14, 2008 1:53 pm

GrUB; Selected item cannot fit into memory

Post 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 = .;
}
User avatar
finarfin
Member
Member
Posts: 106
Joined: Fri Feb 23, 2007 1:41 am
Location: Italy & Ireland
Contact:

Re: GrUB; Selected item cannot fit into memory

Post by finarfin »

Probably you have to change your text (too 0's :D):

Code: Select all

 .text 0x1000000 :
with something like that:

Code: Select all

.text 0x100000 :
This way, should work.
computafreak
Member
Member
Posts: 76
Joined: Sun Dec 14, 2008 1:53 pm

Re: GrUB; Selected item cannot fit into memory

Post 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?
User avatar
finarfin
Member
Member
Posts: 106
Joined: Fri Feb 23, 2007 1:41 am
Location: Italy & Ireland
Contact:

Re: GrUB; Selected item cannot fit into memory

Post 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
Elen síla lúmenn' omentielvo
- DreamOS64 - My latest attempt with osdev: https://github.com/dreamos82/Dreamos64
- Osdev Notes - My notes about osdeving! https://github.com/dreamos82/Osdev-Notes
- My old Os Project: https://github.com/dreamos82/DreamOs
computafreak
Member
Member
Posts: 76
Joined: Sun Dec 14, 2008 1:53 pm

Re: GrUB; Selected item cannot fit into memory

Post 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?
User avatar
finarfin
Member
Member
Posts: 106
Joined: Fri Feb 23, 2007 1:41 am
Location: Italy & Ireland
Contact:

Re: GrUB; Selected item cannot fit into memory

Post by finarfin »

Try to change output format of my script, with:

Code: Select all

OUTPUT_FORMAT("elf32-i386")
(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).
Elen síla lúmenn' omentielvo
- DreamOS64 - My latest attempt with osdev: https://github.com/dreamos82/Dreamos64
- Osdev Notes - My notes about osdeving! https://github.com/dreamos82/Osdev-Notes
- My old Os Project: https://github.com/dreamos82/DreamOs
computafreak
Member
Member
Posts: 76
Joined: Sun Dec 14, 2008 1:53 pm

Re: GrUB; Selected item cannot fit into memory

Post 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
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: GrUB; Selected item cannot fit into memory

Post 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).
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
computafreak
Member
Member
Posts: 76
Joined: Sun Dec 14, 2008 1:53 pm

Re: GrUB; Selected item cannot fit into memory

Post 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)
User avatar
goku
Member
Member
Posts: 29
Joined: Sat Oct 25, 2008 11:32 am
Location: until we meet again!!

Re: GrUB; Selected item cannot fit into memory

Post by goku »

Try changing

Code: Select all

OUTPUT_FORMAT("elf32-i386")
to

Code: Select all

OUTPUT_FORMAT("elf")
I was getting the same error 13 by grub. I am not exactly sure but i think this fixed my problem :roll: Anyways i guess there is no harm in trying.


Cheers.
computafreak
Member
Member
Posts: 76
Joined: Sun Dec 14, 2008 1:53 pm

Re: GrUB; Selected item cannot fit into memory

Post 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
computafreak
Member
Member
Posts: 76
Joined: Sun Dec 14, 2008 1:53 pm

Re: GrUB; Selected item cannot fit into memory

Post 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?
Post Reply