lilzz
Posts: 411
Joined: Sat Nov 30, 2013 5:27 pm

startup.s file _bss_start and _bss_end

Mon Feb 08, 2016 12:08 am

Code: Select all

.extern __bss_start
.extern __bss_end

ldr r0, =__bss_start
ldr r1, =__bss_end
what are the actual values of _bss_start and _bss_end?
They are not given specific values in startup.s file

User avatar
Paeryn
Posts: 2966
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: startup.s file _bss_start and _bss_end

Mon Feb 08, 2016 4:43 am

The linker provides those symbols as defined in the linker script (ld usually provides a default script if you don't explicitly set one).

Part of your link script will collate all the BSS sections of all the object files and set the symbols appropriately.
Normally __bss_start will point to the first free address after the data section and __bss_end will point to the location __bss_start + sizeof(bss section).

Run

Code: Select all

ld --verbose
and you'll see the default linker script (it's quite long). The bss section is in here...

Code: Select all

  .data           :
  {
    PROVIDE (__data_start = .);
    *(.data .data.* .gnu.linkonce.d.*)
    SORT(CONSTRUCTORS)
  }
  .data1          : { *(.data1) }
  _edata = .; PROVIDE (edata = .);
  . = .;
  __bss_start = .;
  __bss_start__ = .;
  .bss            :
  {
   *(.dynbss)
   *(.bss .bss.* .gnu.linkonce.b.*)
   *(COMMON)
   /* Align here to ensure that the .bss section occupies space up to
      _end.  Align after .bss to ensure correct alignment even if the
      .bss section disappears because there are no input sections.
      FIXME: Why do we need it? When there is no .bss section, we don't
      pad the .data section.  */
   . = ALIGN(. != 0 ? 32 / 8 : 1);
  }
  _bss_end__ = . ; __bss_end__ = . ;
  . = ALIGN(32 / 8);
  . = SEGMENT_START("ldata-segment", .);
  . = ALIGN(32 / 8);
  __end__ = . ;
  _end = .; PROVIDE (end = .);
  . = DATA_SEGMENT_END (.);
Google ld linker scripts for info on how scripts work (you can read the manpages for ld but it doesn't go into any detail on how scripts work).
She who travels light — forgot something.

Return to “Beginners”