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
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.