tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
alloca again
This TODO item has been in libc's shlib_version file for ages:
"remove alloca fallback and expect compiler to provide a builtin version."
On various architectures (powerpc, aarch64), pkgsrc bulk build reports
are filled with the following error:
"undefined reference to `alloca'"
On other architectures (amd64), the software quietly compiles,
but the produced code is probably buggy, and you get this warning:
"Warning: reference to the libc supplied alloca(3); this most likely will
not work. Please use the compiler provided version of alloca(3), by
supplying the appropriate compiler flags (e.g. not -std=c89)."
The message is potentially misleading, you have to use -std=gnuXX, and
for C++11 something like -std=gnu++11. This has to be fixed in a lot
of software, presumably because other operating systems don't impose
this requirement (they're arguably wrong, but let's leave that there
for now).
I'd argue that providing alloca(3) as anything except a compiler
builtin is a bug, and that kind of thing should never be used.
This is the current alloca definition in the libc headers:
#if defined(_NETBSD_SOURCE)
#if defined(alloca) && (alloca == __builtin_alloca) && \
defined(__GNUC__) && (__GNUC__ < 2)
void *alloca(int); /* built-in for gcc */
#elif defined(__PCC__) && !defined(__GNUC__)
#define alloca(size) __builtin_alloca(size)
#else
void *alloca(size_t);
#endif /* __GNUC__ */
It could be simplified to this:
#if defined(_NETBSD_SOURCE)
#define alloca(size) __builtin_alloca(size)
#endif
Is there any reason we don't simplify this in the headers -
__builtin_alloca(size) seems to work with every compiler?
Home |
Main Index |
Thread Index |
Old Index