This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/37506] attribute section is not working with constant strings
- From: "nm127 at freemail dot hu" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 14 Sep 2008 05:32:14 -0000
- Subject: [Bug c/37506] attribute section is not working with constant strings
- References: <bug-37506-16706@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #4 from nm127 at freemail dot hu 2008-09-14 05:32 -------
(In reply to comment #3)
> char* y __attribute__ ((__section__(".xxx_section"))) = "Hello World!";
>
> That only puts the pointer variable y into that section and not the string.
Exatly that is my problem. So the pointer variable y goes to section
.xxx_section, but the actual string not. And I do not know any possibility to
specify that the "Hello World!" string should also go to .xxx_section.
For example I expect that in case of the following two lines the "Hello World!"
string itself should be stored in section .xxx_section:
char* z = __attribute__ ((__section__(".xxx_section"))) "Hello World!";
char* w = "Hello World!" __attribute__ ((__section__(".xxx_section")));
What I get for both lines is an error message:
$ gcc -Wall test.c
test.c:5: error: expected expression before '__attribute__'
test.c:6: error: expected ',' or ';' before '__attribute__'
Also, the problem gets complicated when a complete structure is initialized and
it has some string fields:
typedef struct {
int x;
int y;
char* str;
} s;
s a __attribute__ ((__section__(".xxx_section"))) = {
0x11223344,
0x55667788,
"string of the initialized struct"
};
int main() {
return 0;
}
Now we get the following sections:
$ objdump -s a.out
a.out: file format elf32-i386
[...]
Contents of section .rodata:
8048448 03000000 01000200 73747269 6e67206f ........string o
8048458 66207468 6520696e 69746961 6c697a65 f the initialize
8048468 64207374 72756374 00 d struct.
[...]
Contents of section .xxx_section:
804957c 44332211 88776655 50840408 D3"..wfUP...
My expectation is that if I specify that the structure should be stored in
.xxx_section than the string itself should also be stored in .xxx_section.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37506