From ce267bbe37beb94a6128469f6223be5f07168326 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 24 Aug 2018 18:52:10 +0200 Subject: Weak-import global objects used for logging on Apple platforms MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise the dynamic loader will complain about missing symbols when the binary is run on platforms below our supported deployment target: dyld: Symbol not found: __os_activity_current Referenced from: QtCore.framework/Versions/5/QtCore (which was built for Mac OS X 10.12) Expected in: /usr/lib/libSystem.B.dylib in /Users/torarne/build/qt/5.12/qtbase/lib/QtCore.framework/Versions/5/QtCore Trace/BPT trap: 5 We want this to trigger our own logic in qt_apple_check_os_version(), where we tell the user in more friendly terms what's going on. An alternative to the targeted weak imports would be do import the whole library as weak, using -weak-lSystem.B. This doesn't seem to cause any performance issues at startup, but since we only need the two global symbols we stick to the more targeted solution just to be on the safe side. Change-Id: I87c1f185f6dcf9df26c700d31bb5071ddf7685be Reviewed-by: Simon Hausmann Reviewed-by: Tor Arne Vestbø --- src/corelib/kernel/qcore_mac.cpp | 1 + src/corelib/kernel/qcore_mac_p.h | 3 +++ 2 files changed, 4 insertions(+) diff --git a/src/corelib/kernel/qcore_mac.cpp b/src/corelib/kernel/qcore_mac.cpp index 58380001a4..e78b2d1171 100644 --- a/src/corelib/kernel/qcore_mac.cpp +++ b/src/corelib/kernel/qcore_mac.cpp @@ -65,6 +65,7 @@ QCFString::operator CFStringRef() const #if defined(QT_USE_APPLE_UNIFIED_LOGGING) +QT_MAC_WEAK_IMPORT(_os_log_default); bool AppleUnifiedLogger::messageHandler(QtMsgType msgType, const QMessageLogContext &context, const QString &message, const QString &optionalSubsystem) { diff --git a/src/corelib/kernel/qcore_mac_p.h b/src/corelib/kernel/qcore_mac_p.h index 19dddbc2ae..8f2714aa12 100644 --- a/src/corelib/kernel/qcore_mac_p.h +++ b/src/corelib/kernel/qcore_mac_p.h @@ -108,6 +108,8 @@ #define QT_NAMESPACE_ALIAS_OBJC_CLASS(__KLASS__) #endif +#define QT_MAC_WEAK_IMPORT(symbol) extern "C" decltype(symbol) symbol __attribute__((weak_import)); + QT_BEGIN_NAMESPACE template class QAppleRefCounted @@ -326,6 +328,7 @@ private: #define QT_APPLE_LOG_ACTIVITY_WITH_PARENT2(description, parent) QT_APPLE_LOG_ACTIVITY_WITH_PARENT3(true, description, parent) #define QT_APPLE_LOG_ACTIVITY_WITH_PARENT(...) QT_OVERLOADED_MACRO(QT_APPLE_LOG_ACTIVITY_WITH_PARENT, __VA_ARGS__) +QT_MAC_WEAK_IMPORT(_os_activity_current); #define QT_APPLE_LOG_ACTIVITY2(condition, description) QT_APPLE_LOG_ACTIVITY_CREATE(condition, description, OS_ACTIVITY_CURRENT) #define QT_APPLE_LOG_ACTIVITY1(description) QT_APPLE_LOG_ACTIVITY2(true, description) #define QT_APPLE_LOG_ACTIVITY(...) QT_OVERLOADED_MACRO(QT_APPLE_LOG_ACTIVITY, __VA_ARGS__) -- cgit v1.2.3