This is the mail archive of the crossgcc@sources.redhat.com mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more information.


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: How to control location of startup code?


On Wed, Mar 31, 2004 at 04:35:46PM +0200, Toralf Lund wrote:
> I really think there ought to be some way to match the startup code by 
> file name in the linker script, though... Also, in the meantime, I've 
> started wonder if I raelly want to handle crt0 this way. 

It may be worth considering a general alternative to inserting filenames
in the linker script, if only to permit re-use. Taking as a starting
point, this snippet from a gcc linker script:

  .text :
  {
     __code_start = . ;
    *(.vectors)
     __ctors_start = . ;
     *(.ctors)
     __ctors_end = . ;
     __dtors_start = . ;
     *(.dtors)
     __dtors_end = . ;
    *(.progmem.gcc*)
    *(.progmem*)
    . = ALIGN(2);
    *(.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)
    . = ALIGN(2);
    *(.text.*)

Then it is convenient to use this for the vectors:
   .section .vectors,"ax",@progbits
and similarly place the crt0 stuff in .init section(s) of choice.

The vectors are now located at __code_start, as needed, and the crt0 stuff
precedes .text. (If the C++ sections serve only as clutter, we're not
obliged to retain them. :)

What attracts me to this model is the string of fall-through
initialisation sections. They're very useful for additional private
initialisations within individual source files. e.g. hardware set-up.

It works very well for me. It may be of some use in your case.

Erik

------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sources.redhat.com


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