Linking per-CPU variables to a special area?
Posted: Mon Mar 21, 2016 7:01 am
My kernel is a flat binary with a multiboot header (mainly because it has a 32-bit glue followed by 64-bit code).
I am using the following linker script at the moment:
My idea of per-CPU variables would be to put them in a specific section called "data_per_cpu", and have that section linked such that it is at 0xFFFF828000000000 (that's PML4 entry 261). This way, each CPU would have its own copy of the PML4, each having this specific area of memory mapped to a different physical location, hence having per-CPU variables.
However, if I try to put this section inside the ".bss" above, like so:
The linker tries to fill the entire area from the end of BSS all the way up to 0xFFFF828000000000 with zeores; and that is a good few terabytes of data, so it obviously doesn't work.
Can I somehow force the linker not to put any zeroes or other data in that area, but instead simply relocate references to within the per_cpu_data section to match those addresses?
I am using the following linker script at the moment:
Code: Select all
OUTPUT_FORMAT("binary")
ENTRY(_start)
phys = 0xFFFF800000100000;
SECTIONS
{
.text phys : AT(phys) {
code = .;
*(.bootstrap32)
*(.text)
*(.rodata)
. = ALIGN(4096);
}
.data (phys + (data - code)) : AT(phys + (data - code))
{
data = .;
*(.data)
. = ALIGN(4096);
}
.bss (phys + (bss - code)) : AT(phys + (bss - code))
{
bss = .;
*(.bss)
. = ALIGN(4096);
end = .;
}
}
However, if I try to put this section inside the ".bss" above, like so:
Code: Select all
. = 0xFFFF828000000000;
_per_cpu_start = .;
*(.data_per_cpu)
_per_cpu_end = .;
Can I somehow force the linker not to put any zeroes or other data in that area, but instead simply relocate references to within the per_cpu_data section to match those addresses?