diff options
author | Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com> | 2015-06-17 14:39:02 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com> | 2015-06-29 12:39:50 +0000 |
commit | c937bbb4fe708f7f873ca630c6ff225f9a3f9ace (patch) | |
tree | 99b4e9191a887458b92de08f2ff72903ec89cd70 /mkspecs/macx-ios-clang/features | |
parent | 7b0cb2ffa3e4a1fec6ac716f7c82c42e2bacbb2a (diff) |
iOS: Use LC_MAIN to wrap user main() instead of mangling object files
With iOS 6.0 and above the LC_MAIN load command is available, which allows
dyld to call the application entrypoint directly instead of going through
_start in crt.o. By passing -e to the linker we can change this entrypoint
to our wrapper that sets up the separate stack before entering the native
iOS runloop through UIApplicationMain. As before, we call the user's main()
from applicationDidFinishLaunching.
By using LC_MAIN instead of messing with the object files we open up the
possibility of generating Bitcode instead of object code, which can be
useful for link-time optimizations, either locally or by Apple.
Change-Id: If2153bc919581cd93dfa10fb6ff1c305b3e39a52
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@theqtcompany.com>
Diffstat (limited to 'mkspecs/macx-ios-clang/features')
-rw-r--r-- | mkspecs/macx-ios-clang/features/qt.prf | 34 |
1 files changed, 6 insertions, 28 deletions
diff --git a/mkspecs/macx-ios-clang/features/qt.prf b/mkspecs/macx-ios-clang/features/qt.prf index 9e6b486c6e..474a195e4b 100644 --- a/mkspecs/macx-ios-clang/features/qt.prf +++ b/mkspecs/macx-ios-clang/features/qt.prf @@ -19,34 +19,12 @@ equals(TEMPLATE, app):contains(qt_depends, gui(-private)?) { QTPLUGIN.platforms = - !no_main_wrapper { - # We use ld to rename the _main symbol to _qt_main, so that we don't get a symbol clash - # with the _main we provide that calls UIApplicationMain. We need to make a copy of the - # original object file, as ld will not copy over DWARF debug information to the output - # file. Instead, it will inject a reference back to the original object file, so when - # Xcode runs dsymutil to make the final dSYM file it will still find the debug info - # for the object file that provided the original _main. This back-reference has the - # interesting side-effect of the debug information still referring to the original - # symbol name, so stack-traces will show both our wrapper main and the original - # user main as 'main', and adding a symbolic breakpoint for 'main' will break on - # both functions. Although a bit weird, it's a good thing, as the user will still be - # able to add symbolic breakpoints for 'main', not caring that the symbol is actually - # called 'qt_main' now. - - macx-xcode { - objects_dir = "\"${OBJECT_FILE_DIR}-${CURRENT_VARIANT}\"" - archs = "\"${ARCHS}\"" - } else { - isEmpty(OBJECTS_DIR): \ - objects_dir = . - else: \ - objects_dir = $$shell_quote($$OBJECTS_DIR) - archs = $$shell_quote($$QMAKE_IOS_DEVICE_ARCHS $$QMAKE_IOS_SIMULATOR_ARCHS) - } - - !isEmpty(QMAKE_PRE_LINK): \ - QMAKE_PRE_LINK += ";" - - QMAKE_PRE_LINK += $$shell_quote($$QMAKESPEC/rename_main.sh) $$objects_dir $$archs + # The LC_MAIN load command available in iOS 6.0 and above allows dyld to + # directly call the entrypoint instead of going through _start in crt.o. + # Passing -e to the linker changes the entrypoint from _main to our custom + # wrapper that calls UIApplicationMain and dispatches back to main() once + # the application has started up and is ready to initialize QApplication. + QMAKE_LFLAGS += -Wl,-e,_qt_main_wrapper } } |