This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC 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]

Re: Alignment Issue


jkayca <jeremy.kalvin@hotmail.com> writes:

> I have a the following static variable: Note that it is aligned on a 4KB
> boundary via the 'aligned' attribute.
>
> 	typedef struct mystruct_s { unsigned int entry[1024]; } mystruct_t;
> 	static mystruct_t myarray __attribute__ ((aligned (4096)));
>
> I have another static that is used as an index into this array.
>
> 	static unsigned int myix;
>
> Both the myarray and myix are used by several of the functions in the module
> and therefore declared outside the scope of any function. However, they are
> not needed outside said module. Hence the static declaration.
>
> When I compile my module I see myarray placed on a 4KB boundary (which is
> good). I also see myix aligned on a 4KB boundary (which is bad).
>
> I also have other static variables. None of these are aligned on anything
> but their natural alignment.
>
> I'm targeting the i386 architecture and I think the version of gcc is 4.5.1.
>
> Anyone know what's going on? BTW, if I change the declaration of myix to
> include an initializer than everything is fine. I guess because myix gets
> pushed out of the BSS and into the COM section.

What is the output of readelf -s on the .o file?  We only really need to
see the lines for myarray and myix.

Ian


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