Hi,
Are there any suggestions for creating a symbol that marks the end of the kernel image and takes into account the ELF .strtab, .symtab and .shstrtab sections? The "standard" method of marking kernel end by placing a linker symbol at the very end of the linker script does not work; it does not include the space occupied by those three sections. Nor can I relocate those three sections by using the linker script - there are no errors from LD, they just stubbornly refuse to move.
Currently when I use my kernel end symbol to start allocating memory I trash the symbol table and I'd like to keep it intact for stack trace purposes.
Cheers!
[Solved] Finding *real* end of kernel image
- fontknocker
- Posts: 16
- Joined: Mon Dec 11, 2006 1:49 am
- Location: Canberra, Australia
[Solved] Finding *real* end of kernel image
Last edited by fontknocker on Wed Jan 02, 2008 5:49 am, edited 2 times in total.
- fontknocker
- Posts: 16
- Joined: Mon Dec 11, 2006 1:49 am
- Location: Canberra, Australia
Thanks for the suggestion, but putting in that catch-all doesn't solve the issue. Perhaps I'm linking the kernel incorrectly? My linker script is fairly standard (snipped out some stuff). I've placed *(.*) in the BSS section just for testing:
The command to link is pretty straightforward. All the generated object files are linked straight into the final kernel image:
Interestingly, if I put the following in the linker script:
symtabsize comes out to zero, suggesting that the symtab section isn't considered by the linker when running through the script.
I do have a somewhat hacked solution now, but it's kludgy and I'd prefer a better one. I take the value of _KERNEL_END given by the linker and, whilst I'm iterating through the ELF section headers, increment it by the size of these extra sections.
Any thoughts? What obvious thing am I missing?
Code: Select all
// snip...
SECTIONS
{
.setup phys : {
*(.mboot)
*(.setup)
}
. += virt;
// snipping text, data, rodata.
.bss ALIGN(0x1000) : AT(ADDR(.bss) - virt)
{
_BSS_START = .;
*(.bss*)
_BSS_END = .;
*(.*)
}
. = ALIGN(0x1000);
_KERNEL_END = .;
}Code: Select all
$(KERNELIMAGE) : $(OBJECTS)
@$(LD) -T link.ld -o $(KERNELIMAGE) $^
Code: Select all
symtabsize = SIZEOF(.symtab);I do have a somewhat hacked solution now, but it's kludgy and I'd prefer a better one. I take the value of _KERNEL_END given by the linker and, whilst I'm iterating through the ELF section headers, increment it by the size of these extra sections.
Any thoughts? What obvious thing am I missing?
- fontknocker
- Posts: 16
- Joined: Mon Dec 11, 2006 1:49 am
- Location: Canberra, Australia
Sure can:
For extra info, here's part of the result of elfdump:
_KERNEL_END points to the beginning of the .shstrtab section.
Code: Select all
fontknocker@desktop:~/dev/kernel/build$ objdump -h kimage
kimage: file format elf32-i386
Sections:
Idx Name Size VMA LMA File off Algn
0 .setup 0000002a 00100000 00100000 00001000 2**0
CONTENTS, ALLOC, LOAD, READONLY, DATA
1 .text 00003bf7 c0101000 00101000 00002000 2**4
CONTENTS, ALLOC, LOAD, READONLY, CODE
2 .data 00000a4c c0105000 00105000 00006000 2**5
CONTENTS, ALLOC, LOAD, DATA
3 .bss 00002ee0 c0106000 00106000 00007000 2**5
ALLOC
Code: Select all
fontknocker@desktop:~/dev/kernel/build$ objdump -t kimage | grep _KERNEL_END
00108ee0 g *ABS* 00000000 _KERNEL_END
Code: Select all
fontknocker@desktop:~/dev/kernel/build$ elfdump kimage
[ Section headers ]
Idx Name Type Flag VMA Offset Size Lnk Inf Algn Tbl
-------------------------------------------------------------------------
0) NULL 0 0 0 0 0 0 0
1) .setup PROG A 100000 4096 42 0 0 1 0
2) .text PROG XA C0101000 8192 15351 0 0 16 0
3) .data PROG AW C0105000 24576 2636 0 0 32 0
4) .bss NOSP AW C0106000 28672 12000 0 0 32 0
5) .shstrtab STRT 0 40672 51 0 0 1 0
6) .symtab SYMT 0 41044 3776 7 62 4 16
7) .strtab STRT 0 44820 2713 0 0 1 0
Code: Select all
5) .shstrtab STRT 0 40672 51 0 0 1 0
6) .symtab SYMT 0 41044 3776 7 62 4 16
7) .strtab STRT 0 44820 2713 0 0 1 0 Seems correct to me. There is nothing in the elf header that says where .shstrtab etc should be loaded in to (if at all) so where they go is completely implementation dependent and thus unreliable.
- fontknocker
- Posts: 16
- Joined: Mon Dec 11, 2006 1:49 am
- Location: Canberra, Australia
