linker script .data and .bss not page aligned

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
ITchimp
Member
Member
Posts: 134
Joined: Sat Aug 18, 2018 8:44 pm

linker script .data and .bss not page aligned

Post by ITchimp »

given the following linker script

Code: Select all

.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)
Octocontrabass
Member
Member
Posts: 5575
Joined: Mon Mar 25, 2013 7:01 pm

Re: linker script .data and .bss not page aligned

Post by Octocontrabass »

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?
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: linker script .data and .bss not page aligned

Post by iansjack »

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)))?
ITchimp
Member
Member
Posts: 134
Joined: Sat Aug 18, 2018 8:44 pm

Re: linker script .data and .bss not page aligned

Post by ITchimp »

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: Select all

.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.
kzinti
Member
Member
Posts: 898
Joined: Mon Feb 02, 2015 7:11 pm

Re: linker script .data and .bss not page aligned

Post by kzinti »

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: Select all

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