authorgravatar for motiejus@jakstys.ltMotiejus Jakštys <motiejus@jakstys.lt> 2023-03-28 20:30:06+03:00
committergravatar for motiejus@jakstys.ltMotiejus Jakštys <motiejus@jakstys.lt> 2023-03-28 20:35:08+03:00
log7e6aeead85c0831b054f095f35677abb49e9b984
tree1ab1d49a83ff07586d15eb4f8284d10c504bece5
parent43487eb3ef0933c1da53b917c44ba6070d8e5a21

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

3 files changed, 37 insertions(+), 0 deletions(-)

lib/libc/glibc/io/fcntl.h+7
...@@ -167,6 +167,10 @@ typedef __pid_t pid_t;...@@ -167,6 +167,10 @@ typedef __pid_t pid_t;
167 effective IDs, not real IDs. */167 effective IDs, not real IDs. */
168#endif168#endif
169169
170
171/* fcntl was a simple symbol until glibc 2.27 inclusive. glibc 2.28 onwards
172 * re-defines it to fcntl64 (via #define) if _FILE_OFFSET_BITS == 64. */
173#if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 28) || __GLIBC__ > 2
170/* Do the file control operation described by CMD on FD.174/* Do the file control operation described by CMD on FD.
171 The remaining arguments are interpreted depending on CMD.175 The remaining arguments are interpreted depending on CMD.
172176
...@@ -197,6 +201,9 @@ extern int __fcntl_time64 (int __fd, int __request, ...) __THROW;...@@ -197,6 +201,9 @@ extern int __fcntl_time64 (int __fd, int __request, ...) __THROW;
197# define fcntl __fcntl_time64201# define fcntl __fcntl_time64
198# endif202# endif
199#endif203#endif
204#else /* glibc 2.27 or lower */
205extern int fcntl (int __fd, int __cmd, ...);
206#endif
200207
201/* Open FILE and return a new file descriptor for it, or -1 on error.208/* Open FILE and return a new file descriptor for it, or -1 on error.
202 OFLAG determines the type of access used. If O_CREAT or O_TMPFILE is set209 OFLAG determines the type of access used. If O_CREAT or O_TMPFILE is set
lib/libc/include/generic-glibc/fcntl.h+8
...@@ -167,6 +167,11 @@ typedef __pid_t pid_t;...@@ -167,6 +167,11 @@ typedef __pid_t pid_t;
167 effective IDs, not real IDs. */167 effective IDs, not real IDs. */
168#endif168#endif
169169
170
171/* fcntl was a simple symbol until glibc 2.27 inclusive.
172 * glibc 2.28 onwards converted it to a macro when compiled with
173 * USE_LARGEFILE64. */
174#if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 28) || __GLIBC__ > 2
170/* Do the file control operation described by CMD on FD.175/* Do the file control operation described by CMD on FD.
171 The remaining arguments are interpreted depending on CMD.176 The remaining arguments are interpreted depending on CMD.
172177
...@@ -197,6 +202,9 @@ extern int __fcntl_time64 (int __fd, int __request, ...) __THROW;...@@ -197,6 +202,9 @@ extern int __fcntl_time64 (int __fd, int __request, ...) __THROW;
197# define fcntl __fcntl_time64202# define fcntl __fcntl_time64
198# endif203# endif
199#endif204#endif
205#else /* glibc 2.27 or lower */
206extern int fcntl (int __fd, int __cmd, ...);
207#endif
200208
201/* Open FILE and return a new file descriptor for it, or -1 on error.209/* Open FILE and return a new file descriptor for it, or -1 on error.
202 OFLAG determines the type of access used. If O_CREAT or O_TMPFILE is set210 OFLAG determines the type of access used. If O_CREAT or O_TMPFILE is set
lib/libc/include/generic-glibc/resolv.h+22
...@@ -169,6 +169,28 @@ __END_DECLS...@@ -169,6 +169,28 @@ __END_DECLS
169#define res_init __res_init169#define res_init __res_init
170#define res_isourserver __res_isourserver170#define res_isourserver __res_isourserver
171171
172/* In glibc 2.33 and earlier res_search, res_nsearch, res_query, res_nquery,
173 * res_querydomain, res_nquerydomain were #define'd to __res_search,
174 * __res_nsearch, etc. glibc 2.34 onwards removes the macros and exposes the
175 * symbols directly. New glibc exposes compat symbols with underscores for
176 * backwards compatibility. Applications linked to glibc 2.34+ are expected
177 * to use the non-underscored symbols.
178 *
179 * It will be enough to bring the macros back when compiling against the older
180 * glibc versions.
181 *
182 * See glibc commit ea9878ec271c791880fcbbe519d70c42f8113750.
183 */
184#if (__GLIBC__ == 2 && __GLIBC_MINOR__ < 34)
185#define res_search __res_search
186#define res_nsearch __res_nsearch
187#define res_query __res_query
188#define res_nquery __res_nquery
189#define res_querydomain __res_querydomain
190#define res_nquerydomain __res_nquerydomain
191#endif
192/* end glibc compat hacks */
193
172#ifdef _LIBC194#ifdef _LIBC
173# define __RESOLV_DEPRECATED195# define __RESOLV_DEPRECATED
174# define __RESOLV_DEPRECATED_MSG(msg)196# define __RESOLV_DEPRECATED_MSG(msg)