Skip to content

build: auto-detect the presence of the openat2() syscall#925

Open
mmayer wants to merge 2 commits into
RsyncProject:masterfrom
mmayer:openat2_autodetect
Open

build: auto-detect the presence of the openat2() syscall#925
mmayer wants to merge 2 commits into
RsyncProject:masterfrom
mmayer:openat2_autodetect

Conversation

@mmayer
Copy link
Copy Markdown

@mmayer mmayer commented May 29, 2026

Let configure detect if the openat2() syscall is supported by the kernel headers we are building against. Do not attempt to use openat2() if support is not present.

Users can still disable using the openat2() syscall manually if so desired.

Let configure detect if the openat2() syscall is supported by the kernel
headers we are building against. Do not attempt to use openat2() if
support is not present.

Users can still disable using the openat2() syscall manually if so
desired.

Signed-off-by: Markus Mayer <mmayer@broadcom.com>
@mmayer
Copy link
Copy Markdown
Author

mmayer commented May 29, 2026

This is for issue 924.

@satmandu
Copy link
Copy Markdown

Note that this doesn't fix make check:

gcc -I. -I. -I./zlib -O3 -pipe -ffat-lto-objects -fPIC -fuse-ld=mold  -flto=auto -flto=auto -DHAVE_CONFIG_H -Wall -W  -c tls.c -o tls.o
gcc -I. -I. -I./zlib -O3 -pipe -ffat-lto-objects -fPIC -fuse-ld=mold  -flto=auto -flto=auto -DHAVE_CONFIG_H -Wall -W  -c t_stub.c -o t_stub.o
gcc -I./zlib -O3 -pipe -ffat-lto-objects -fPIC -fuse-ld=mold  -flto=auto -flto=auto -DHAVE_CONFIG_H -Wall -W -flto=auto -o tls tls.o syscall.o util2.o t_stub.o lib/compat.o lib/snprintf.o lib/permstring.o lib/sysxattrs.o  -lacl -lpopt -llz4 -lzstd -lxxhash -lcrypto 
gcc -I. -I. -I./zlib -O3 -pipe -ffat-lto-objects -fPIC -fuse-ld=mold  -flto=auto -flto=auto -DHAVE_CONFIG_H -Wall -W  -c getgroups.c -o getgroups.o
gcc -I./zlib -O3 -pipe -ffat-lto-objects -fPIC -fuse-ld=mold  -flto=auto -flto=auto -DHAVE_CONFIG_H -Wall -W -flto=auto -o getgroups getgroups.o -lacl -lpopt -llz4 -lzstd -lxxhash -lcrypto 
gcc -I. -I. -I./zlib -O3 -pipe -ffat-lto-objects -fPIC -fuse-ld=mold  -flto=auto -flto=auto -DHAVE_CONFIG_H -Wall -W  -c getfsdev.c -o getfsdev.o
gcc -I./zlib -O3 -pipe -ffat-lto-objects -fPIC -fuse-ld=mold  -flto=auto -flto=auto -DHAVE_CONFIG_H -Wall -W -flto=auto -o getfsdev getfsdev.o -lacl -lpopt -llz4 -lzstd -lxxhash -lcrypto 
gcc -I. -I. -I./zlib -O3 -pipe -ffat-lto-objects -fPIC -fuse-ld=mold  -flto=auto -flto=auto -DHAVE_CONFIG_H -Wall -W  -c testrun.c -o testrun.o
gcc -I./zlib -O3 -pipe -ffat-lto-objects -fPIC -fuse-ld=mold  -flto=auto -flto=auto -DHAVE_CONFIG_H -Wall -W -flto=auto -o testrun testrun.o
gcc -I. -I. -I./zlib -O3 -pipe -ffat-lto-objects -fPIC -fuse-ld=mold  -flto=auto -flto=auto -DHAVE_CONFIG_H -Wall -W  -c trimslash.c -o trimslash.o
gcc -I./zlib -O3 -pipe -ffat-lto-objects -fPIC -fuse-ld=mold  -flto=auto -flto=auto -DHAVE_CONFIG_H -Wall -W -flto=auto -o trimslash trimslash.o syscall.o util2.o t_stub.o lib/compat.o lib/snprintf.o -lacl -lpopt -llz4 -lzstd -lxxhash -lcrypto 
gcc -I. -I. -I./zlib -O3 -pipe -ffat-lto-objects -fPIC -fuse-ld=mold  -flto=auto -flto=auto -DHAVE_CONFIG_H -Wall -W  -c t_unsafe.c -o t_unsafe.o
gcc -I./zlib -O3 -pipe -ffat-lto-objects -fPIC -fuse-ld=mold  -flto=auto -flto=auto -DHAVE_CONFIG_H -Wall -W -flto=auto -o t_unsafe t_unsafe.o syscall.o util1.o util2.o t_stub.o lib/compat.o lib/snprintf.o lib/wildmatch.o -lacl -lpopt -llz4 -lzstd -lxxhash -lcrypto 
gcc -I. -I. -I./zlib -O3 -pipe -ffat-lto-objects -fPIC -fuse-ld=mold  -flto=auto -flto=auto -DHAVE_CONFIG_H -Wall -W  -c t_chmod_secure.c -o t_chmod_secure.o
t_chmod_secure.c:22:10: fatal error: linux/openat2.h: No such file or directory
   22 | #include <linux/openat2.h>
      |          ^~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:72: t_chmod_secure.o] Error 1

@mmayer
Copy link
Copy Markdown
Author

mmayer commented May 29, 2026

It works for me. I just tried again after "make distclean".

$ ls -l rsync -rwxrwxr-x 1 mmayer mmayer 2276384 May 29 10:04 rsync

This is with Ubuntu 18.04.

Did you regenerate configure.sh after applying the patch? What does config.log have to say about detecting the presence of SYS_openat2?

You should see something like this.

[...]
checking whether to enable rolling-checksum SIMD optimizations... yes (x86_64)
checking if assembler accepts noexecstack... yes
checking for openat2... no
checking for broken largefile support... no
checking for special C compiler options needed for large files... no
[...]

And in config.log:

[...]
configure.sh:6286: checking for openat2
configure.sh:6305: gcc -c -g -O2 -DHAVE_CONFIG_H -Wall -W  conftest.c >&5
conftest.c: In function 'main':
conftest.c:72:9: error: 'SYS_openat2' undeclared (first use in this function); did you mean 'SYS_openat'?
 int i = SYS_openat2
         ^~~~~~~~~~~
         SYS_openat
conftest.c:72:9: note: each undeclared identifier is reported only once for each function it appears in
conftest.c:72:5: warning: unused variable 'i' [-Wunused-variable]
 int i = SYS_openat2
     ^
[...]

@mmayer
Copy link
Copy Markdown
Author

mmayer commented May 29, 2026

But I see what you mean re: "make check". Let me take a look. ... That's because t_chmod_secure.c only has

#if defined(__linux__)

instead of

#if defined(__linux__) && defined(HAVE_OPENAT2)

Let me add that change to the pull request.

To prevent using openat2() in situations where it is not supported, use
    #if defined(__linux__) && defined(HAVE_OPENAT2)
in t_chmod_secure.c, just like it was already being done in syscall.c.

Signed-off-by: Markus Mayer <mmayer@broadcom.com>
@mmayer
Copy link
Copy Markdown
Author

mmayer commented May 29, 2026

BTW, make check was already failing in this situation before my patch. So that is nothing new.

@mmayer
Copy link
Copy Markdown
Author

mmayer commented May 29, 2026

My pull request is now updated to fix t_chmod_secure.c (i.e. make check) as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants