Hi Dmitry,
Looking good, it should work, some comments.
>....
>
> Subsection init6:
> being linked only when constructors necesary.
> all global constructors will be called here.
> stack pointer will be initialized here with RAM top.
> so, main's attribute reserve(x) will be useless.
more comments later....
> Subsection init9:
> jump to main.
>
> constructors list:
> data pointers to the global constructors. Being accessed from
subsection
> init6 by __do_global_ctors()
>
> destructors list:
> data pointers to the global constructors. Being accessed from
subsection
> fini6 by __do_global_dtors()
You can setup the linker script not to link these in if not required
(generally they are not required on a embedded system with a stop loop
at the end).
I was thinking in the AVR port if there was a way of not putting the
code in for the global destructors that would also save some code space.
The global destructors would have to be put into a section of their own
and then could be linked out if required. I don't know if this is possible.
> .text:
> user code will reside here (including ROMs user defined sections)
>
> Subsection fini9:
> this one where __stop_progExec__ label resides.
> executes one machine insn:
> push r15
>
> Subsection fini6:
> being linked only when destructors necesary.
> all global destructors will be called here.
Could be linked out with the linker script, a good thing.
>...
>
> Actually, this might be much easier (better?) to call constructors
> in main's code just before first main's instruction after stack
> initialization, but then user cannot pass parametres to main().
I think in the C++ spec, the constructors are supposed to be run before
main is run, is it a bit of a hack to put it in the prologue of main?
Hmm, is there some solution to this, the AVR sets up the stack pointer
in the .init2 section.
Ok I see in the AVR port that the stack pointer gets initialized twice,
once in init2 (in avr-libc/crt1/gcrt1.S) and once in the main prologue
(in gcc/config/avr/avr.c avr_function_prolog).
I has always assumed that if you wanted to reserve ram like using the
RESERVE_RAM, that it would be done in the linker script, its the thing
to control where things are put into memory.
Its a bit of a hack but, maybe in the main prologue we could change to the
.init2 section put the stack code in then change back to the .text
section this would get the stack pointer initialized before the
constructors are run and would allow the RESERVE_RAM to also work. Or I
just had a thought, define a symbol here in the main prologue to be the
start of stack then use it in .init2 section to set the stack to the
same place. This symbol could be defined week so it could also be over
ridden by the linker script.
This would be in gcc/config/msp430/msp430.c
msp430_function_prologue(file, size)
{
....
if (main_p)
....
}
> Actually, this might be much easier (better?) to call destructors
> just before returning from main(). But then destructors will not
> be called when execution aborts with abort().
I like the current way, the destructors in a separate section, so they
can be deleted with the linker when not required.
Regards,
--
Peter Jansen
STS
Australian Antarctic Division
Channel Highway
Kingston
TAS 7050
AUSTRALIA
Ph (03) 62 323 533
Fax (03) 62 323 351
___________________________________________________________________________
Australian Antarctic Division - Commonwealth of Australia
IMPORTANT: This transmission is intended for the addressee only. If you are
not the intended recipient, you are notified that use or dissemination of
this communication is strictly prohibited by Commonwealth law. If you have
received this transmission in error, please notify the sender immediately
by e-mail or by telephoning +61 3 6232 3209 and DELETE the message.
Visit our web site at http://www.aad.gov.au/
___________________________________________________________________________