This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

ld bug in the location counter calculation?


Hi,

I may have a problem where the linker is not generating the correct
address for the location counter, however I want to check it with the
folks on this list before filling a bug report.

I have the following snippet in my linker script

__ROM_START__  = 0x00000000;
__TEXT_START__ = 0x00080000;
__DATA_START__ = 0x40007000;
__STACK_END__  = 0x4000D000;
SECTIONS
{
  /* Read-only sections, merged into text segment,
   * including the startup code.
   * */

  .boot_identifier __ROM_START__ :
  {
      *(.boot_identifier)
  }


  .text __TEXT_START__ :
  {
    *(.startup_code)
    *intvec.o(.text)
    *(.text)
    *(.text.*)
  }

  PROVIDE (__etext = .);
  .rodata   :
  {
    *(.rodata)
    *(.rodata.*)
  }

  /* append .data; it will be copied by crt0 to final __DATA_START__ */
  . = ALIGN(4);
  __INIT_DATA_START__ = .;

  .data __DATA_START__ : AT ( __INIT_DATA_START__ )
  {
    *(.data)
    *(.data.*)
    SORT(CONSTRUCTORS)
  }
  . = ALIGN(4);
  __DATA_END__ = .;



  /* noninitialized data; will be zeroed by crt0*/
  __bss_start__ = .;
  .bss       :
  {
   *(.bss)
   *(.bss.*)
   *(COMMON)
   . = ALIGN(4);
  }
  . = ALIGN(4);
  __bss_end__ = . ;

  /* noninitialized small data; will be zeroed by crt0 */
  __sbss_start__ = .;
  .sbss       :
  {
   *(.sbss)
   *(.sbss.*)
   *(COMMON)
   . = ALIGN(4);
  }
  . = ALIGN(4);
  __sbss_end__ = . ;

  PROVIDE (end = .);
}

The C code that I use to test this is

volatile uint32_t causescrash = 0;    // comment out to stop crash

int main(void)
{
    while(1)
    {
      ;
    }
}


The compiler correctly optimised the variable causescrashes and puts
into the bss section as an uninitialised variable as it is initialised
to zero.

However, as there isn't any real initialise data, the .data section is
empty. Looking at the code that it generates, __DATA_END__ has been
assigned an address that the same as __INIT_DATA_START__.

>From what I understand of the ld documentation, __DATA_END__ should be
the same as __DATA_START__

This problem goes away if it set causescrashes to a non-zero value, or
use the compiler option -fno-zero-initilialized-in-bss.

By the way, we are using ld version 2.18 for the powerpc.

Is this a bug in how the location counter is updated? If it is, any
suggestion for a workaround?

I have searched through http://www.sourceware.org/bugzilla/ but was
not able to find a similar bug.

Many thanks,
Tehn Yit Chin


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]