Re: section attribute producing invalid sized sections

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

 



[ please keep replies on the mailing list ]

jayhawk@xxxxxxxxxxxx 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

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux