This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: section attribute producing invalid sized sections
- From: Brian Dessent <brian at dessent dot net>
- To: jayhawk at soe dot ucsc dot edu
- Cc: gcc-help at gcc dot gnu dot org
- Date: Fri, 28 Nov 2008 22:45:26 -0800
- Subject: Re: section attribute producing invalid sized sections
- References: <17546210.776721227939426825.JavaMail.nabble@isper.nabble.com>
- Reply-to: gcc-help at gcc dot gnu dot org
[ please keep replies on the mailing list ]
jayhawk@soe.ucsc.edu wrote:
> Thanks for the hints at seeing the assembly that helps and quick reply. The alignment error
> was what I expected, but still expected correct behavior in C when iterating
> over the section.
>
> That is,
>
> struct dummy *start = __start_section_test[];
> struct dummy *stop = __stop_section_test[]
> struct dummy *iter = start;
>
> I should be able to use iter++ to access the next element in the section. Am
> I doing such operation correctly, or assuming a different behavior that only
> worked by chance on another arch?
I don't think that's a valid assumption. It would be valid if you
defined them as an array, but since they are defined as separate
discrete objects there's nothing that requires them to be laid out
contiguously (or in any particular order.)
In practice if you want this to work you'll have to ensure that their
size is always a multiple of their alignment, such as x86 where it's 12
and 4 respectively so it works by chance.
One method that might be more portable would be to leave the actual
structures themselves in their normal location and accumulate pointers
to them in your own section_test. The size and natural alignment of a
pointer type ought to be the same practically everywhere (famous last
words) so you shouldn't encounter any padding.
Brian