OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 3:52 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: linker script .data and .bss not page aligned
PostPosted: Sun Jun 07, 2020 9:14 pm 
Offline
Member
Member

Joined: Sat Aug 18, 2018 8:44 pm
Posts: 127
given the following linker script

Code:
.data :
{
        data =  .; _data = .; __data = .;
        *(.data)
        *(.rodata)
        . = ALIGN(4096);
}
.bss:
{
        bss =  .; _bss = .; __bss = .;
        *(.bss)
        . = ALIGN(4096);
}


does that mean .data and .bss will start from a page ?

I checked the value of &bss and &data, none of which is page aligned (ie. last 3 hex digits are zero)


Top
 Profile  
 
 Post subject: Re: linker script .data and .bss not page aligned
PostPosted: Mon Jun 08, 2020 8:18 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
ITchimp wrote:
does that mean .data and .bss will start from a page ?

It means .bss will, but .data may not. You can't tell for sure without seeing the entire linker script.

ITchimp wrote:
I checked the value of &bss and &data, none of which is page aligned (ie. last 3 hex digits are zero)

How did you declare those variables?


Top
 Profile  
 
 Post subject: Re: linker script .data and .bss not page aligned
PostPosted: Mon Jun 08, 2020 9:10 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
Why would you expect the addresses of the variables bss and data to be aligned? Isn't it the content of these variables that you are interested in (or else _symval(&bss)) and _symval(data)))?


Top
 Profile  
 
 Post subject: Re: linker script .data and .bss not page aligned
PostPosted: Mon Jun 08, 2020 4:47 pm 
Offline
Member
Member

Joined: Sat Aug 18, 2018 8:44 pm
Posts: 127
I am writing a simple multi-tasking OS... I want to move the kernel heap as close to the beginning as possible... to get as much page frame as I can

from my experiment with linker script so far

Code:
.data :
{
        data =  .; _data = .; __data = .;
        *(.data)
        *(.rodata)
        . = ALIGN(4096);
}
.bss:
{
        bss =  .; _bss = .; __bss = .;
        *(.bss)
        . = ALIGN(4096);
}


the linker script above does *not* make .data or .bss start from the first byte of a page, it
just means that the entire section will end at the a page boundary...

linker can select the starting address at some value past the page boundary...

I declare the value in my C code as extern, the linker will do the rest.


Top
 Profile  
 
 Post subject: Re: linker script .data and .bss not page aligned
PostPosted: Mon Jun 08, 2020 7:29 pm 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 898
ITchimp wrote:
I want to move the kernel heap as close to the beginning as possible...

The beginning of what?

ITchimp wrote:
the linker script above does *not* make .data or .bss start from the first byte of a page, it
just means that the entire section will end at the a page boundary...

Correct. The linker script does what you tell it too.

If what you intended was to align the sections on page boundaries, you would need something like this instead:

Code:
.data:
{
        . = ALIGN(4096);
        data =  .; _data = .; __data = .;
        *(.data)
        *(.rodata)
}
.bss:
{
        . = ALIGN(4096);
        bss =  .; _bss = .; __bss = .;
        *(.bss)
}

_________________
https://github.com/kiznit/rainbow-os


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 49 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group