Re: [patch, avr-libc] Fix atexit.c
Joern Rennecke <[email protected]>
| Newsgroups | gmane.comp.hardware.avr.gcc |
|---|---|
| Message-ID | <CAMqJFCpR6bJ0Jss7SoU_tU88bJcQfNoTw-AV+c74sgmKzYnJNg@mail.gmail.com> |
On 14 October 2014 11:43, Georg-Johann Lay <[email protected]> wrote: > atexit.c has several issues which are fixed by the patch below: > > > i) > Issuance of calls to functions as registered by atexit() is located in > section .fini6a. As the current linker description does not handle that > section it's treated as orphan and located conflicting with other sections: I actually wrote a binutils patch at the same time as the atexit implementation: [email protected]:embecosm/avr-binutils-gdb.git branch avr-mainline commit 640411f2fb984e70c4ab06154089692db1734a97 I just haven't gotten around to push this to the main repo yet. > ii) > __atexit_fini is not naked thus will crash the program as it is returning. Good point. However, I'd prefer to add a new attribute to just say that the function returns by falling through at the end. Opinions on how to name this? "fallthrough" ? "return_falls_through" ? "ctor_dtor" (although that can get confusing with the constructor / destructor attribute) ? Overload the meaning of the section attribute so that .init / .fini section 'magically' causes the different return? +atexit_finido (void) { - while (__atexit_p) + while (atexit_p) { - void (*fun) (void) = __atexit_p->fun; - __atexit_p = __atexit_p->next; - (*fun) (); + atexit_p->fun(); + atexit_p = atexit_p->next; This introduces a bug. If the called function calls exit (e.g. because it throws an error), you get an infinite recursion. The pointer must be updated before the function is called.