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

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
User avatar
jrhetf4xb
Member
Member
Posts: 38
Joined: Fri May 16, 2014 11:50 am
Location: Bulgaria

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

Post 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?
Practice makes perfect.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

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

Post by Candy »

Does your linker script that you're not entirely showing have a discard section? If not, that's what's there.
User avatar
jrhetf4xb
Member
Member
Posts: 38
Joined: Fri May 16, 2014 11:50 am
Location: Bulgaria

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

Post 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 = .;
}
Practice makes perfect.
User avatar
eryjus
Member
Member
Posts: 286
Joined: Fri Oct 21, 2011 9:47 pm
Libera.chat IRC: eryjus
Location: Tustin, CA USA

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

Post 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).
Adam

The name is fitting: Century Hobby OS -- At this rate, it's gonna take me that long!
Read about my mistakes and missteps with this iteration: Journal

"Sometimes things just don't make sense until you figure them out." -- Phil Stahlheber
User avatar
jrhetf4xb
Member
Member
Posts: 38
Joined: Fri May 16, 2014 11:50 am
Location: Bulgaria

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

Post by jrhetf4xb »

Alright, thanks both!
Practice makes perfect.
Post Reply