Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsymbolsresolveutils.cpp
Go to the documentation of this file.
1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
6#include <qdebug.h>
7#include <qloggingcategory.h>
8
10
11Q_STATIC_LOGGING_CATEGORY(qLcSymbolsResolver, "qt.multimedia.symbolsresolver");
12
13bool SymbolsResolver::isLazyLoadEnabled()
14{
15 static const bool lazyLoad =
16 !static_cast<bool>(qEnvironmentVariableIntValue("QT_INSTANT_LOAD_FFMPEG_STUBS"));
17 return lazyLoad;
18}
19
20SymbolsResolver::SymbolsResolver(const char *libLoggingName, LibraryLoader loader)
21 : m_libLoggingName(libLoggingName)
22{
23 Q_ASSERT(libLoggingName);
24 Q_ASSERT(loader);
25
26 auto library = loader();
27 if (library && library->isLoaded())
28 m_library = std::move(library);
29 else
30 qCWarning(qLcSymbolsResolver) << "Couldn't load" << m_libLoggingName << "library";
31}
32
33SymbolsResolver::SymbolsResolver(const char *libName, const char *version,
34 const char *libLoggingName)
35 : m_libLoggingName(libLoggingName ? libLoggingName : libName)
36{
37 Q_ASSERT(libName);
38 Q_ASSERT(version);
39
40 auto library = std::make_unique<QLibrary>(QString::fromLocal8Bit(libName),
41 QString::fromLocal8Bit(version));
42 if (library->load())
43 m_library = std::move(library);
44 else
45 qCWarning(qLcSymbolsResolver) << "Couldn't load" << m_libLoggingName << "library";
46}
47
48SymbolsResolver::~SymbolsResolver()
49{
50 if (m_library)
51 m_library->unload();
52}
53
54QFunctionPointer SymbolsResolver::initOptionalFunction(const char *funcName)
55{
56 return m_library ? m_library->resolve(funcName) : nullptr;
57}
58
59QFunctionPointer SymbolsResolver::initFunction(const char *funcName)
60{
61 QFunctionPointer func = initOptionalFunction(funcName);
62
63 if (!func && m_library)
64 {
65 qCWarning(qLcSymbolsResolver) << "Couldn't resolve" << m_libLoggingName << "symbol" << funcName;
66 m_library->unload();
67 m_library.reset();
68 }
69
70 return func;
71}
72
73void SymbolsResolver::checkLibrariesLoaded(SymbolsMarker *begin, SymbolsMarker *end)
74{
75 if (m_library) {
76 qCDebug(qLcSymbolsResolver) << m_libLoggingName << "symbols resolved";
77 } else {
78 const auto size = reinterpret_cast<char *>(end) - reinterpret_cast<char *>(begin);
79 memset(begin, 0, size);
80 qCWarning(qLcSymbolsResolver) << "Couldn't resolve" << m_libLoggingName << "symbols";
81 }
82}
83
84QT_END_NAMESPACE
#define qCWarning(category,...)
#define qCDebug(category,...)
#define Q_STATIC_LOGGING_CATEGORY(name,...)