Page 1 of 1

GCC Segment issue

Posted: Fri Mar 04, 2011 2:10 pm
by pranjas
Hi,

While coding my IDT and GDT descriptor tables which were declared to be global i found out something very strange.

I have a structure named ExceptionGate so i declared 48 of them like this,

Code: Select all

struct ExceptionGate interrupts[48]={0};
GCC does gives a warning but this is
supposedly initialized data
correct?

However when i looked at the objdump of sections of the object file i found out this array was going into the bss section which already housed my stack and things went really ugly guys! Spent almost 3 days figuring out what i did wrong! :(

Finally i appeneded section attribute like this,

Code: Select all

struct ExceptionGate interrupts[48] __attribute__((section(".data")))={0};
which did worked indeed.

So the question is do i've to this everytime i declare a global variable? Anyone else who has done similar thing to get data into correct segments?

These are my CFLAGS for make

Code: Select all

CFLAGS = -c -nostartfiles -nostdlib -nodefaultlibs -fno-builtin -Wall -ffreestanding -fno-common
and CPPFLAGS as

Code: Select all

CPPFLAGS= -c -nostartfiles -nostdlib -nodefaultlibs -fno-builtin -Wall -ffreestanding -fno-rtti -fno-exceptions -nostdinc++ -fno-common
I'm using
gcc (SUSE Linux) 4.4.1 [gcc-4_4-branch revision 150839]