crond and non-void function not returning
Yann E. MORIN
yann.morin.1998 at anciens.enib.fr
Sun May 21 20:22:17 UTC 2006
Bernhard,
All,
On Saturday 20 May 2006 153, Bernhard Fischer wrote:
> On Fri, May 19, 2006 at 10:03:34PM +0200, Yann E. MORIN wrote:
> >And using ATTRIBUTE_NORETURN has no effect on a function that is non-void.
> You're right.
No, I'm not totally right, see below...
> So.. that proposed return 0; confuses the optimizers enough to add about
> 50 (or so) bytes to the defconfig binary.
Woupss.. Bad.
> IMA mode
IMA == ? (yep, all sources compiled at once, but acronym means?)
> AFAICS adding a exit(0) or bb_fflush_stdout_and_exit(0) is size-neutral
> for both IMA and legacy compiles, so i will apply the latter instead of
> return 0.
In fact if a non-void function does never return anything, *and* does not call
a __noreturn__ function, than adding __noreturn__ efffectively has no effect
on the former function.
But, if a non-void function does never return anything, *and* does call a
__noreturn__ function, than adding __noreturn__ to the former function removes
the warning.
Examples ( [...] are the CFLAGS used by busybox ):
$ cat foo.c
int foo_main( int argc, char** argv );
int foo_main( int argc, char** argv )
{
while(1) { ; };
}
$ gcc [...] foo.c
foo.c: In function 'foo_main':
foo.c:5: warning: no return statement in function returning non-void
Now let's add the noreturn attribute:
$ cat foo-noret.c
int foo_main(int argc, char** argv) __attribute__ ((_noreturn__));
int foo_main(int argc, char** argv)
{
while (1) { ; };
}
$ gcc [...] foo-noret.c
foo-noret.c: In function 'foo_main':
foo-noret.c:5: warning: no return statement in function returning non-void
And then let's call exit(3) at the bottom of the function body:
$ cat foo-exit.c
#include <stdlib.h>
int foo_main(int argc, char** argv);
int foo_main(int argc, char** argv)
{
while (1) { ; };
exit(0);
}
$ gcc [...] foo-exit.c
$ gcc [...] -Wmissing-noreturn foo-exit.c
foo-exit.c: In function 'foo_main':
foo-exit.c:4: warning: function might be possible candidate for attribute 'noreturn'
And finally with both the attribute and call to exit(3):
$ cat foo-noret-exit.c
#include <stdlib.h>
int foo_main( int argc, char** argv ) __attribute__ ((__noreturn__));
int foo_main( int argc, char** argv )
{
while(1) { ; };
exit(0);
}
$ gcc [...] foo-exit.c
$ gcc [...] -Wmissing-noreturn foo-exit.c
"Et voila." And as Bernhard pointed out, adding a call to exit(3), or to
bb_fflush_stdout_and_exit, is size-neutral.
So the fix by Bernhard is correct.
Regards,
Yann E. MORIN.
--
.-----------------.--------------------.------------------.--------------------.
| Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +0/33 662376056 | Software Designer | \ / CAMPAIGN | ^ |
| --==< °_° >==-- °---.----------------: X AGAINST | /e\ There is no |
| web: ymorin.free.fr | SETI at home 3808 | / \ HTML MAIL | """ conspiracy. |
°---------------------°----------------°------------------°--------------------°
More information about the busybox
mailing list