Page 1 of 1

link.ld - What's the meaning of the __end label?

Posted: Sat Dec 13, 2014 8:33 am
by Espanish
James Molloy's tutorial uses the link.ld file as copy-pasted below.

Question: what does the __end label represent?
More specifically: is it a pointer to the last byte of the binary, or in C++ STL style, to the byte after the last byte of the binary (thereby pointing "outside")?

Code: Select all

ENTRY(start)
SECTIONS
{
  .text 0x100000 :
  {
    code = .; _code = .; __code = .;
    *(.text)
    . = ALIGN(4096);
  }

  .data :
  {
     data = .; _data = .; __data = .;
     *(.data)
     *(.rodata)
     . = ALIGN(4096);
  }

  .bss :
  {
    bss = .; _bss = .; __bss = .;
    *(.bss)
    . = ALIGN(4096);
  }

  end = .; _end = .; __end = .;
}

Re: link.ld - What's the meaning of the __end label?

Posted: Sat Dec 13, 2014 8:46 am
by Combuster
Have you tried it?

Re: link.ld - What's the meaning of the __end label?

Posted: Sat Dec 13, 2014 11:36 am
by mariuszp
Espanish wrote:James Molloy's tutorial uses the link.ld file as copy-pasted below.

Question: what does the __end label represent?
More specifically: is it a pointer to the last byte of the binary, or in C++ STL style, to the byte after the last byte of the binary (thereby pointing "outside")?

Code: Select all

ENTRY(start)
SECTIONS
{
  .text 0x100000 :
  {
    code = .; _code = .; __code = .;
    *(.text)
    . = ALIGN(4096);
  }

  .data :
  {
     data = .; _data = .; __data = .;
     *(.data)
     *(.rodata)
     . = ALIGN(4096);
  }

  .bss :
  {
    bss = .; _bss = .; __bss = .;
    *(.bss)
    . = ALIGN(4096);
  }

  end = .; _end = .; __end = .;
}
It points to the byte after the last byte of the binary in memory (i.e. once the binary is laoded, along with the BSS section, __end will point to the first byte outside the binary).

EDIT: Typo (wrote TSS instead of BSS sorry)

Re: link.ld - What's the meaning of the __end label?

Posted: Sat Dec 13, 2014 12:22 pm
by Espanish
mariuszp wrote:It points to the byte after the last byte of the binary in memory (i.e. once the binary is laoded, along with the TSS section, __end will point to the first byte outside the binary).
Thank you for the clarification.
In the meantime I found an [unofficial LD manual] describing the location counter. Their wording is thus:
. actually refers to the byte offset from the start of the current containing object.