Re: Checking for built-in functions from build systems
Thank you very much, Jonathan. That's very helpful! This test program: int main() { void *a = alloca(10); return 0; } Compiles fine with: gcc -o test test.c But then fails with: gcc -o test test.c -fno-builtin That's on an Arch Linux system (based on glibc) The issue is that what happens when built-ins are not inlined is not well defined. The libc may not implement the routine, or it's not clear which dependency should provide it. Thanks, Luca Bacci Il giorno mer 10 ago 2022 alle ore 23:27 Jonathan Wakely < jwakely@gmail.com> ha scritto: > > > On Wed, 10 Aug 2022, 23:12 Luca Bacci via Gcc, wrote: > >> >> 1. Is inlining of built-ins dependant only on the target architecture and >> command-line arguments? >> > > No, I think it can depend on the arguments to the built-in as well. > > > 2. If the answer to 1 is yes, could a __is_builtin_inlined (func) macro be >> added to GCC? It should tell whether func is going to be substituted >> inline >> for the given compiler invocation > > > I don't think that can work for some built-ins, e.g. in a single > translation unit memcmp can be inlined for constant arguments of small > size, and not inlined for other calls. > > > >
Re: Checking for built-in functions from build systems
On Wed, 10 Aug 2022, 23:12 Luca Bacci via Gcc, wrote: > > 1. Is inlining of built-ins dependant only on the target architecture and > command-line arguments? > No, I think it can depend on the arguments to the built-in as well. 2. If the answer to 1 is yes, could a __is_builtin_inlined (func) macro be > added to GCC? It should tell whether func is going to be substituted inline > for the given compiler invocation I don't think that can work for some built-ins, e.g. in a single translation unit memcmp can be inlined for constant arguments of small size, and not inlined for other calls.
Checking for built-in functions from build systems
Hello dear GCC developers, I am working on an issue in Meson wrt GCC built-in functions, see https://github.com/mesonbuild/meson/issues/10641. As you already know, some built-ins are always inlined, while others are inlined only at times (e.g. depending on the target architecture) and resolve to a regular function call otherwise. The issue is about the latter's, i.e. those that may emit regular function calls. In fact, even though __has_builtin(func) evaluates to 1, func may not be present in libraries (libgcc, libc, libm), causing linking errors if not inlined. Because some of the GCC built-in functions are not part of the C standard (e.g. sincos), it's not worthwhile to require having implementations in libc. In addition, should generic implementations be added to libgcc, those would likely have sub-par performance or accuracy issues (being generic). As such, I think that a build system should check if an implementation of a conditionally-inlined built-in function is provided in the target libc. I have a few questions: 1. Is inlining of built-ins dependant only on the target architecture and command-line arguments? 2. If the answer to 1 is yes, could a __is_builtin_inlined (func) macro be added to GCC? It should tell whether func is going to be substituted inline for the given compiler invocation 3. Is it true that conditionally-inlined built-ins are exactly those that come in the two variants of '__builtin_func' and 'func'? Thanks, Luca Bacci