Page 1 of 1

Starnge LD linker script result

Posted: Wed Jun 10, 2015 9:12 am
by songziming
Hello everyone. In my kernel I use a linker script to describe kernel's memory layout. The script is:

Code: Select all

OUTPUT_FORMAT(binary)
SECTIONS {
    . = 1M;
    kernel_load_addr = .;
    .text BLOCK(4K) : ALIGN(4K) {
        kernel_text_start = .;
        *(.boot)
        *(.text)
        kernel_text_end = .;
    } = 0x90    /* NOP */
    .data BLOCK(4K) : ALIGN(4K) {
        kernel_data_start = .;
        *(.rodata)
        *(.data)
        kernel_data_end = .;
    } = 0
    .bss BLOCK(4K) : ALIGN(4K) {
        kernel_bss_start = .;
        *(COMMON)
        *(.bss)
        kernel_bss_end = .;
    } = 0
    kernel_end = .;
}
And in C code I printed out addresses of those locations, the result is:
address printed
address printed
123321.png (2.84 KiB) Viewed 1502 times
("kernel_stack" and "pml4t" are two data structures located in bss segment)

That's strange. I thought "kernel_end" should be the largest number, but tended out to be same as "kernel_start". And, "text_start" is different from "kernel_start", even text is the first segment. And each segments' start and end address are all same.

Re: Starnge LD linker script result

Posted: Wed Jun 10, 2015 9:42 am
by iansjack
If you produce a linker map file what does it show for those symbols? (I'm wondering if the problem is not in the link but in the way you are printing the symbols.)