From 8a425026820cab9ea4b4e8bb05afde9f1092edd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 6 Sep 2013 23:16:28 +0200 Subject: iOS: Change main-wrapper logic to not require changing the user's main MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of using a define to rename the user's main() function during compilation, we leave the user code alone, and inject our wrapper one step earlier in the process, at the application entry point 'start'. This entry point is provided by crt1.o, which is normally linked into the application automatically. The start() function sets up some state and then calls main(), but we change the start() function to instead call our main wrapper. Instead of shipping our own crt1 binary/sources, we make a copy of the appropriate crt1.o at build time, and modify its symbol table in place. This is unproblematic as long as we keep the same length for the wrapper function name, as the symbol names are just entries in the global string table of the object file. The result is that for the regular Qt use-case the user won't see any changes to their main function, and we have more control over the startup sequence. For the hybrid use-case, we no longer rely on the fragile solution of having our back-up 'main' symbol in a single translation unit, which would break eg with --load_all, and we don't need to provide a dummy 'qt_user_main' symbol. OSX 10.8 and iOS 6.0 introduced a new load command called LC_MAIN, which places the state setup in the shared dyld, and then just calls main() directly. Once we bump the minimum deployment target to iOS 6.0 we can start using this loader instead of LC_UNIXTHREAD, but for now we force the classic loader using the -no_new_main flag. There's also a bug in the ld64 linker provided by the current Xcode toolchains that results in the -e linker flag (to set the entry point) having no effect, but hopefully this bug has been fixed (or Apple has switched to the LLVM lld linker) by the time we bump our deployment target. Change-Id: Ie0ba869c13ddc5277dc95c539aebaeb60e949dc2 Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/ios/qiosmain_wrapper.mm | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'src/plugins/platforms/ios/qiosmain_wrapper.mm') diff --git a/src/plugins/platforms/ios/qiosmain_wrapper.mm b/src/plugins/platforms/ios/qiosmain_wrapper.mm index d9b8c7311e..cb9a2c161e 100644 --- a/src/plugins/platforms/ios/qiosmain_wrapper.mm +++ b/src/plugins/platforms/ios/qiosmain_wrapper.mm @@ -41,18 +41,7 @@ #include "qiosapplicationdelegate.h" -/* - This file provides a wrapper implementation of main() for the non- - hybrid use-case. The user's main is renamed to qt_user_main by the - build rules, and we'll call out to that main at the appropriate time. - - This file purposly only exports a single symbol, _main, so that - when the linker considers the translation unit for inclusion it - will discard it when main has already been defined in the user's - application for the hybrid use-case. -*/ - -int main(int argc, char *argv[]) +extern "C" int qtmn(int argc, char *argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([QIOSApplicationDelegate class])); -- cgit v1.2.3