[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[microblaze-uclinux] microblaze-uclinux-elf2flt bug with static initializers



Hello,

We've encountered a problem with static initializers in the microblaze-uclinux-elf2flt tool from PetaLinux 0.20 Build -rc1 050607, svn revision 5150.

In the following code snippet two arrays w_0[] and r_0[] reside in .bss, and two other arrays w[] and r[] in .data:

int w_0; /* .bss */
int r_0; /* .bss */

int *w[] = {&w_0}; /* .data */
int *r[] = {&r_0}; /* .data */

The arrays from .data are initialized with pointers to the arrays in .bss. However, the r[] array gets initialized wrongly as can be seen by running the attached C program. Essentially, elf2flt seems to assign a wrong pointer to an array element with a static initializer, if the pointer refers to a symbol from a different ELF section.

Is there any chance this issue can be solved in the elf2flt? Thanks in advance!

Best regards,
Andrei Terechko

/*
  elf2flt bug test
  June 22, 2009

  Array r[] gets a wrong initialization value of w_0. The error shows up
  only in the bflt code; the elf binary compiled with mb-gcc does not fail.
  We suspect that elf2flt creates wrong static initializers when data elements
  reside in different elf sections.

  To reproduce:
  $ microblaze-uclinux-gcc elf2flt_bug.c -o elf2flt_bug.out -Wall
  $ elf2flt_bug.out
  w[0] = 3f9273d8	r[0] = 3f9273d8
  test FAILED

  $ microblaze-uclinux-gcc --version
  microblaze-uclinux-gcc (GCC) 3.4.1 ( PetaLinux 0.20 Build -rc1 050607 )
  Copyright (C) 2004 Free Software Foundation, Inc.
  This is free software; see the source for copying conditions.  There is NO
  warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */

#include <stdio.h>

int w_0; /* .bss */
int r_0; /* .bss */

int *w[] = {&w_0}; /* .data */
int *r[] = {&r_0}; /* .data */

int main(void)
{
  fprintf(stderr, "w[0] = %08x\tr[0] = %08x\n", (int) w[0], (int) r[0]);
  fprintf(stderr, "test %s\n", r[0] == w[0] ? "FAILED" : "PASSED");

  return r[0] == w[0];
}