systemd/casync

renameat2 test by meson failing with glibc 2.28-4, linux-headers 4.18.5 on Arch

charles-dyfis-net opened this issue · 1 comments

Building e4a3c5e on current Arch Linux, with glibc 2.28-4, meson.build detects renameat2 as unavailable:

Checking for function "renameat2" : NO

...followed by, later:

In file included from ../src/caformat-util.h:9,
                 from ../src/caremote.c:10:
../src/util.h:532:19: error: static declaration of ‘renameat2’ follows non-static declaration
 static inline int renameat2(int oldfd, const char *oldname, int newfd, const char *newname, unsigned flags) {
                   ^~~~~~~~~
In file included from ../src/util.h:12,
                 from ../src/caformat-util.h:9,
                 from ../src/caremote.c:10:
/usr/include/stdio.h:164:12: note: previous declaration of ‘renameat2’ was here
 extern int renameat2 (int __oldfd, const char *__old, int __newfd,
            ^~~~~~~~~
ninja: build stopped: subcommand failed.

Oddly, though (given that /usr/include/stdio.h does define renameat2 (when __USE_GNU is set), digging through meson-log.txt, it's genuinely not there during the test -- something which remains true when editing meson.build to add #define __USE_GNU 1 to the invocation:

Command line:  cc /tmp/tmp04xnec4t/testfile.c -pipe -D_FILE_OFFSET_BITS=64 -o /tmp/tmp04xnec4t/output.exe -march=x86 -64 -mtune=generic -O2 -fstack-protector-strong -fno-plt -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -O0 -std=gnu99

Code:
 #include <stdio.h>
#include <limits.h>

        #if defined __stub_renameat2 || defined __stub___renameat2
        fail fail fail this function is not going to work
        #endif

int main() {
            void *a = (void*) &renameat2;
            long b = (long) a;
            return (int) b;
        }
Compiler stdout:

Compiler stderr:
 /tmp/tmp04xnec4t/testfile.c: In function 'main':
/tmp/tmp04xnec4t/testfile.c:9:32: error: 'renameat2' undeclared (first use in this function); did you mean 'renameat'?
             void *a = (void*) &renameat2;
                                ^~~~~~~~~
                                renameat

@charles-dyfis-net -- I'm seeing the same issue here, and I'm on the same distro, same kernel version, same glibc:

local/acl 2.2.53-1                                                                               
    Access control list utilities, libraries and headers                                         
local/fuse2 2.9.8-1                                                                              
    A library that makes it possible to implement a filesystem in a userspace program.           
local/curl 7.61.0-2                                                                              
    An URL retrieval utility and library                                                         
local/libgcrypt 1.8.3-1                                                                          
    General purpose cryptographic library based on the code from GnuPG                           
local/libselinux 2.8-1 (selinux)                                                                 
    SELinux library and simple utilities                                                         
local/xz 5.2.4-1                                                                                 
    Library and command line tools for XZ and LZMA compressed files                              
local/zlib 1:1.2.11-3                                                                            
    Compression library implementing the deflate compression method found in gzip and PKZIP      
local/zstd 1.3.5-1                                                                               
    Zstandard - Fast real-time compression algorithm                                             
local/meson 0.47.2-1                                                                             
    High productivity build system                                                               
local/python-sphinx 1.7.6-2                                                                      
    Python3 documentation generator                                                              
local/rsync 3.1.3-1                                                                              
    A file transfer program to keep remote files in sync                                         
local/linux-headers 4.18.4.arch1-1                                                               
    Header files and scripts for building modules for Linux kernel                               
local/glibc 2.28-4 (base)                                                                        
    GNU C Library                                                                                
$ uname -a                                                        
Linux somehost 4.18.4-arch1-1-ARCH #1 SMP PREEMPT Wed Aug 22 07:33:26 UTC 2018 x86_64 GNU/Linux

Following a clue from the meson manual:

System definitions should be passed via compiler args (eg: _GNU_SOURCE is often required for some symbols to be exposed on Linux, and it should be passed via args keyword argument, see below).

I applied this patch:

diff --git a/meson.build b/meson.build
index f42ed16..c0f741e 100644
--- a/meson.build
+++ b/meson.build
@@ -81 +81 @@ foreach ident : [
-        have = cc.has_function(ident[0], prefix : ident[1])
+        have = cc.has_function(ident[0], args : '-D_GNU_SOURCE', prefix : ident[1])

After which both building and testing succeeded.