Bug 32458 - __attribute((section(".myname"))) is not working as expected in G++ but works ni GCC
Summary: __attribute((section(".myname"))) is not working as expected in G++ but works...
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.2.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-06-21 16:21 UTC by Prem
Modified: 2007-06-21 20:34 UTC (History)
1 user (show)

See Also:
Host: x86_64-pc-linux
Target: x86_64-pc-linux
Build: x86_64-pc-linux
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Prem 2007-06-21 16:21:30 UTC
I used the simple program provided in the gcc help pages.
i am using gcc-4.2.0 cross compiler for ARM (I think the problem
should persist in native compilers as well)

------------a.c--------
#include <stdio.h>
int main(void) {
static int  a __attribute__ ((section (".offsets"))) = 0;
static int myname __attribute__ ((section (".offsets"))) =  0 ;
//static char stack[10000] __attribute__ ((section (".stack"))) =
{ 0 };
static int init_data __attribute__ ((section (".prems"))) = 0;

        printf("Hellow world %d\n", 0);
        return 0;
}

---------------------------

---------------a.cc----------------
#include <stdio.h>
int main(void) {
static int  a __attribute__ ((section (".offsets"))) = 0;
static int myname __attribute__ ((section (".offsets"))) =  0 ;
//static char stack[10000] __attribute__ ((section (".stack"))) =
{ 0 };
static int init_data __attribute__ ((section (".prems"))) = 0;

        printf("Hellow world %d\n", 0);
        return 0;
}

-------------------------------------

The files 'a.c' and 'a.cc' are the same except that the 'a.cc' is
treated as c++ file.
in a.o created from 'a.c' has the sections. but the a.o created from
'a.cc' doesn't have

command used:
arm-none-linux-gnueabi-gcc -c a.c

arm-none-linux-gnueabi-gcc -c a.cc

Please let me know if I am wrong here, or let me know if there is a
workaround to make the 'a.cc' to have the sections compiled in.

/Prem
Comment 1 Andrew Pinski 2007-06-21 20:34:22 UTC
You forgot to mark the variables as being used.
You mark the variable used with the attribute used.
Once you do that, the variables are emitted.
This is not a bug but by design that GCC can optimize out unused variables, even the ones marked with a different section.