section attribute producing invalid sized sections
Noah W
jayhawk@soe.ucsc.edu
Sat Nov 29 06:02:00 GMT 2008
Please let me know if this forum is not appropriate for this question.
Thanks.
I am using __attribute__((section("section-name"))) to place some data into
a section, and using the __start_..., __stop_..., symbols to iterate over
the contents of the section.
When one struct is added to the section the __start_/__stop_ bounds are
correct (the section defined is the size of one struct). When more than one
struct is added the size of the section is larger than I believe it should
be.
Broken on: Gcc: x86_64-linux-gnu, gcc version 4.3.2 (Ubuntu 4.3.2-1ubuntu11)
Note: this test works as expected on: i386-redhat-linux, gcc version 4.1.2
20070925 (Red Hat 4.1.2-33)
I have attached a small test that demonstrates this. The size of the struct
is 24 bytes. If I place 3 structs in to the section the size calculated by
the difference between __start_ and __stop_ is 88, 16 more than I would
expect.
#include <stdio.h>
struct dummy {
int *x, *y, *z;
};
extern struct dummy __start_section_test[];
extern struct dummy __stop_section_test[];
int main(int argc, char **argv)
{
unsigned long long start, stop;
static struct dummy entry_A __attribute__((section("section_test")));
static struct dummy entry_B __attribute__((section("section_test")));
static struct dummy entry_C __attribute__((section("section_test")));
start = (unsigned long long)__start_section_test;
stop = (unsigned long long)__stop_section_test;
printf("struct size=%llu, start=%llu, stop=%llu, diff=%llu\n",
(unsigned long long)sizeof(struct dummy), start, stop, stop-start);
}
--
View this message in context: http://www.nabble.com/section-attribute-producing-invalid-sized-sections-tp20744085p20744085.html
Sent from the gcc - Help mailing list archive at Nabble.com.
More information about the Gcc-help
mailing list