Page 1 of 1

Linker script location pointer doesn't move as expected

Posted: Mon Dec 11, 2006 2:16 am
by fontknocker
Hi folks,

I've defined _KERNEL_START and _KERNEL_END in my linker script (provided below). After linking _KERNEL_START is 0xC0100000, as expected, however _KERNEL_END is also set to 0xC0100000, which is incorrect (.text, .data and .bss certainly aren't 0 bytes in length).

I've tried removing the higher-half linking and it produces the same problem, except then _KERNEL_START = _KERNEL_END = 0x100000.

I've got some extremely basic bare bones kernel code I keep around for testing, and when using the same linker script to link that kernel all symbols are defined correctly. That suggests to me that the problem isn't in the linker script, but somewhere in the C or ASM code, but I'm not quite sure how high-level code would affect symbols set during link time.

I should point out that sbss and ebss are also incorrectly set (sbss = ebss), whilst the symbols "code" and "data" are both correct.

I've defined _KERNEL_START and _KERNEL_END within C as follows:

Code: Select all

extern void *_KERNEL_END;
extern void *_KERNEL_START;
Linker script:

Code: Select all

ENTRY(start)
OUTPUT_FORMAT("elf32-i386")
OUTPUT_ARCH(i386)

SECTIONS
{
	. = 0x100000;

	.mboot : { *(.mboot) }
	
	.setup :
	{
		*(.setup)
	}

	. += 0xC0000000;
	
	_KERNEL_START = .;
	
	.text : AT(ADDR(.text) - 0xC0000000)
	{
		code = .;
		*(.text)
	}
	
	.data ALIGN(4096) : AT(ADDR(.data) - 0xC0000000)
	{
		data = .;
		*(.data)
		*(.rodata)
	}

	.bss ALIGN(4096) : AT(ADDR(.bss) - 0xC0000000)
	{
		sbss = .;
		*(.bss)
		ebss = .;
	}	

	. = ALIGN(4096);
	
	_KERNEL_END = .;
}
objdump output:

Code: Select all

$ objdump -t kernel | grep KERNEL
c0100000 g       *ABS*  00000000 _KERNEL_START
c0100000 g       *ABS*  00000000 _KERNEL_END

$ objdump -t kernel | grep bss
c0102000 l    d  .bss   00000000 .bss
c0103008 l       .bss   00000000 sys_stack
c0104000 g     O .bss   00001000 kernelPageDir
c0103008 g     O .bss   00000006 gp
c010300e g     O .bss   00000018 gdt
c0103008 g       .bss   00000000 sbss
c0102000 g     O .bss   00000004 cursorX
c0105000 g     O .bss   00001000 lowPageTable
c0102004 g     O .bss   00000004 cursorY
c0103008 g       .bss   00000000 ebss
What am I missing? If you need to see anything else, just ask.

Thanks.