gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > RODATA suddenly misaligned

#24802 - Gene Ostrowski - Wed Aug 11, 2004 7:41 pm

I was pulling my hair out trying to determine why my sprite data was suddenly garbled.

It turns out that when I look at the memmap of the output, I am seeing:

08043fd1 R _binary_gfx_spr32_raw_start

...which is clearly not being aligned properly, which in turn is messing up my routines that require 4-byte alignment.

This is a problem that just suddenly started-- I've always had my rodata properly aligned without having to do anything special.

Any ideas why this might be happening? Is it objcopy or the linker that would cause this misalignment?

I'm not a linker-script guru, but it shows:
Code:
 .rodata :
  {
    *(.rodata)
    *all.rodata*(*)
    *(.roda)
    *(.rodata.*)
    *(.gnu.linkonce.r*)
    SORT(CONSTRUCTORS)
    . = ALIGN(4);   /* REQUIRED. LD is flaky without it. */
  } = 0xff

and that appears to be set to align things properly.

Any ideas why it's happening, and more importantly, how I may be able to find a different way to force it to be aligned?

BTW,
I was hoping to fool gcc by re-declaring the array as an int to try to force it to link properly, but it didn't help:

Code:
extern unsigned int _binary_gfx_spr32_raw_start[];


Any thoughts would be greatly appreciated.
_________________
------------------
Gene Ostrowski

#24935 - f(DarkAngel) - Fri Aug 13, 2004 6:26 pm

Have you tried using __attribute__((align(2)))?
_________________
death scream...

#24944 - Gene Ostrowski - Fri Aug 13, 2004 7:49 pm

No I havent. Where would I put that, at the end before the semicolon?
_________________
------------------
Gene Ostrowski

#24951 - DKL - Fri Aug 13, 2004 8:26 pm

Gene Ostrowski wrote:
No I havent. Where would I put that, at the end before the semicolon?

Damn, I deleted my post twice... I'm tired...

unsigned int _binary_gfx_spr32_raw_start[] __attribute__ ((aligned))={your data};

If it don't work, could you please post part of your code & your makefile ?

Btw, some compilers need a pragma directive rather than an attribute, which compiler are you using ?

DKL