This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: What is .init_array and how does it affext an arm-eabi build for bare metal?


On Thu, 2009-01-22 at 16:52 -0800, Rob Emanuele wrote:
> Hi all,
> 
> I am building an application for a Cortex-m3 processor.  When built
> the map file and executable show a section called .init_array located
> in the chip's main RAM.  This section is not in my linker script.
> What is this section for?  From what I can tell it is stdc++ related
> but I could use more information.  The fact that this ends up in my
> main RAM concerns me as it will be uninitialized upon reset.  If I was
> to add it to my linker script where should it live?

.init_array contains pointers to blocks of code that need to be executed
when an application is being initialized (before main() is called).  Its
used for a number of things, but the primary use is in C++ for running
static constructors; a secondary use that is sometimes used is to
initialize IO systems in the C library.

If you are not using C++ you may (depending on your C library) be able
to live without it entirely; but you'd need to hack your startup code to
deal with this.

.init_array probably ends up in ram because its marked read/write --
that happens because in a dynamic linking environment the dynamic linker
has to fix up all the pointers it contains before it can be used.  In a
static environment you might be able to get away with forcing it into a
read-only section.

R.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]