From 166e7922695e9b145e0ce33e3674a1716021a1e3 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 6 Jun 2023 08:47:41 -0700 Subject: [PATCH] QProcess/FreeBSD: remove the workaround allowing undefined symbols On FreeBSD, the environ variable doesn't come from libc, but is instead inserted during linking. See ccf74b592809e0c5a613eff27d6431a4c659e368 (5.6) for more information. But instead of allowing undefined symbols in QtCore, let's use a weakref to environ so this one symbol is allowed to be undefined. It won't be, but the linker doesn't know. FreeBSD appears to be the only BSD to require this. We used to apply the same linker option to OpenBSD in Qt 5, but neither the OpenBSD or nor the NetBSD ports trees[1][2] carry a patch for this, so I don't think it's necessary. [1] https://github.com/openbsd/ports/tree/master/x11/qt6/qtbase/patches [2] https://github.com/NetBSD/pkgsrc/tree/trunk/x11/qt6-qtbase/patches Pick-to: 6.6 Change-Id: I63b988479db546dabffcfffd17661c839014771a Reviewed-by: Oswald Buddenhagen Reviewed-by: Volker Hilsheimer --- src/corelib/CMakeLists.txt | 8 -------- src/corelib/io/qprocess_unix.cpp | 9 +++++---- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/corelib/CMakeLists.txt b/src/corelib/CMakeLists.txt index 5c5d6beaff..9bc5a4380a 100644 --- a/src/corelib/CMakeLists.txt +++ b/src/corelib/CMakeLists.txt @@ -479,14 +479,6 @@ qt_internal_extend_target(Core CONDITION MSVC AND (TEST_architecture_arch STREQU "/BASE:0x67000000" ) -# QtCore can't be compiled with -Wl,-no-undefined because it uses the -# "environ" variable and FreeBSD does not include a weak symbol for it -# in libc. -qt_internal_extend_target(Core CONDITION FREEBSD - LINK_OPTIONS - "LINKER:--warn-unresolved-symbols" -) - qt_internal_extend_target(Core CONDITION QT_FEATURE_xmlstream SOURCES serialization/qxmlstream.cpp serialization/qxmlstream.h serialization/qxmlstream_p.h diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp index abfdfc8c82..9a52916ef1 100644 --- a/src/corelib/io/qprocess_unix.cpp +++ b/src/corelib/io/qprocess_unix.cpp @@ -52,6 +52,11 @@ # define O_PATH 0 #endif +#ifdef Q_OS_FREEBSD +__attribute__((weak)) +#endif +extern char **environ; + QT_BEGIN_NAMESPACE using namespace Qt::StringLiterals; @@ -80,10 +85,6 @@ struct PThreadCancelGuard #if !defined(Q_OS_DARWIN) -QT_BEGIN_INCLUDE_NAMESPACE -extern char **environ; -QT_END_INCLUDE_NAMESPACE - QProcessEnvironment QProcessEnvironment::systemEnvironment() { QProcessEnvironment env;