Skip to content

Commit

Permalink
Network: link directly to libresolv instead of dlopen()ing it
Browse files Browse the repository at this point in the history
There's little need for us to dynamically load it. The reasons why that
was necessary aren't in the public history (Qt 4.5 already had it[1]). I
remember writing the code in 2007-2008, I just don't remember why.

On modern Linux and FreeBSD, there's no libresolv.so any more and those
symbols have been rolled up into libc.so. It's still necessary on Darwin
systems, so this commit introduces WrapResolv.

It also resolves the unity build issues relating to libresolv symbols.

[1] https://code.qt.io/cgit/qt/qt.git/tree/src/network/kernel/qhostinfo_unix.cpp?h=v4.5.1

Task-number: QTBUG-109394
Change-Id: Ic5799e4d000b6c9395109e008780643bac52122b
Reviewed-by: Mårten Nordheim <[email protected]>
  • Loading branch information
amirmasoudabdol authored and thiagomacieira committed May 12, 2023
1 parent ff9da1d commit 68b6259
Show file tree
Hide file tree
Showing 9 changed files with 178 additions and 314 deletions.
49 changes: 49 additions & 0 deletions cmake/FindWrapResolv.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright (C) 2022 The Qt Company Ltd.
# Copyright (C) 2023 Intel Corpotation.
# SPDX-License-Identifier: BSD-3-Clause

# We can't create the same interface imported target multiple times, CMake will complain if we do
# that. This can happen if the find_package call is done in multiple different subdirectories.
if(TARGET WrapResolv::WrapResolv)
set(WrapResolv_FOUND ON)
return()
endif()

set(WrapResolv_FOUND OFF)

include(CheckCXXSourceCompiles)
include(CMakePushCheckState)

if(QNX)
find_library(LIBRESOLV socket)
else()
find_library(LIBRESOLV resolv)
endif()

cmake_push_check_state()
if(LIBRESOLV)
list(APPEND CMAKE_REQUIRED_LIBRARIES "${LIBRESOLV}")
endif()

check_cxx_source_compiles("
#include <netinet/in.h>
#include <resolv.h>
int main(int, char **)
{
res_init();
}
" HAVE_RES_INIT)

cmake_pop_check_state()

if(HAVE_RES_INIT)
set(WrapResolv_FOUND ON)
add_library(WrapResolv::WrapResolv INTERFACE IMPORTED)
if(LIBRESOLV)
target_link_libraries(WrapResolv::WrapResolv INTERFACE "${LIBRESOLV}")
endif()
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(WrapResolv DEFAULT_MSG WrapResolv_FOUND)
39 changes: 16 additions & 23 deletions src/network/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,6 @@ qt_internal_extend_target(Network CONDITION UNIX
kernel/qhostinfo_unix.cpp
socket/qnativesocketengine_unix.cpp
socket/qnet_unix_p.h
NO_UNITY_BUILD_SOURCES
kernel/qhostinfo_unix.cpp # Temporary exclusion until, this,
# https://codereview.qt-project.org/c/qt/qtbase/+/463670
# is merged.
)

qt_internal_extend_target(Network CONDITION QT_FEATURE_dlopen AND UNIX
LIBRARIES
${CMAKE_DL_LIBS}
)

qt_internal_extend_target(Network CONDITION QT_FEATURE_linux_netlink AND UNIX
Expand All @@ -195,11 +186,6 @@ qt_internal_extend_target(Network CONDITION UNIX AND NOT QT_FEATURE_linux_netlin
kernel/qnetworkinterface_unix.cpp
)

qt_internal_extend_target(Network CONDITION ANDROID AND QT_FEATURE_dnslookup
SOURCES
kernel/qdnslookup_android.cpp
)

qt_internal_extend_target(Network CONDITION WIN32
SOURCES
kernel/qhostinfo_win.cpp
Expand All @@ -214,11 +200,6 @@ qt_internal_extend_target(Network CONDITION WIN32
winhttp
)

qt_internal_extend_target(Network CONDITION QT_FEATURE_dnslookup AND WIN32
SOURCES
kernel/qdnslookup_win.cpp
)

qt_internal_extend_target(Network CONDITION APPLE AND NOT UIKIT
LIBRARIES
${FWCoreServices}
Expand All @@ -236,6 +217,22 @@ qt_internal_extend_target(Network CONDITION APPLE
${FWCFNetwork}
)

qt_internal_extend_target(Network CONDITION QT_FEATURE_dnslookup AND TEST_res_ninit
SOURCES
kernel/qdnslookup_unix.cpp
LIBRARIES
WrapResolv::WrapResolv
)

qt_internal_extend_target(Network CONDITION QT_FEATURE_dnslookup AND WIN32
SOURCES
kernel/qdnslookup_win.cpp
)

qt_internal_extend_target(Network CONDITION QT_FEATURE_dnslookup AND NOT TEST_res_ninit AND NOT WIN32
SOURCES
kernel/qdnslookup_dummy.cpp
)

qt_internal_extend_target(Network CONDITION IOS OR MACOS
SOURCES
Expand Down Expand Up @@ -369,10 +366,6 @@ qt_internal_extend_target(Network CONDITION QT_FEATURE_ocsp AND QT_FEATURE_opens
ssl/qocsp_p.h
)

qt_internal_extend_target(Network CONDITION QT_FEATURE_dnslookup AND UNIX AND NOT ANDROID
SOURCES
kernel/qdnslookup_unix.cpp
)
qt_internal_add_docs(Network
doc/qtnetwork.qdocconf
)
Expand Down
26 changes: 25 additions & 1 deletion src/network/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ qt_find_package(Libproxy PROVIDED_TARGETS PkgConfig::Libproxy MODULE_NAME networ
qt_find_package(GSSAPI PROVIDED_TARGETS GSSAPI::GSSAPI MODULE_NAME network QMAKE_LIB gssapi)
qt_find_package(GLIB2 OPTIONAL_COMPONENTS GOBJECT PROVIDED_TARGETS GLIB2::GOBJECT MODULE_NAME core QMAKE_LIB gobject)
qt_find_package(GLIB2 OPTIONAL_COMPONENTS GIO PROVIDED_TARGETS GLIB2::GIO MODULE_NAME core QMAKE_LIB gio)

qt_find_package(WrapResolv PROVIDED_TARGETS WrapResolv::WrapResolv MODULE_NAME network QMAKE_LIB libresolv)

#### Tests

Expand Down Expand Up @@ -100,6 +100,25 @@ ci.ifa_prefered = ci.ifa_valid = 0;
}
")

# res_ninit
qt_config_compile_test(res_ninit
LABEL "res_ninit()"
LIBRARIES
WrapResolv::WrapResolv
CODE
"#include <sys/types.h>
#include <netinet/in.h>
#include <resolv.h>
int main()
{
res_state state;
res_ninit(state);
res_nclose(state);
return 0;
}
"
)

# sctp
qt_config_compile_test(sctp
LABEL "SCTP support"
Expand Down Expand Up @@ -211,6 +230,11 @@ qt_feature("linux-netlink" PRIVATE
LABEL "Linux AF_NETLINK"
CONDITION LINUX AND NOT ANDROID AND TEST_linux_netlink
)
qt_feature("res_ninit" PRIVATE
LABEL "res_ninit()"
CONDITION TEST_res_ninit
AUTODETECT UNIX
)
qt_feature("securetransport" PUBLIC
LABEL "SecureTransport"
CONDITION APPLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void QDnsLookupRunnable::query(const int requestType, const QByteArray &requestN
Q_UNUSED(reply);
qWarning("Not yet supported on Android");
reply->error = QDnsLookup::ResolverError;
reply->errorString = tr("Not yet supported on Android");
reply->errorString = tr("Not yet supported on this OS");
return;
}

Expand Down
Loading

0 comments on commit 68b6259

Please sign in to comment.