Weak-import global objects used for logging on Apple platforms

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 <simon.hausmann@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Tor Arne Vestbø 2018-08-24 18:52:10 +02:00
parent 42588a8487
commit ce267bbe37
2 changed files with 4 additions and 0 deletions

View File

@ -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)
{

View File

@ -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 <typename T, typename U, U (*RetainFunction)(U), void (*ReleaseFunction)(U)>
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__)