For some standard functions like memset, the programmer can override the standard function with a custom implementation using -fno-builtin or -fno-builtin-<name>.
That doesn't work for functions like atoi that have inline implementations in the headers. For example:
---- t.c ----
int f1(void *p, const char *s)
memset(p, 0, 16);
With "gcc -S -O2 t.c", both calls get optimized. Adding -fno-builtin-memset suppresses the memset optimization, enabling the programmer to provide their own implementation of memset. Adding -fno-builtin-atoi has no effect.
Would this be considered a bug or a feature? And if the latter, is there a recommended method for suppressing the optimization of atoi without completely disabling inlining or optimization in general?
This is not a bug. You could make the file using atoi declare it itself
rather than including <stdlib.h> (because the type of atoi doesn't involve
any types from standard headers, doing so is valid). Or, again, separate
the use of atoi into a separate file and use -fno-inline for that file.
This is not a bug, the headers are declaring atoi for optimized version.
Thanks for the prompt responses.
Please consider the fact that the same behavior also occurs with "gcc -S -O2 -ffreestanding t.c".
Wouldn't you agree that using the inline implementation of atoi from the headers is a clear violation of freestanding semantics?
<stdlib.h> is not a standard part of a freestanding implementation.