Freestanding ARM C++ Code - empty .ctors section
- by Matthew Iselin
I'm writing C++ code to run in a freestanding environment (basically an ARM board). It's been going well except I've run into a stumbling block - global static constructors.
To my understanding the .ctors section contains a list of addresses to each static constructor, and my code simply needs to iterate this list and make calls to each function as it goes. However, I've found that this section in my binary is in fact completely empty! Google pointed towards using ".init_array" instead of ".ctors" (an EABI thing), but that has not changed anything.
Any ideas as to why my static constructors don't exist? Relevant linker script and objdump output follows:
.ctors :
{
. = ALIGN(4096);
start_ctors = .;
*(.init_array);
*(.ctors);
end_ctors = .;
}
.dtors :
{
. = ALIGN(4096);
start_dtors = .;
*(.fini_array);
*(.dtors);
end_dtors = .;
}
--
2 .ctors 00001000 8014c000 8014c000 00054000 2**2
CONTENTS, ALLOC, LOAD, DATA
<snip>
8014d000 g O .ctors 00000004 start_ctors
<snip>
8014d000 g O .ctors 00000004 end_ctors
I'm using an arm-elf targeted GCC compiler (4.4.1).