Linker script in bare bones tutorial

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
gsingh2011
Member
Member
Posts: 83
Joined: Tue Feb 03, 2009 11:37 am

Linker script in bare bones tutorial

Post by gsingh2011 »

I have a few questions about the linker script in the bare bones tutorial. Here is the script:

Code: Select all

ENTRY (loader)

SECTIONS
{
    . = 0x00100000;

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

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

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

    .bss :
    {
        sbss = .;
        *(COMMON)
        *(.bss)
        ebss = .;
    }
}
My first question is in this section:

Code: Select all

    .bss :
    {
        sbss = .;
        *(COMMON)
        *(.bss)
        ebss = .;
    }
I assume sbss and ebss stand for start bss and end bss. Why do they need to be there?

My second question is that why we need a linker script in the first place? Isn't ELF a common format? Should ld be able to link it without us writing our own script?
User avatar
Griwes
Member
Member
Posts: 374
Joined: Sat Jul 30, 2011 10:07 am
Libera.chat IRC: Griwes
Location: Wrocław/Racibórz, Poland
Contact:

Re: Linker script in bare bones tutorial

Post by Griwes »

http://en.wikipedia.org/wiki/.bss

In general, .bss is used for global variables, but it is not included in executable. `sbss` and `ebss` are there so you can "create" it in memory (for example, move something that was right after executable on disk, zero it or whatever you want).

Personally, since I have recently hit a problem with it, I just put `*(.bss)` in `.data`, so I don't have to worry about it.

As for the "why linker script" question - there might be a chance that ld will get it just right without it, but since in OSDev what you need and what you seek is *control* over what's happening - and linker script gives you that.
Reaver Project :: Repository :: Ohloh project page
<klange> This is a horror story about what happens when you need a hammer and all you have is the skulls of the damned.
<drake1> as long as the lock is read and modified by atomic operations
Post Reply