1

In my project I defined: (This is not the real code - for abstraction purpose)

typedef struct {
...
} my_struct;

In some C file I declared:

my_struct my_struct_inst;

And in other 2 C files I used that struct by declaring:

extern my_struct my_struct_inst;

and used it's contents.

I compiled that code to ARM with RVCT2.2 and trying to find the address of that structure:

1) When does memory being allocated to my_struct_inst? On compilation time? On run time?

2) In the disassembly I can see that in the .FLASH_RAM section (probably where this kind of data belongs) there is some reference like: my_struct_inst % 0x190 I got it with IDA. What does it mean? (That that struct instance will start at offset 0x190 from the beginning of .FLASH_RAM section?)

3) How exactly the actual address (where the struct actually sitting in memory) is being accessed when I write my_struct_inst.some_member (should I read some ABI documentation?)

Bush
  • 2,433
  • 5
  • 34
  • 57
  • Write some C that says, "&my_struct_inst", compile it to assembly and look at the code. – Charlie Burns Oct 06 '13 at 19:30
  • Do you mean to print the address of the instance in run time? – Bush Oct 06 '13 at 19:42
  • That's what I meant. I think that answers 3), but maybe I misunderstood your question. – Charlie Burns Oct 06 '13 at 19:44
  • 1
    `my_struct_inst % 0x190` means that `my_struct_inst` is 0x190 bytes in size, and its contents is not initialized. – Igor Skochinsky Oct 07 '13 at 13:47
  • Thank's @IgorSkochinsky- You mean that 0x190 bytes allocated to it in the compilation time as Jitesh answered? (so in the elf itself there are 0x190 bytes reserved for it? or is it just an enrty that says my_struct_inst has 0x190 bytes and if it will be used a memory will be allocated to it in run time?) – Bush Oct 07 '13 at 20:40

1 Answers1

2

The memory for your structure will be allocated at compilation time.

The address will be defined by your linker script. To see the address of the structure (assuming it is a global variable), you will need the generated ELF file (lets call it a.elf, for this example). Then just run:

arm-eabi-objdump -t a.elf | grep my_struct_inst

Objdump "-t" will list all global symbols with its address and the section it belongs too. You can replace the "objdump" by any cross-compiled objdump that you have.

Jitesh
  • 73
  • 4