Hello, On Mon, Jan 22, 2024 at 8:05 PM Peter Maydell <peter.mayd...@linaro.org> wrote: > > On Thu, 18 Jan 2024 at 16:03, Manolo de Medici <manolodemed...@gmail.com> > wrote: > > > > Compilation fails on systems where copy_file_range is already defined as a > > stub. > > What do you mean by "stub" here ? If the system headers define > a prototype for the function, I would have expected the > meson check to set HAVE_COPY_FILE_RANGE, and then this > function doesn't get defined at all. That is, the prototype > mismatch shouldn't matter because if the prototype exists we > use the libc function, and if it doesn't then we use our version.
Let me answer :) glibc has this stubs mechanism: a function can be declared in the system headers, but only implemented as a stub that always fails with ENOSYS (or some such). You get a linker warning at link time if you call such a function. For example on GNU/Linux, remove(2) is a stub, and if I try to use it, the code does compile, but I get /usr/bin/ld: /tmp/ccLCnRnW.o: in function `main': demo.c:(.text+0xa): warning: revoke is not implemented and will always fail during linking. This is done by embedding a '.gnu.warning.function-name' section inside libc.so (try readelf --wide --section-headers /lib64/libc.so.6 | grep warning). You can also find the list of stubs in the gnu/stubs.h header, which contains definitions like __stub_revoke. Meson's has_function() knows about this mechanism, and returns false if the function is declared, but is actually just a stub (by looking for "__stub_{func}" being defined); autoconf does, too. But as the prototype is still declared (and the function technically exists, too, even if it's a stub), you'll get errors if you define the same function incompatibly yourself. Sergey