public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/37506] New: attribute section is not working with constant strings
@ 2008-09-13 9:05 nm127 at freemail dot hu
2008-09-13 9:51 ` [Bug c/37506] " pinskia at gmail dot com
` (6 more replies)
0 siblings, 7 replies; 9+ messages in thread
From: nm127 at freemail dot hu @ 2008-09-13 9:05 UTC (permalink / raw)
To: gcc-bugs
With the __attribute__ __section__ it is possible to allocate variables to
different section than the default (
http://gcc.gnu.org/onlinedocs/gcc/Variable-Attributes.html ). In case of the
following source code I would achieve to allocate both "foo bar" and "Hello
World!" strings into the .xxx_section section:
char x[] __attribute__ ((__section__(".xxx_section"))) = "foo bar";
char* y __attribute__ ((__section__(".xxx_section"))) = "Hello World!";
int main() {
return 0;
}
However, with gcc version 4.3.1 (Debian 4.3.1-9) only the "foo bar" string is
stored in .xxx_section:
$ objdump -s a.out
a.out: file format elf32-i386
[...]
Contents of section .rodata:
8048448 03000000 01000200 48656c6c 6f20576f ........Hello Wo
8048458 726c6421 00 rld!.
[...]
Contents of section .xxx_section:
8049568 666f6f20 62617200 50840408 foo bar.P...
--
Summary: attribute section is not working with constant strings
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: nm127 at freemail dot hu
GCC build triplet: 4.3.1
GCC target triplet: i486-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37506
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/37506] attribute section is not working with constant strings
2008-09-13 9:05 [Bug c/37506] New: attribute section is not working with constant strings nm127 at freemail dot hu
@ 2008-09-13 9:51 ` pinskia at gmail dot com
2008-09-13 14:00 ` nm127 at freemail dot hu
` (5 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: pinskia at gmail dot com @ 2008-09-13 9:51 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pinskia at gmail dot com 2008-09-13 09:49 -------
Subject: Re: New: attribute section is not working with constant strings
Sent from my iPhone
On Sep 13, 2008, at 2:04 AM, "nm127 at freemail dot hu"
<gcc-bugzilla@gcc.gnu.org
> wrote:
> With the __attribute__ __section__ it is possible to allocate
> variables to
> different section than the default (
> http://gcc.gnu.org/onlinedocs/gcc/Variable-Attributes.html ). In
> case of the
> following source code I would achieve to allocate both "foo bar" and
> "Hello
> World!" strings into the .xxx_section section:
>
> char x[] __attribute__ ((__section__(".xxx_section"))) = "foo bar";
> char* y __attribute__ ((__section__(".xxx_section"))) = "Hello
> World!";
>
> int main() {
> return 0;
> }
>
> However, with gcc version 4.3.1 (Debian 4.3.1-9) only the "foo bar"
> string is
> stored in .xxx_section:
>
> $ objdump -s a.out
>
> a.out: file format elf32-i386
> [...]
> Contents of section .rodata:
> 8048448 03000000 01000200 48656c6c 6f20576f ........Hello Wo
> 8048458 726c6421 00 rld!.
> [...]
> Contents of section .xxx_section:
> 8049568 666f6f20 62617200 50840408 foo bar.P...
>
>
> --
> Summary: attribute section is not working with constant
> strings
> Product: gcc
> Version: unknown
> Status: UNCONFIRMED
> Severity: normal
> Priority: P3
> Component: c
> AssignedTo: unassigned at gcc dot gnu dot org
> ReportedBy: nm127 at freemail dot hu
> GCC build triplet: 4.3.1
> GCC target triplet: i486-linux-gnu
>
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37506
>
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37506
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/37506] attribute section is not working with constant strings
2008-09-13 9:05 [Bug c/37506] New: attribute section is not working with constant strings nm127 at freemail dot hu
2008-09-13 9:51 ` [Bug c/37506] " pinskia at gmail dot com
@ 2008-09-13 14:00 ` nm127 at freemail dot hu
2008-09-14 4:46 ` pinskia at gcc dot gnu dot org
` (4 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: nm127 at freemail dot hu @ 2008-09-13 14:00 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from nm127 at freemail dot hu 2008-09-13 13:59 -------
This problem maybe related to bug #192.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37506
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/37506] attribute section is not working with constant strings
2008-09-13 9:05 [Bug c/37506] New: attribute section is not working with constant strings nm127 at freemail dot hu
2008-09-13 9:51 ` [Bug c/37506] " pinskia at gmail dot com
2008-09-13 14:00 ` nm127 at freemail dot hu
@ 2008-09-14 4:46 ` pinskia at gcc dot gnu dot org
2008-09-14 5:33 ` nm127 at freemail dot hu
` (3 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-09-14 4:46 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from pinskia at gcc dot gnu dot org 2008-09-14 04:45 -------
char* y __attribute__ ((__section__(".xxx_section"))) = "Hello World!";
That only puts the pointer variable y into that section and not the string.
The correct way is do like what you do for x.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37506
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/37506] attribute section is not working with constant strings
2008-09-13 9:05 [Bug c/37506] New: attribute section is not working with constant strings nm127 at freemail dot hu
` (2 preceding siblings ...)
2008-09-14 4:46 ` pinskia at gcc dot gnu dot org
@ 2008-09-14 5:33 ` nm127 at freemail dot hu
2008-09-14 5:37 ` pinskia at gcc dot gnu dot org
` (2 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: nm127 at freemail dot hu @ 2008-09-14 5:33 UTC (permalink / raw)
To: gcc-bugs
------- 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
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/37506] attribute section is not working with constant strings
2008-09-13 9:05 [Bug c/37506] New: attribute section is not working with constant strings nm127 at freemail dot hu
` (3 preceding siblings ...)
2008-09-14 5:33 ` nm127 at freemail dot hu
@ 2008-09-14 5:37 ` pinskia at gcc dot gnu dot org
2008-09-14 7:15 ` nm127 at freemail dot hu
2008-09-14 7:56 ` brian at dessent dot net
6 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-09-14 5:37 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from pinskia at gcc dot gnu dot org 2008-09-14 05:36 -------
This is all expected, if you want a string constant to be in a different
section, you need to put there your self by using a variable.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37506
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/37506] attribute section is not working with constant strings
2008-09-13 9:05 [Bug c/37506] New: attribute section is not working with constant strings nm127 at freemail dot hu
` (4 preceding siblings ...)
2008-09-14 5:37 ` pinskia at gcc dot gnu dot org
@ 2008-09-14 7:15 ` nm127 at freemail dot hu
2008-09-14 7:56 ` brian at dessent dot net
6 siblings, 0 replies; 9+ messages in thread
From: nm127 at freemail dot hu @ 2008-09-14 7:15 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from nm127 at freemail dot hu 2008-09-14 07:14 -------
(In reply to comment #5)
> This is all expected, if you want a string constant to be in a different
> section, you need to put there your self by using a variable.
So the __attribute__ __section__ modifier is not recursively applied to all
child element?
If the __attribute__ __section__ is not recursive shouldn't it be possible to
specify explicitly this modifier for the child elements something like "z" and
"w" in comment #4?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37506
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c/37506] attribute section is not working with constant strings
2008-09-13 9:05 [Bug c/37506] New: attribute section is not working with constant strings nm127 at freemail dot hu
` (5 preceding siblings ...)
2008-09-14 7:15 ` nm127 at freemail dot hu
@ 2008-09-14 7:56 ` brian at dessent dot net
6 siblings, 0 replies; 9+ messages in thread
From: brian at dessent dot net @ 2008-09-14 7:56 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from brian at dessent dot net 2008-09-14 07:54 -------
Subject: Re: attribute section is not working with constant strings
If you want a struct containing a pointer to a string in a specified
section, then:
char str[] __attribute__ ((__section__(".xxx_section"))) = "foo";
struct foo {
char *p
} var = { str };
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37506
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Bug c/37506] New: attribute section is not working with constant strings
@ 2008-09-13 9:49 Andrew Thomas Pinski
0 siblings, 0 replies; 9+ messages in thread
From: Andrew Thomas Pinski @ 2008-09-13 9:49 UTC (permalink / raw)
To: gcc-bugzilla; +Cc: gcc-bugs
Sent from my iPhone
On Sep 13, 2008, at 2:04 AM, "nm127 at freemail dot hu" <gcc-bugzilla@gcc.gnu.org
> wrote:
> With the __attribute__ __section__ it is possible to allocate
> variables to
> different section than the default (
> http://gcc.gnu.org/onlinedocs/gcc/Variable-Attributes.html ). In
> case of the
> following source code I would achieve to allocate both "foo bar" and
> "Hello
> World!" strings into the .xxx_section section:
>
> char x[] __attribute__ ((__section__(".xxx_section"))) = "foo bar";
> char* y __attribute__ ((__section__(".xxx_section"))) = "Hello
> World!";
>
> int main() {
> return 0;
> }
>
> However, with gcc version 4.3.1 (Debian 4.3.1-9) only the "foo bar"
> string is
> stored in .xxx_section:
>
> $ objdump -s a.out
>
> a.out: file format elf32-i386
> [...]
> Contents of section .rodata:
> 8048448 03000000 01000200 48656c6c 6f20576f ........Hello Wo
> 8048458 726c6421 00 rld!.
> [...]
> Contents of section .xxx_section:
> 8049568 666f6f20 62617200 50840408 foo bar.P...
>
>
> --
> Summary: attribute section is not working with constant
> strings
> Product: gcc
> Version: unknown
> Status: UNCONFIRMED
> Severity: normal
> Priority: P3
> Component: c
> AssignedTo: unassigned at gcc dot gnu dot org
> ReportedBy: nm127 at freemail dot hu
> GCC build triplet: 4.3.1
> GCC target triplet: i486-linux-gnu
>
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37506
>
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2008-09-14 7:56 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-13 9:05 [Bug c/37506] New: attribute section is not working with constant strings nm127 at freemail dot hu
2008-09-13 9:51 ` [Bug c/37506] " pinskia at gmail dot com
2008-09-13 14:00 ` nm127 at freemail dot hu
2008-09-14 4:46 ` pinskia at gcc dot gnu dot org
2008-09-14 5:33 ` nm127 at freemail dot hu
2008-09-14 5:37 ` pinskia at gcc dot gnu dot org
2008-09-14 7:15 ` nm127 at freemail dot hu
2008-09-14 7:56 ` brian at dessent dot net
2008-09-13 9:49 [Bug c/37506] New: " Andrew Thomas Pinski
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).