This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: .init .text .fini
- From: Erik Christiansen <erik at dd dot nec dot com dot au>
- To: binutils at sources dot redhat dot com
- Date: Thu, 5 May 2005 16:32:53 +1000
- Subject: Re: .init .text .fini
- References: <7f45d9390505042133324516f0@mail.gmail.com>
On Wed, May 04, 2005 at 09:33:35PM -0700, Shaun Jackman wrote:
> Why do the symbols _init and _fini sit in their own segments .init and
> .fini rather than in .text?
Because initialisation normally precedes the main act (.text), and
finish comes after? ;)
> I'm trying to generate a binary suitable for a flash image in an
> embedded system where the start symbol is at the first address, but
> with the default linker script -- armelf.xc in my case -- _init from
> .init is being placed before _mainCRTStartup from .text.
Err .. that sounds perfectly normal doesn't it?. Anything in .text is
post-init code, since your compiler/assembler directives will have
placed initialisation in a .init section? As just one example, avr-gcc
default linker script offers ten init sections:
*(.init0) /* Start here after reset. */
*(.init1)
*(.init2) /* Clear __zero_reg__, set up stack pointer. */
*(.init3)
*(.init4) /* Initialize data and BSS. */
*(.init5)
*(.init6) /* C++ constructors. */
*(.init7)
*(.init8)
*(.init9) /* Call main(). */
*(.text)
Of course, one's own init stuff can be placed wherever it does the most
good.
> Could the default order in ld/scripttempl/elf.sc be changed to .text
> .init .fini rather than the current .init .text .fini, or would this
> break something?
If it is OK to have the code at _init run when/if execution falls off
the end of .text, then by all means you could modify your linker script
to do that. (But running a system's initialisation just before it shuts
down does look a little odd. ;)
hth
Erik