I'm using a custom linker script to split a kernel image into two parts. The first is normal code and data, and the second is initialization code and data to be discarded when it's no longer needed. The initialization part is also not shared between address spaces the way the kernel proper is, so anything there gets copied on fork() if it's still around (it is in these early phases of development).
I have allocated a small kernel stack to use while booting, but from what I can see, I can only put it either in the .bss section where it gets shared between address spaces or in the init area where it can't be sto开发者_Go百科red as uninitialized data. I would like to store it in the init part of the image as uninitialized data so that each process gets its own copy.
I can think of two potential ways to do this, but I haven't been able to find out if they're possible or how I would tell the linker to do them. The first would be to put uninitialized regions in non-.bss sections, but I'm not sure that's possible- I don't think you can mix sections like that. The second would be to create a second .bss-like section that only stores uninitialized data, which I could put in the initialization pat of the linker script.
Any ideas? For completeness, here's the linker script I'm using:
ENTRY(_start)
_kernel_offset = _start_kernel - _start_kernel_phys;
SECTIONS {
_start_init = 0x100000;
.init _start_init : AT(ADDR(.init)) { *(.mboot .init*) }
.ctors : {
__CTOR_NUM__ = .; LONG((__CTOR_END__ - __CTOR_LIST__) / 4)
__CTOR_LIST__ = .; *(.ctors*)
__CTOR_END__ = .;
}
_end_init = .;
. = ALIGN(4M);
_start_kernel_phys = .;
_start_kernel = 0xF0000000;
.text _start_kernel : AT(ADDR(.text) - _kernel_offset) { *(.text*) }
.data ALIGN(4K) : AT(ADDR(.data) - _kernel_offset) { *(.rodata* .data*) }
.bss ALIGN(4K) : AT(ADDR(.bss) - _kernel_offset) { *(.bss) *(COMMON) }
_end_kernel = .;
_end_kernel_phys = _end_kernel - _kernel_offset;
/DISCARD/ : { *(.eh_frame .comment) }
}
(ugh, answering my own question again)
Making a new section without the CONTENTS attribute works; it's declared in assembly like this:
.section .init.bss, "aw", @nobits
精彩评论