Page 1 of 1

linker script .data and .bss not page aligned

Posted: Sun Jun 07, 2020 9:14 pm
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)

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

Posted: Mon Jun 08, 2020 8:18 am
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?

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

Posted: Mon Jun 08, 2020 9:10 am
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)))?

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

Posted: Mon Jun 08, 2020 4:47 pm
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.

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

Posted: Mon Jun 08, 2020 7:29 pm
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)
}