Page 1 of 1

Initialised data after end of kernel that shouldn't be there

Posted: Mon Mar 09, 2015 10:06 am
by jrhetf4xb
Hi,

In my kernel linker script I have a symbol to easily point to the last address used by the kernel:

Code: Select all

    ...

    .bss ALIGN (0x1000) :
    {
        sbss = .;
        *(COMMON)
        *(.bss)
        *(.gnu.linkonce.b*)
        ebss = .;
    }

    kernel_end = .;
}
When my kernel runs this turns out to be address 0x00302074. However, upon examining the memory after this location, about 4KiB later there is some data that I have no idea where it comes from. I'm really confused why there is data after the kernel so I was wondering if anyone had any ideas what that could be.

This is some data around 4KiB after the address:
Image

Note I'm using qemu, so unitialised addresses read 0 instead of garbage data. Could it be data from qemu or GRUB's multiboot data? All I'm doing in the kernel is loading a GDT with statically defined structs and utilising a simple kprintf() function. All the static data is supposedly located before kernel_end, no?

Re: Initialised data after end of kernel that shouldn't be t

Posted: Mon Mar 09, 2015 1:43 pm
by Candy
Does your linker script that you're not entirely showing have a discard section? If not, that's what's there.

Re: Initialised data after end of kernel that shouldn't be t

Posted: Mon Mar 09, 2015 1:52 pm
by jrhetf4xb
There isn't any, this is the full script:

Code: Select all

ENTRY (loader)

SECTIONS
{
    . = 0x00100000;

    kernel_start = .;

    .text ALIGN (0x1000) :
    {
        *(.text*)
        *(.gnu.linkonce.t*)
    }

    .rodata ALIGN (0x1000) :
    {
        start_ctors = .;
        *(.ctor*)
        end_ctors = .;

        start_dtors = .;
        *(.dtor*)
        end_dtors = .;

        *(.rodata*)
        *(.gnu.linkonce.r*)
    }

    .data ALIGN (0x1000) :
    {
        *(.data)
        *(.gnu.linkonce.d*)
    }

    .bss ALIGN (0x1000) :
    {
        sbss = .;
        *(COMMON)
        *(.bss)
        *(.gnu.linkonce.b*)
        ebss = .;
    }

    kernel_end = .;
}

Re: Initialised data after end of kernel that shouldn't be t

Posted: Mon Mar 09, 2015 7:29 pm
by eryjus
Since you are not discarding any sections, you are probably looking at your symbol table and shared string table (not to be confused with the static strings in your code).

Re: Initialised data after end of kernel that shouldn't be t

Posted: Tue Mar 10, 2015 9:59 am
by jrhetf4xb
Alright, thanks both!