I am trying to move from assembler to C programming on the AVR while
avoiding unnecessary overhead. I see that crt1/gcrt1.S contains the
following code:
.section .init9,"ax",@progbits
#ifdef __AVR_ASM_ONLY__
XJMP main
#else /* !__AVR_ASM_ONLY__ */
XCALL main
XJMP exit
#endif /* __AVR_ASM_ONLY__ */
The above references to main() and exit() are needed for complying with
the C standard. However, I would tend to believe that normally programs
written for bare metal (such as the AVR) never terminate. Such programs
do not need an exit() function or even a call or jump to main().
Would it be possible to introduce a (necessarily non-standard) option
that allows the .init9 section of the runtime libary to be omitted?
Then, the user could declare their infinite main loop something like
this:
__attribute__((naked)) __attribute__((section(".init9")))
static
void
mainloop (void)
{
for (;;) do_my_stuff ();
}
This would save 3 instructions and some RAM (call main/ret, jump exit).
I am aware of the linker options -nostartfiles -nostdlib, but I do want
the interrupt table and the sections .init0 through .init8.
Perhaps .linkonce or some clever use of .weak could help here? Or
perhaps an alternative crt.o file could be provided for a minimal
startup?
I would have tried to patch gcrt1.S myself, but I am having trouble
setting up the build environment.
Best regards,
Marko
_______________________________________________
AVR-libc-dev mailing list
AVR-libc-dev@nongnu.org
https://lists.nongnu.org/mailman/listinfo/avr-libc-dev