avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Missing "call main()" in startup code


From: Georg-Johann Lay
Subject: Re: [avr-gcc-list] Missing "call main()" in startup code
Date: Tue, 15 Nov 2011 23:04:58 +0100
User-agent: Mozilla Thunderbird 1.0.7 (Windows/20050923)

Dave Harper schrieb:
Hi Johann,

Thanks for your response. Right now I'm having list subscription problems (working with the moderator on that) so I can only reply directly by email.

The post you saw was actually written several days ago but was only posted this morning by the moderator. I have made some progress since then but a basic question still remains. I find that when I used the -nostartfiles linker option that I still get variable initialization (both .data and .bss). Missing is the stack, status register and ramp register initializations, along with the call to main (and exit). This is what surprised me - I expected that I would

The startup code is a blend of code from libgcc and avr-libc.
Some parts are dragged in by magic (vectors) others are dragged in by
referencing them. Notice the references to __do_copy_data and/or
__do_clear_bss in avr-gcc's assembler output.

get nothing and would have to roll my own C runtime code.  Since then
I've found that the -nostdlib linker option does eliminate everything, freeing me to write my own startup code. This leads me to the question of what good is the -nostartfiles option? It's nice that it has the variable initialization, but without a call to main at the end, the startup code is basically useless if compiling with optimization. Do you have any thoughts or insights on this?

-nostartfiles is a GCC option, it's not specific to avr-gcc, and
generally default start-up code is used or not used by -nostartfiles.

This is a bit different for AVR because some parts of startup code are
only linked if they are really needed. For example, if nothing is in
.data there is no need to initialize it. This was introduced to help
small devices with very tiny flash. It is accomplished by referencing
these pieces if needed -- at least in newer versions of avr-gcc, older
versions drag in unconditonally.

-nostartfiles is not passed to the compiler proper; it's just passed to
the compiler driver (the thing that calls the compiler, assembler, linker for you). And up to now no one extended this to pass the
information down to cc1 or cc1plus so that the compiler won't issue the
mentioned references in presence of -nostartfiles.

Please notice that the GNU AVR tools are short of developer and these
issues are not in the center of priotity.

If nostdlib is too much of reduction you can write you own __do_copy_data like so:

.global __do_copy_data
.section .init4,"ax",@progbits
__do_copy_data:
        ; your code

Johann

Thanks, Dave



reply via email to

[Prev in Thread] Current Thread [Next in Thread]