From: Viktor Szakats Date: Sun, 9 Feb 2025 04:12:24 +0000 (+0100) Subject: addrinfo: add curl macro to avoid redefining foreign symbols X-Git-Tag: curl-8_13_0~496 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=de0693f24943cd65f26a7b421a4304cbadb875a0;p=thirdparty%2Fcurl.git addrinfo: add curl macro to avoid redefining foreign symbols Before this patch curl code was redefining `getaddrinfo` and `freeaddrinfo` system symbols to plug in its debug wrappers. This was causing pains to avoid applying the redefinitions to system headers defining these functions, and to the local debug wrappers. Especially in unity builds. It also required workarounds for systems where these symbols are already macros. Introduce curl-namespaced macros for these functions and use them. This allows to drop all workarounds and makes it work in all envs, local targets and unity/bundle combinations. Also drop GHA/windows workaround and use the same unity batch across all jobs. Follow-up to 29e4eda631f46368c2adf833ba3065b1b46c2a7d #16272 Ref: #16272 Ref: 71cf0d1fca9e1f53524e1545ef0c08d174458d80 #14772 Ref: 3efba94f773db5d8ae19e33aa749ab7914cafeea #14765 Ref: f7d5f47059c381502824ef9c1c9a2ca484930c91 #14399 Closes #16274 --- diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 21c2d219dd..2964139335 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -86,7 +86,7 @@ jobs: if [ '${{ matrix.build }}' = 'cmake' ]; then PATH="/usr/bin:$(cygpath "${SYSTEMROOT}")/System32" cmake -B bld -G Ninja ${options} \ - -DCMAKE_UNITY_BUILD=ON -DCMAKE_UNITY_BUILD_BATCH_SIZE=32 -DCURL_TEST_BUNDLES=ON \ + -DCMAKE_UNITY_BUILD=ON -DCMAKE_UNITY_BUILD_BATCH_SIZE=30 -DCURL_TEST_BUNDLES=ON \ -DCURL_WERROR=ON \ ${{ matrix.config }} else @@ -252,7 +252,7 @@ jobs: cmake -B bld -G Ninja ${options} \ -DCMAKE_C_FLAGS="${{ matrix.cflags }} ${CFLAGS_CMAKE} ${CPPFLAGS}" \ -DCMAKE_BUILD_TYPE='${{ matrix.type }}' \ - -DCMAKE_UNITY_BUILD=ON -DCMAKE_UNITY_BUILD_BATCH_SIZE=32 -DCURL_TEST_BUNDLES=ON \ + -DCMAKE_UNITY_BUILD=ON -DCMAKE_UNITY_BUILD_BATCH_SIZE=30 -DCURL_TEST_BUNDLES=ON \ -DCURL_WERROR=ON \ ${{ matrix.config }} else diff --git a/lib/curl_addrinfo.c b/lib/curl_addrinfo.c index 52f0f91255..39cff02f3c 100644 --- a/lib/curl_addrinfo.c +++ b/lib/curl_addrinfo.c @@ -118,7 +118,7 @@ Curl_getaddrinfo_ex(const char *nodename, *result = NULL; /* assume failure */ - error = getaddrinfo(nodename, servname, hints, &aihead); + error = CURL_GETADDRINFO(nodename, servname, hints, &aihead); if(error) return error; @@ -184,7 +184,7 @@ Curl_getaddrinfo_ex(const char *nodename, /* destroy the addrinfo list */ if(aihead) - freeaddrinfo(aihead); + CURL_FREEADDRINFO(aihead); /* if we failed, also destroy the Curl_addrinfo list */ if(error) { @@ -509,7 +509,7 @@ curl_dbg_freeaddrinfo(struct addrinfo *freethis, #ifdef USE_LWIPSOCK lwip_freeaddrinfo(freethis); #else - (freeaddrinfo)(freethis); + freeaddrinfo(freethis); #endif } #endif /* defined(CURLDEBUG) && defined(HAVE_FREEADDRINFO) */ @@ -534,7 +534,7 @@ curl_dbg_getaddrinfo(const char *hostname, #ifdef USE_LWIPSOCK int res = lwip_getaddrinfo(hostname, service, hints, result); #else - int res = (getaddrinfo)(hostname, service, hints, result); + int res = getaddrinfo(hostname, service, hints, result); #endif if(0 == res) /* success */ diff --git a/lib/curl_memory.h b/lib/curl_memory.h index 7f110dab7d..bc3e944fea 100644 --- a/lib/curl_memory.h +++ b/lib/curl_memory.h @@ -84,20 +84,6 @@ #undef socketpair #endif -#ifndef CURL_NO_GETADDRINFO_OVERRIDE -#ifdef HAVE_GETADDRINFO -#if defined(getaddrinfo) && defined(__osf__) -#undef ogetaddrinfo -#else -#undef getaddrinfo -#endif -#endif /* HAVE_GETADDRINFO */ - -#ifdef HAVE_FREEADDRINFO -#undef freeaddrinfo -#endif /* HAVE_FREEADDRINFO */ -#endif /* !CURL_NO_GETADDRINFO_OVERRIDE */ - /* sclose is probably already defined, redefine it! */ #undef sclose #undef fopen diff --git a/lib/curl_setup.h b/lib/curl_setup.h index 7a6ef10b2d..3879f59337 100644 --- a/lib/curl_setup.h +++ b/lib/curl_setup.h @@ -935,6 +935,16 @@ endings either CRLF or LF so 't' is appropriate. #define CURL_ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0])) +#ifdef CURLDEBUG +#define CURL_GETADDRINFO(host,serv,hint,res) \ + curl_dbg_getaddrinfo(host, serv, hint, res, __LINE__, __FILE__) +#define CURL_FREEADDRINFO(data) \ + curl_dbg_freeaddrinfo(data, __LINE__, __FILE__) +#else +#define CURL_GETADDRINFO getaddrinfo +#define CURL_FREEADDRINFO freeaddrinfo +#endif + /* Some versions of the Android NDK is missing the declaration */ #if defined(HAVE_GETPWUID_R) && \ defined(__ANDROID_API__) && (__ANDROID_API__ < 21) diff --git a/lib/memdebug.h b/lib/memdebug.h index 80f3374e52..f45d4925f6 100644 --- a/lib/memdebug.h +++ b/lib/memdebug.h @@ -153,28 +153,6 @@ CURL_EXTERN int curl_dbg_fclose(FILE *file, int line, const char *source); __LINE__, __FILE__) #endif -#ifndef CURL_NO_GETADDRINFO_OVERRIDE -#ifdef HAVE_GETADDRINFO -#if defined(getaddrinfo) && defined(__osf__) -/* OSF/1 and Tru64 have getaddrinfo as a define already, so we cannot define - our macro as for other platforms. Instead, we redefine the new name they - define getaddrinfo to become! */ -#define ogetaddrinfo(host,serv,hint,res) \ - curl_dbg_getaddrinfo(host, serv, hint, res, __LINE__, __FILE__) -#else -#undef getaddrinfo -#define getaddrinfo(host,serv,hint,res) \ - curl_dbg_getaddrinfo(host, serv, hint, res, __LINE__, __FILE__) -#endif -#endif /* HAVE_GETADDRINFO */ - -#ifdef HAVE_FREEADDRINFO -#undef freeaddrinfo -#define freeaddrinfo(data) \ - curl_dbg_freeaddrinfo(data, __LINE__, __FILE__) -#endif /* HAVE_FREEADDRINFO */ -#endif /* !CURL_NO_GETADDRINFO_OVERRIDE */ - /* sclose is probably already defined, redefine it! */ #undef sclose #define sclose(sockfd) curl_dbg_sclose(sockfd,__LINE__,__FILE__) diff --git a/src/tool_operate.c b/src/tool_operate.c index e4b53e21b5..20a8d87b1a 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -50,12 +50,6 @@ #endif #ifdef HAVE_UV_H -/* Hack for Unity mode */ -#ifdef HEADER_CURL_MEMDEBUG_H -#undef HEADER_CURL_MEMDEBUG_H -#undef freeaddrinfo -#undef getaddrinfo -#endif /* this is for libuv-enabled debug builds only */ #include #endif diff --git a/tests/libtest/CMakeLists.txt b/tests/libtest/CMakeLists.txt index 6c1d8e9323..f5f6a0d10c 100644 --- a/tests/libtest/CMakeLists.txt +++ b/tests/libtest/CMakeLists.txt @@ -81,7 +81,6 @@ foreach(_target IN LISTS LIBTESTPROGS) if(NOT CURL_TEST_BUNDLES) set_property(TARGET ${_target_name} APPEND PROPERTY COMPILE_DEFINITIONS ${_upper_target}) endif() - set_property(TARGET ${_target_name} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_NO_GETADDRINFO_OVERRIDE") set_target_properties(${_target_name} PROPERTIES OUTPUT_NAME "${_target}" PROJECT_LABEL "Test libtest ${_target}") diff --git a/tests/libtest/Makefile.am b/tests/libtest/Makefile.am index c1363d8dd7..cccea6723e 100644 --- a/tests/libtest/Makefile.am +++ b/tests/libtest/Makefile.am @@ -90,8 +90,6 @@ libstubgss_la_DEPENDENCIES = endif if USE_TEST_BUNDLES -AM_CPPFLAGS += -DCURL_NO_GETADDRINFO_OVERRIDE - libtest_bundle.c: $(top_srcdir)/tests/mk-bundle.pl lib1521.c @PERL@ $(top_srcdir)/tests/mk-bundle.pl $(srcdir) > libtest_bundle.c diff --git a/tests/server/CMakeLists.txt b/tests/server/CMakeLists.txt index 2ad8b5eed0..3b18bba4c3 100644 --- a/tests/server/CMakeLists.txt +++ b/tests/server/CMakeLists.txt @@ -47,10 +47,6 @@ foreach(_target IN LISTS noinst_PROGRAMS) if(WIN32) set_property(TARGET ${_target_name} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_STATICLIB") endif() - # getaddrinfo/freeaddrinfo overrides break UNITY build by overriding them - # before including system headers. Server code doesn't need these overrides, - # so it's safe to disable them globally. - set_property(TARGET ${_target_name} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_NO_GETADDRINFO_OVERRIDE") set_target_properties(${_target_name} PROPERTIES OUTPUT_NAME "${_target}" PROJECT_LABEL "Test server ${_target}") diff --git a/tests/server/Makefile.am b/tests/server/Makefile.am index 40433f8c5c..c33532fc7c 100644 --- a/tests/server/Makefile.am +++ b/tests/server/Makefile.am @@ -43,7 +43,6 @@ LIBS = $(BLANK_AT_MAKETIME) if DOING_NATIVE_WINDOWS AM_CPPFLAGS += -DCURL_STATICLIB endif -AM_CPPFLAGS += -DCURL_NO_GETADDRINFO_OVERRIDE # Makefile.inc provides neat definitions include Makefile.inc diff --git a/tests/server/resolve.c b/tests/server/resolve.c index 0e8166f70a..78a76daffc 100644 --- a/tests/server/resolve.c +++ b/tests/server/resolve.c @@ -21,10 +21,6 @@ * SPDX-License-Identifier: curl * ***************************************************************************/ -#ifndef CURL_NO_GETADDRINFO_OVERRIDE -#define CURL_NO_GETADDRINFO_OVERRIDE -#endif - #include "server_setup.h" /* Purpose