Linker Script Madness
Posted: Wed Jun 10, 2015 12:38 am
I am working on the transition to paging and virtual memory. After reading so many articles it seems this should be relatively straight forward. The current issue I have is with the linker script
Two things the symbols _kernel_head_address, _lernel_tail_address and _kernel_size are all allocated an address inside the .bss section and this does not reflect what I was expecting which was the ability to calculate the kernel's usage of memory. Because the symbols are all addressed within the .bss the only calculation I have (which is the same as the _kernel_size) results in 4 bytes which is the difference between the addresses.
What is going on here?
The second issue is that I expected the linker to create a series of sections with VMA differing from the LMA by 0xC0000000 however when I use objdump I get this result.
Which again is completely different to what I expected. I can only assume I am missing some switch on the linker or doing something fundamentally wrong, but after staring at this for the last 3 days I just cannot see where or what I am doing incorrectly.
Anyone able to point out my misunderstanding?
Code: Select all
SECTIONS
{
/* The kernel will live at 3GB + 4MB in the virtual address space, which will be mapped
* to 4MB in the physical address space.
*/
. = 0xC0400000;
_kernel_head_address = .;
.text ALIGN ( 0x1000 ) : AT ( ADDR ( .text ) - 0xC0000000 )
{
*(.text) *(.rdata*) *(.rodata)
}
.data ALIGN ( 0x1000 ) : AT ( ADDR ( .data ) - 0xC0000000 )
{
*(.data)
}
.bss ALIGN ( 0x1000 ) : AT ( ADDR ( .bss ) - 0xC0000000 )
{
*(.bss)
}
_kernel_tail_address = .;
_kernel_size = _kernel_tail_address - _kernel_head_address;
}
What is going on here?
The second issue is that I expected the linker to create a series of sections with VMA differing from the LMA by 0xC0000000 however when I use objdump I get this result.
Code: Select all
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 000012d4 c0400000 c0400000 00000400 2**9
CONTENTS, ALLOC, LOAD, READONLY, CODE, DATA
1 .text.st 00000014 c0402000 c0402000 00001800 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
2 .init 00000024 c0403000 c0403000 00001a00 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
3 .fini 00000024 c0404000 c0404000 00001c00 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
4 .ctors 00000004 c0405000 c0405000 00001e00 2**2
CONTENTS, ALLOC, LOAD, DATA
5 .data 00000004 c0406000 c0406000 00002000 2**2
CONTENTS, ALLOC, LOAD, DATA
6 .bss 0000001c c0407000 c0407000 00000000 2**2
ALLOC
Anyone able to point out my misunderstanding?