Starnge LD linker script result

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
songziming
Member
Member
Posts: 71
Joined: Fri Jun 28, 2013 1:48 am
Contact:

Starnge LD linker script result

Post 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 1501 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.
Reinventing the Wheel, code: https://github.com/songziming/wheel
User avatar
iansjack
Member
Member
Posts: 4707
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Starnge LD linker script result

Post 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.)
Post Reply