summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@digia.com>2013-10-16 19:06:47 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-10-17 13:26:28 +0200
commit32f34ddbe1a57255194703955730058386789cf8 (patch)
treee576bbc3e81a42ecf8064d7f533e43dc5afce1a8 /src/plugins
parentb5fe1ed1724a34765a91faa135b2dd98e1941f58 (diff)
iOS: Wrap user's main by renaming symbol and relying on weak linking
This approach is similar to the earlier apprach of defining main=qt_main when building the user's sources, but uses the linker to rename the symbol instead, which is less fragile than using the preprocessor. To keep the hybrid usecase unaffected by our wrapper logic we declare both our main wrapper and a fallback qt_main as weak symbols, which ensures that when the user's application links in our plugin the real main/qt_main provided by the user is preferred over our weak symbols. Change-Id: Ic76f3ba8932430c4b13a1d3a40b8ed2322fe5eea Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/platforms/ios/qioseventdispatcher.mm17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/plugins/platforms/ios/qioseventdispatcher.mm b/src/plugins/platforms/ios/qioseventdispatcher.mm
index 9991a59d9e..3dd9c7ad9f 100644
--- a/src/plugins/platforms/ios/qioseventdispatcher.mm
+++ b/src/plugins/platforms/ios/qioseventdispatcher.mm
@@ -213,7 +213,7 @@ static int infoPlistValue(NSString* key, int defaultValue)
return value ? [value intValue] : defaultValue;
}
-extern "C" int qtmn(int argc, char *argv[])
+extern "C" int __attribute__((weak)) main(int argc, char *argv[])
{
@autoreleasepool {
size_t defaultStackSize = 512 * kBytesPerKiloByte; // Same as secondary threads
@@ -248,7 +248,18 @@ enum SetJumpResult
kJumpedFromUserMainTrampoline,
};
-extern "C" int main(int argc, char *argv[]);
+// We define qt_main so that user_main_trampoline() will not cause
+// missing symbols in the case of hybrid applications that don't
+// user our main wrapper. Since the symbol is weak, it will not
+// get used or cause a clash in the normal Qt application usecase,
+// where we rename main to qt_main.
+extern "C" int __attribute__((weak)) qt_main(int argc, char *argv[])
+{
+ Q_UNUSED(argc);
+ Q_UNUSED(argv);
+
+ Q_UNREACHABLE();
+}
static void __attribute__((noinline, noreturn)) user_main_trampoline()
{
@@ -261,7 +272,7 @@ static void __attribute__((noinline, noreturn)) user_main_trampoline()
strcpy(argv[i], [arg cStringUsingEncoding:[NSString defaultCStringEncoding]]);
}
- int exitCode = main(argc, argv);
+ int exitCode = qt_main(argc, argv);
delete[] argv;
qEventDispatcherDebug() << "Returned from main with exit code " << exitCode;