public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* section attribute producing invalid sized sections
@ 2008-11-29  6:02 Noah W
  2008-11-29  6:19 ` Brian Dessent
  0 siblings, 1 reply; 4+ messages in thread
From: Noah W @ 2008-11-29  6:02 UTC (permalink / raw)
  To: gcc-help


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.

^ permalink raw reply	[flat|nested] 4+ messages in thread
[parent not found: <17546210.776721227939426825.JavaMail.nabble@isper.nabble.com>]

end of thread, other threads:[~2008-11-29  6:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-29  6:02 section attribute producing invalid sized sections Noah W
2008-11-29  6:19 ` Brian Dessent
2008-11-29  6:46   ` Noah W
     [not found] <17546210.776721227939426825.JavaMail.nabble@isper.nabble.com>
2008-11-29 11:35 ` Brian Dessent

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).