From 7e6aeead85c0831b054f095f35677abb49e9b984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Tue, 28 Mar 2023 20:30:06 +0300 Subject: [PATCH] glibc: add backwards compatibility for some symbols - `fcntl` was renamed to `fcntl64` in glibc 2.28 (see #9485) - `res_{,n}{search,query,querydomain}` became "their own" symbols since glibc 2.34: they were prefixed with `__` before. This PR makes it possible to use `fcntl` with glibc 2.27 or older and the `res_*` functions with glibc 2.33 or older. These patches will become redundant with universal-headers and can be dropped. But we have to do with what we have now. Closes #9485 --- lib/libc/glibc/io/fcntl.h | 7 +++++++ lib/libc/include/generic-glibc/fcntl.h | 8 ++++++++ lib/libc/include/generic-glibc/resolv.h | 22 ++++++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/lib/libc/glibc/io/fcntl.h b/lib/libc/glibc/io/fcntl.h index 8917a73b42..5c76999da3 100644 --- a/lib/libc/glibc/io/fcntl.h +++ b/lib/libc/glibc/io/fcntl.h @@ -167,6 +167,10 @@ typedef __pid_t pid_t; effective IDs, not real IDs. */ #endif + +/* fcntl was a simple symbol until glibc 2.27 inclusive. glibc 2.28 onwards + * re-defines it to fcntl64 (via #define) if _FILE_OFFSET_BITS == 64. */ +#if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 28) || __GLIBC__ > 2 /* Do the file control operation described by CMD on FD. The remaining arguments are interpreted depending on CMD. @@ -197,6 +201,9 @@ extern int __fcntl_time64 (int __fd, int __request, ...) __THROW; # define fcntl __fcntl_time64 # endif #endif +#else /* glibc 2.27 or lower */ +extern int fcntl (int __fd, int __cmd, ...); +#endif /* Open FILE and return a new file descriptor for it, or -1 on error. OFLAG determines the type of access used. If O_CREAT or O_TMPFILE is set diff --git a/lib/libc/include/generic-glibc/fcntl.h b/lib/libc/include/generic-glibc/fcntl.h index ceeb63138b..fb93ee658b 100644 --- a/lib/libc/include/generic-glibc/fcntl.h +++ b/lib/libc/include/generic-glibc/fcntl.h @@ -167,6 +167,11 @@ typedef __pid_t pid_t; effective IDs, not real IDs. */ #endif + +/* fcntl was a simple symbol until glibc 2.27 inclusive. + * glibc 2.28 onwards converted it to a macro when compiled with + * USE_LARGEFILE64. */ +#if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 28) || __GLIBC__ > 2 /* Do the file control operation described by CMD on FD. The remaining arguments are interpreted depending on CMD. @@ -197,6 +202,9 @@ extern int __fcntl_time64 (int __fd, int __request, ...) __THROW; # define fcntl __fcntl_time64 # endif #endif +#else /* glibc 2.27 or lower */ +extern int fcntl (int __fd, int __cmd, ...); +#endif /* Open FILE and return a new file descriptor for it, or -1 on error. OFLAG determines the type of access used. If O_CREAT or O_TMPFILE is set diff --git a/lib/libc/include/generic-glibc/resolv.h b/lib/libc/include/generic-glibc/resolv.h index aadb9e79a7..406727e8fb 100644 --- a/lib/libc/include/generic-glibc/resolv.h +++ b/lib/libc/include/generic-glibc/resolv.h @@ -169,6 +169,28 @@ __END_DECLS #define res_init __res_init #define res_isourserver __res_isourserver +/* In glibc 2.33 and earlier res_search, res_nsearch, res_query, res_nquery, + * res_querydomain, res_nquerydomain were #define'd to __res_search, + * __res_nsearch, etc. glibc 2.34 onwards removes the macros and exposes the + * symbols directly. New glibc exposes compat symbols with underscores for + * backwards compatibility. Applications linked to glibc 2.34+ are expected + * to use the non-underscored symbols. + * + * It will be enough to bring the macros back when compiling against the older + * glibc versions. + * + * See glibc commit ea9878ec271c791880fcbbe519d70c42f8113750. + */ +#if (__GLIBC__ == 2 && __GLIBC_MINOR__ < 34) +#define res_search __res_search +#define res_nsearch __res_nsearch +#define res_query __res_query +#define res_nquery __res_nquery +#define res_querydomain __res_querydomain +#define res_nquerydomain __res_nquerydomain +#endif +/* end glibc compat hacks */ + #ifdef _LIBC # define __RESOLV_DEPRECATED # define __RESOLV_DEPRECATED_MSG(msg)