Linker Script

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
artrecks
Posts: 23
Joined: Wed Jul 11, 2007 8:24 pm

Linker Script

Post 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??
SpooK
Member
Member
Posts: 260
Joined: Sun Jun 18, 2006 7:21 pm

Re: Linker Script

Post 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.)
artrecks
Posts: 23
Joined: Wed Jul 11, 2007 8:24 pm

Post 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 = .;
    }
}


artrecks
Posts: 23
Joined: Wed Jul 11, 2007 8:24 pm

Post 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?
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Post 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;
artrecks
Posts: 23
Joined: Wed Jul 11, 2007 8:24 pm

Post by artrecks »

I didn't understand why, but the way you said worked. Thank you. But can you explain me why this worked??
marcio
Posts: 14
Joined: Fri Oct 20, 2006 10:54 am

Post by marcio »

From the LD manual, section "Assignment: Defining Symbols":
You may create global symbols, and assign values (addresses) to global symbols, (...)
:)
Post Reply