Question

I am wondering what is the use of defining symbols in a linker script. Using a linker script to arrange different sections is understandable but defining new symbols in the script is not clear to me. I was reading an article which uses a linker script defining two new symbols but those symbols were not referenced anywhere else in the linker script or in the article. An example is the use of sbss and ebss symbols in the bss section as shown below :

ENTRY (loader)
SECTIONS
{    . = 0x00100000;
    .text ALIGN (0x1000) :
    {
        *(.text)
    }
    .rodata ALIGN (0x1000) :
    {
        *(.rodata*)
    }
    .data ALIGN (0x1000) :
    {
        *(.data)
    }

    .bss :
    {
        sbss = .;
        *(COMMON)
        *(.bss)
        ebss = .;
    }
}

There are other symbols also which are frequently used such as etext , dataEnd etc. Please explain the use of defining such symbols when they are not referenced anywhere in the script.

Was it helpful?

Solution

vjain27,

I do not know why one would define symbols as your example linker script defines. This is mostly done in order to allow the executable to know the start and end of a section. This is useful if the data needs to be copied, or otherwise manipulated in memory.

OTHER TIPS

When writing an x86 bootloader, I want the image to be a multiple of 512 bytes by using:

. = ALIGN(512);

in the linker script.

But then I need some way to know the exact size, and pass that to the al of my boot code which will to an int 13h BIOS call that loads data from hard disk to memory. So I wrote something like:

__stage2_size = .;
BYTE((ALIGN(.) / 512) - 1);
. = ALIGN(512);

and used __stage2_size on the boot script.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top