Bug List: (This bug is not in your last search results)   Show last search results      Search page      Enter new bug
Bug#: 37506
Product:  
Component:  
Status: RESOLVED
Resolution: INVALID
Assigned To: Not yet assigned to anyone <unassigned@gcc.gnu.org>
Host:
Reported against  
Priority:  
Severity:  
Target Milestone:  
 
 
Target:
Reporter: Márton Németh <nm127@freemail.hu>
Add CC:
CC:
Remove selected CCs
Build:
URL:
Summary:
Keywords:
Known to work:
Known to fail:

Attachment Description Type Created Size Actions
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 37506 depends on: Show dependency tree
Show dependency graph
Bug 37506 blocks:

Additional Comments:






View Bug Activity   |   Format For Printing   |   Clone This Bug


Description:   Last confirmed: Opened: 2008-09-13 09:04
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...

------- Comment #1 From pinskia@gmail.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
>

------- Comment #2 From Márton Németh 2008-09-13 13:59 -------
This problem maybe related to bug #192.

------- Comment #3 From Andrew Pinski 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.

------- Comment #4 From Márton Németh 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.

------- Comment #5 From Andrew Pinski 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.

------- Comment #6 From Márton Németh 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?

------- Comment #7 From Brian Dessent 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 };

Bug List: (This bug is not in your last search results)   Show last search results      Search page      Enter new bug