public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Checking for built-in functions from build systems
@ 2022-08-10 21:11 Luca Bacci
  2022-08-10 21:27 ` Jonathan Wakely
  0 siblings, 1 reply; 3+ messages in thread
From: Luca Bacci @ 2022-08-10 21:11 UTC (permalink / raw)
  To: gcc

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Checking for built-in functions from build systems
  2022-08-10 21:11 Checking for built-in functions from build systems Luca Bacci
@ 2022-08-10 21:27 ` Jonathan Wakely
  2022-08-10 22:16   ` Luca Bacci
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Wakely @ 2022-08-10 21:27 UTC (permalink / raw)
  To: Luca Bacci; +Cc: gcc

On Wed, 10 Aug 2022, 23:12 Luca Bacci via Gcc, <gcc@gcc.gnu.org> 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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Checking for built-in functions from build systems
  2022-08-10 21:27 ` Jonathan Wakely
@ 2022-08-10 22:16   ` Luca Bacci
  0 siblings, 0 replies; 3+ messages in thread
From: Luca Bacci @ 2022-08-10 22:16 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc

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.gcc@gmail.com> ha scritto:

>
>
> On Wed, 10 Aug 2022, 23:12 Luca Bacci via Gcc, <gcc@gcc.gnu.org> 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.
>
>
>
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-08-10 22:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-10 21:11 Checking for built-in functions from build systems Luca Bacci
2022-08-10 21:27 ` Jonathan Wakely
2022-08-10 22:16   ` Luca Bacci

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).