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

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
User avatar
Espanish
Posts: 24
Joined: Fri Nov 21, 2014 6:30 am

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

Post 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 = .;
}
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

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

Post by Combuster »

Have you tried it?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
mariuszp
Member
Member
Posts: 587
Joined: Sat Oct 16, 2010 3:38 pm

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

Post 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)
Last edited by mariuszp on Sat Dec 13, 2014 2:49 pm, edited 1 time in total.
User avatar
Espanish
Posts: 24
Joined: Fri Nov 21, 2014 6:30 am

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

Post 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.
Post Reply