possible issue with bss section in sparc

Aleix Conchillo Flaqué aconchillo at ieec.cat
Wed Aug 29 02:46:53 CDT 2007


Hi all,

yesterday I changed some dynamic allocated arrays of structures to
static arrays and the application I am working on had a really weird
behaviour. I changed the array to dynamic and everything worked
properly again. So, after a couple of hours I started thinking that it
could be a problem of the bss section (a moment of desperation I
guess).

I had a look at the linker script
(c/src/lib/libbsp/sparc/erc32/startup/linkcmds):

  .bss :
  {
    __bss_start = ALIGN(0x8);
    _bss_start = .;
    bss_start = .;
    *(.bss)
    *(COMMON)
    end = .;
    _end = ALIGN(0x8);
    __end = ALIGN(0x8);
  } > ram

And at the startup code (c/src/lib/libbsp/sparc/shared/start.S):

        /* clear the bss */
1:

        sethi %hi(_edata),%g2
        or    %g2,%lo(_edata),%g2       ! g2 = start of bss
        sethi %hi(_end),%g3
        or    %g3,%lo(_end),%g3         ! g3 = end of bss
        mov   %g0,%g1                   ! so std has two zeros
zerobss:
        std    %g0,[%g2]
        add    %g2,8,%g2
        cmp    %g2,%g3
        bleu,a zerobss
        nop

And I thought it could be a problem on the alignment of the bss
section, which aligns to the next byte, and the instruction "std
%g0,[%g2]" which stores 8 bytes at the same time. I'm not an expert on
this, so this was another moment of desperation.

I tried out two separate things: first, change the alignment to
ALIGN(16), and second, change the assembly to (keeping ALIGN(8)):

        stb    %g0,[%g2]
        add    %g2,1,%g2

Both things worked well. So, I'm wondering if that makes any sense at
all. Could it be that the "std" is overwriting some bytes that it
should not? Should I find the error in my application, probably a
memory issue, because the bss thing doesn't make any sense?

Any clues would be really appreciated.

Thanks in advance,

Aleix



More information about the rtems-users mailing list