Page 1 of 1

Linker Script

Posted: Fri Aug 03, 2007 2:35 pm
by artrecks
I'm trying to write a linker script ( so I reading LD documentation ), but looking into someones linker script I got a section named ".rodata" and I want to know what is this section for??

Re: Linker Script

Posted: Fri Aug 03, 2007 2:59 pm
by SpooK
artrecks wrote:I'm trying to write a linker script ( so I reading LD documentation ), but looking into someones linker script I got a section named ".rodata" and I want to know what is this section for??
.rodata = Read-Only Data (i.e. run-time constants.)

Posted: Fri Aug 03, 2007 3:13 pm
by artrecks
ok, thanks for replying!!!

Since I'm using a binary format for my kernel I guess that the BSS section won't be write to the file, so I putted the BSS at the end of the memory ( with the linker script) and I created two pointers ( one for the beginning of the section and one for the end ), this way I can zero-fill this memory at my kernel start. But is the script ok:

Code: Select all


OUTPUT_FORMAT("binary")
ENTRY(kfstart)
SECTIONS{
    . = 0x00100000;

    .text :{
        *(.text)
    }

    .rodata ALIGN (0x1000) : {
        *(.rodata)
    }

    .data ALIGN (0x1000) : {
        *(.data)
    }

    .bss : {
        _start_bss = .;
        *(.bss)
        _end_bss = .;
    }
}



Posted: Mon Aug 06, 2007 5:04 pm
by artrecks
but using this I could not get the address of (_start_bss ) and (_end_bss). I used them in C code ( extern unsigned long start_bss ) but I got number 0 for start_bss and 0x89D189C3 for end_bss
Why this is happening?

Posted: Mon Aug 06, 2007 5:32 pm
by frank
artrecks wrote:but using this I could not get the address of (_start_bss ) and (_end_bss). I used them in C code ( extern unsigned long start_bss ) but I got number 0 for start_bss and 0x89D189C3 for end_bss
Why this is happening?
Try taking the address of start_bss in the C code. Because of the way that the variables are represented you have to take the address of them to get the correct value.

Code: Select all

/* The correct way to get the start of the bss section would be something like this */
DWORD start_of_bss = (DWORD)&start_bss;

Posted: Mon Aug 06, 2007 5:43 pm
by artrecks
I didn't understand why, but the way you said worked. Thank you. But can you explain me why this worked??

Posted: Tue Aug 07, 2007 2:30 am
by marcio
From the LD manual, section "Assignment: Defining Symbols":
You may create global symbols, and assign values (addresses) to global symbols, (...)
:)