Build system support for LTO
authorkrollin@apple.com <krollin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 27 Aug 2018 17:16:17 +0000 (17:16 +0000)
committerkrollin@apple.com <krollin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 27 Aug 2018 17:16:17 +0000 (17:16 +0000)
https://bugs.webkit.org/show_bug.cgi?id=187785
<rdar://problem/42353132>

Reviewed by Dan Bernstein.

.:

Add support for building WebKit with LTO (Link Time Optimization) on
macOS and iOS. Both variations are supported: "full" (which performs
all the optimizations it can regardless of the cost) and "thin" (which
sacrifices some optimizations in order to recover build time and
memory usage).

By default, LTO is disabled for Debug and Release builds, but is
enabled for Production builds. For Debug and Release builds, LTO is
controlled as follows:

- When using `make` from the command line, include
  WK_LTO_MODE={none,thin,full}. For example, `make WK_LTO_MODE=full
  release`. As when specifying debug/release, the LTO configuration
  information is written to the WebKitBuild directory and is used as
  the default on the next build if a new setting is not specified.

- When using `build-webkit`, include --lto-mode={none,thin,full} on
  the command line. For example, `build-webkit --lto-mode=full ...`.

- When using Xcode, create a configuration file called
  LocalOverrides.xcconfig at the root level of your WebKit checkout
  directory. Include within it a line that says:

    WK_LTO_MODE={none,thin,full}

  For example:

    WK_LTO_MODE=full

Note that LocalOverrides.xcconfig is included in the .gitignore file,
so you won't accidentally check your changes into source control.

Enabling LTO can greatly increase build times, especially when using
"full" LTO with 32GB or RAM or less. Following is a table of full
build times for a Release build on a fully decked-out 2017 iMac Pro:

    LTO     macOS      iOS
    -----  -------   -------
    None:   9m 11s   14m 11s
    Thin:  11m 44s   17m 30s
    Full:  21m 39s   28m 56s

Incremental times are affected even more greatly. The actual
optimization and compilation of LLVM bitcode is moved to the link
phase, meaning that the link phase, which previously took only
seconds, can now take many minutes. It's for this reason that LTO is
not enabled in Debug and Release builds, since incremental builds are
an integral part of those configurations. However, using the
mechanisms described above, developers can perform optional LTO builds
if needed to track down build or runtime issues in that configuration.

* .gitignore: Include LocalOverrides.xcconfig.
* Makefile.shared: Add support for WK_LTO_MODE on the command line.

Source/bmalloc:

Update Base.xcconfig and DebugRelease.xcconfig to optionally enable
LTO.

* Configurations/Base.xcconfig:
* Configurations/DebugRelease.xcconfig:

Source/JavaScriptCore:

Update Base.xcconfig and DebugRelease.xcconfig to optionally enable
LTO.

* Configurations/Base.xcconfig:
* Configurations/DebugRelease.xcconfig:

Source/ThirdParty/ANGLE:

Update Base.xcconfig and DebugRelease.xcconfig to optionally enable
LTO.

* Configurations/Base.xcconfig:
* Configurations/DebugRelease.xcconfig:

Source/ThirdParty/libwebrtc:

Update Base.xcconfig and DebugRelease.xcconfig to optionally enable
LTO.

* Configurations/Base.xcconfig:
* Configurations/DebugRelease.xcconfig:

Source/WebCore:

Update Base.xcconfig and DebugRelease.xcconfig to optionally enable
LTO.

No new tests -- no new WebKit functionality.

* Configurations/Base.xcconfig:
* Configurations/DebugRelease.xcconfig:

Source/WebCore/PAL:

Update Base.xcconfig and DebugRelease.xcconfig to optionally enable
LTO.

* Configurations/Base.xcconfig:
* Configurations/DebugRelease.xcconfig:

Source/WebInspectorUI:

Update Base.xcconfig and DebugRelease.xcconfig to optionally enable
LTO.

* Configurations/Base.xcconfig:
* Configurations/DebugRelease.xcconfig:

Source/WebKit:

Update Base.xcconfig and DebugRelease.xcconfig to optionally enable
LTO.

* Configurations/Base.xcconfig:
* Configurations/DebugRelease.xcconfig:

Source/WebKitLegacy/mac:

Update Base.xcconfig and DebugRelease.xcconfig to optionally enable
LTO.

* Configurations/Base.xcconfig:
* Configurations/DebugRelease.xcconfig:

Source/WTF:

Update Base.xcconfig and DebugRelease.xcconfig to optionally enable
LTO.

* Configurations/Base.xcconfig:
* Configurations/DebugRelease.xcconfig:

Tools:

Add tools/scripts support for controlling LTO builds.

* Scripts/build-webkit: Add --lto-mode={none,thin,full}.
* Scripts/set-webkit-configuration: Add support for saving LTO
configuration to WebKitBuild/LTO.
* Scripts/webkitdirs.pm: Add support for reading configuration from
WebKitBuild/LTO and providing it to xcodebuild.
(determineLTOMode):
(ltoMode):
(XcodeOptions):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@235381 268f45cc-cd09-0410-ab3c-d52691b4dbfc

37 files changed:
.gitignore
ChangeLog
Makefile.shared
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/Configurations/Base.xcconfig
Source/JavaScriptCore/Configurations/DebugRelease.xcconfig
Source/ThirdParty/ANGLE/ChangeLog
Source/ThirdParty/ANGLE/Configurations/Base.xcconfig
Source/ThirdParty/ANGLE/Configurations/DebugRelease.xcconfig
Source/ThirdParty/libwebrtc/ChangeLog
Source/ThirdParty/libwebrtc/Configurations/Base.xcconfig
Source/ThirdParty/libwebrtc/Configurations/DebugRelease.xcconfig
Source/WTF/ChangeLog
Source/WTF/Configurations/Base.xcconfig
Source/WTF/Configurations/DebugRelease.xcconfig
Source/WebCore/ChangeLog
Source/WebCore/Configurations/Base.xcconfig
Source/WebCore/Configurations/DebugRelease.xcconfig
Source/WebCore/PAL/ChangeLog
Source/WebCore/PAL/Configurations/Base.xcconfig
Source/WebCore/PAL/Configurations/DebugRelease.xcconfig
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/Configurations/Base.xcconfig
Source/WebInspectorUI/Configurations/DebugRelease.xcconfig
Source/WebKit/ChangeLog
Source/WebKit/Configurations/Base.xcconfig
Source/WebKit/Configurations/DebugRelease.xcconfig
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/Configurations/Base.xcconfig
Source/WebKitLegacy/mac/Configurations/DebugRelease.xcconfig
Source/bmalloc/ChangeLog
Source/bmalloc/Configurations/Base.xcconfig
Source/bmalloc/Configurations/DebugRelease.xcconfig
Tools/ChangeLog
Tools/Scripts/build-webkit
Tools/Scripts/set-webkit-configuration
Tools/Scripts/webkitdirs.pm

index e934031..58531f5 100644 (file)
@@ -48,3 +48,6 @@ __cmake_systeminformation/
 
 # Ignore YouCompleteMe symlinks
 .ycm_extra_conf.py
+
+# Local overrides configuration files
+LocalOverrides.xcconfig
index 1f2ea2b..0d86582 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,65 @@
+2018-08-27  Keith Rollin  <krollin@apple.com>
+
+        Build system support for LTO
+        https://bugs.webkit.org/show_bug.cgi?id=187785
+        <rdar://problem/42353132>
+
+        Reviewed by Dan Bernstein.
+
+        Add support for building WebKit with LTO (Link Time Optimization) on
+        macOS and iOS. Both variations are supported: "full" (which performs
+        all the optimizations it can regardless of the cost) and "thin" (which
+        sacrifices some optimizations in order to recover build time and
+        memory usage).
+
+        By default, LTO is disabled for Debug and Release builds, but is
+        enabled for Production builds. For Debug and Release builds, LTO is
+        controlled as follows:
+
+        - When using `make` from the command line, include
+          WK_LTO_MODE={none,thin,full}. For example, `make WK_LTO_MODE=full
+          release`. As when specifying debug/release, the LTO configuration
+          information is written to the WebKitBuild directory and is used as
+          the default on the next build if a new setting is not specified.
+
+        - When using `build-webkit`, include --lto-mode={none,thin,full} on
+          the command line. For example, `build-webkit --lto-mode=full ...`.
+
+        - When using Xcode, create a configuration file called
+          LocalOverrides.xcconfig at the root level of your WebKit checkout
+          directory. Include within it a line that says:
+
+            WK_LTO_MODE={none,thin,full}
+
+          For example:
+
+            WK_LTO_MODE=full
+
+        Note that LocalOverrides.xcconfig is included in the .gitignore file,
+        so you won't accidentally check your changes into source control.
+
+        Enabling LTO can greatly increase build times, especially when using
+        "full" LTO with 32GB or RAM or less. Following is a table of full
+        build times for a Release build on a fully decked-out 2017 iMac Pro:
+
+            LTO     macOS      iOS
+            -----  -------   -------
+            None:   9m 11s   14m 11s
+            Thin:  11m 44s   17m 30s
+            Full:  21m 39s   28m 56s
+
+        Incremental times are affected even more greatly. The actual
+        optimization and compilation of LLVM bitcode is moved to the link
+        phase, meaning that the link phase, which previously took only
+        seconds, can now take many minutes. It's for this reason that LTO is
+        not enabled in Debug and Release builds, since incremental builds are
+        an integral part of those configurations. However, using the
+        mechanisms described above, developers can perform optional LTO builds
+        if needed to track down build or runtime issues in that configuration.
+
+        * .gitignore: Include LocalOverrides.xcconfig.
+        * Makefile.shared: Add support for WK_LTO_MODE on the command line.
+
 2018-08-27  Michael Catanzaro  <mcatanzaro@igalia.com>
 
         Unreviewed, bump WPE/GTK version numbers
index b318440..7d1feb1 100644 (file)
@@ -56,6 +56,14 @@ ASAN_OPTION=--no-asan
 endif
 endif
 
+ifeq ($(WK_LTO_MODE),full)
+WK_LTO_OPTION=--lto-mode=full
+else ifeq ($(WK_LTO_MODE),thin)
+WK_LTO_OPTION=--lto-mode=thin
+else ifeq ($(WK_LTO_MODE),none)
+WK_LTO_OPTION=--lto-mode=none
+endif
+
 export DSYMUTIL_NUM_THREADS = $(shell sysctl -n hw.activecpu)
 
 # Run xcodebuild with the same PATH with which the Xcode IDE runs, to mitigate unnecessary rebuilds due to PATH differences.
@@ -66,15 +74,15 @@ all: set_asan_configuration
        ( $(SET_COLOR_DIAGNOSTICS_ARG); xcodebuild $(OTHER_OPTIONS) $(XCODE_OPTIONS) | $(OUTPUT_FILTER) && exit $${PIPESTATUS[0]} )
 
 debug d development dev develop: force
-       $(SCRIPTS_PATH)/set-webkit-configuration --debug $(ASAN_OPTION)
+       $(SCRIPTS_PATH)/set-webkit-configuration --debug $(ASAN_OPTION) $(WK_LTO_OPTION)
        ( $(SET_COLOR_DIAGNOSTICS_ARG); xcodebuild $(OTHER_OPTIONS) $(XCODE_OPTIONS) | $(OUTPUT_FILTER) && exit $${PIPESTATUS[0]} )
 
 release r deployment dep deploy: force
-       $(SCRIPTS_PATH)/set-webkit-configuration --release $(ASAN_OPTION)
+       $(SCRIPTS_PATH)/set-webkit-configuration --release $(ASAN_OPTION) $(WK_LTO_OPTION)
        ( $(SET_COLOR_DIAGNOSTICS_ARG); xcodebuild $(OTHER_OPTIONS) $(XCODE_OPTIONS) | $(OUTPUT_FILTER) && exit $${PIPESTATUS[0]} )
 
 analyze:
-       $(SCRIPTS_PATH)/set-webkit-configuration --debug $(ASAN_OPTION)
+       $(SCRIPTS_PATH)/set-webkit-configuration --debug $(ASAN_OPTION) $(WK_LTO_OPTION)
 ifndef PATH_TO_SCAN_BUILD
        ( $(SET_COLOR_DIAGNOSTICS_ARG); xcodebuild $(OTHER_OPTIONS) $(XCODE_OPTIONS) RUN_CLANG_STATIC_ANALYZER=YES | $(OUTPUT_FILTER) && exit $${PIPESTATUS[0]} )
 else
index ffb5eee..31eed76 100644 (file)
@@ -1,3 +1,17 @@
+2018-08-27  Keith Rollin  <krollin@apple.com>
+
+        Build system support for LTO
+        https://bugs.webkit.org/show_bug.cgi?id=187785
+        <rdar://problem/42353132>
+
+        Reviewed by Dan Bernstein.
+
+        Update Base.xcconfig and DebugRelease.xcconfig to optionally enable
+        LTO.
+
+        * Configurations/Base.xcconfig:
+        * Configurations/DebugRelease.xcconfig:
+
 2018-08-27  Patrick Griffis  <pgriffis@igalia.com>
 
         [GTK][JSC] Add warn_unused_result attribute to some APIs
index 8fce987..72907a8 100644 (file)
@@ -178,3 +178,18 @@ WK_COCOA_TOUCH_watchsimulator = cocoatouch;
 WK_COCOA_TOUCH_appletvos = cocoatouch;
 WK_COCOA_TOUCH_appletvsimulator = cocoatouch;
 WK_IS_COCOA_TOUCH = $(WK_NOT_$(WK_EMPTY_$(WK_COCOA_TOUCH)));
+
+LLVM_LTO = $(WK_LLVM_LTO_$(WK_XCODE_SUPPORTS_LTO));
+WK_LLVM_LTO_NO = NO;
+WK_LLVM_LTO_YES = $(WK_USER_LTO_MODE);
+
+WK_XCODE_SUPPORTS_LTO = $(WK_NOT_$(WK_XCODE_VERSION_BEFORE_9_$(XCODE_VERSION_MAJOR)));
+WK_XCODE_VERSION_BEFORE_9_0800 = YES;
+WK_XCODE_VERSION_BEFORE_9_0700 = YES;
+
+WK_USER_LTO_MODE = $(WK_USER_LTO_MODE_$(WK_LTO_MODE));
+WK_USER_LTO_MODE_full = NO; // Disable LTO for JavaScript due to <rdar://problem/24543547>
+WK_USER_LTO_MODE_thin = NO; // Disable LTO for JavaScript due to <rdar://problem/24543547>
+WK_USER_LTO_MODE_none = NO;
+WK_USER_LTO_MODE_ = $(WK_DEFAULT_LTO_MODE);
+WK_DEFAULT_LTO_MODE = $(WK_USER_LTO_MODE_full);
index ef5fb0a..f9a7564 100644 (file)
@@ -22,6 +22,7 @@
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 
 #include "Base.xcconfig"
+#include? "../../../LocalOverrides.xcconfig"
 
 ARCHS = $(ARCHS_STANDARD_32_64_BIT);
 
@@ -44,5 +45,7 @@ SDKROOT_YES = macosx.internal;
 
 WK_RELOCATABLE_FRAMEWORKS = YES;
 
+WK_DEFAULT_LTO_MODE = $(WK_USER_LTO_MODE_none);
+
 WK_CCACHE_DIR = $(SRCROOT)/../../Tools/ccache;
 #include "../../../Tools/ccache/ccache.xcconfig"
index 83e0596..3720ace 100644 (file)
@@ -1,3 +1,17 @@
+2018-08-27  Keith Rollin  <krollin@apple.com>
+
+        Build system support for LTO
+        https://bugs.webkit.org/show_bug.cgi?id=187785
+        <rdar://problem/42353132>
+
+        Reviewed by Dan Bernstein.
+
+        Update Base.xcconfig and DebugRelease.xcconfig to optionally enable
+        LTO.
+
+        * Configurations/Base.xcconfig:
+        * Configurations/DebugRelease.xcconfig:
+
 2018-08-03  Alex Christensen  <achristensen@webkit.org>
 
         Fix spelling of "overridden"
index 93c9700..17d5d22 100644 (file)
@@ -81,3 +81,18 @@ ANGLE_INSTALL_PATH_PREFIX_DEPLOYMENT_YES_USE_ALTERNATE_YES = $(WK_ALTERNATE_FRAM
 WK_PLATFORM_NAME = $(WK_PLATFORM_NAME_USE_ALTERNATE_FRAMEWORKS_DIR_$(WK_USE_ALTERNATE_FRAMEWORKS_DIR));
 WK_PLATFORM_NAME_USE_ALTERNATE_FRAMEWORKS_DIR_YES = iosmac;
 WK_PLATFORM_NAME_USE_ALTERNATE_FRAMEWORKS_DIR_NO = $(PLATFORM_NAME);
+
+LLVM_LTO = $(WK_LLVM_LTO_$(WK_XCODE_SUPPORTS_LTO));
+WK_LLVM_LTO_NO = NO;
+WK_LLVM_LTO_YES = $(WK_USER_LTO_MODE);
+
+WK_XCODE_SUPPORTS_LTO = $(WK_NOT_$(WK_XCODE_VERSION_BEFORE_9_$(XCODE_VERSION_MAJOR)));
+WK_XCODE_VERSION_BEFORE_9_0800 = YES;
+WK_XCODE_VERSION_BEFORE_9_0700 = YES;
+
+WK_USER_LTO_MODE = $(WK_USER_LTO_MODE_$(WK_LTO_MODE));
+WK_USER_LTO_MODE_full = YES;
+WK_USER_LTO_MODE_thin = YES_THIN;
+WK_USER_LTO_MODE_none = NO;
+WK_USER_LTO_MODE_ = $(WK_DEFAULT_LTO_MODE);
+WK_DEFAULT_LTO_MODE = $(WK_USER_LTO_MODE_full);
index f0ff2cc..de0ab3a 100644 (file)
@@ -1,4 +1,5 @@
 #include "Base.xcconfig"
+#include? "../../../../LocalOverrides.xcconfig"
 
 ARCHS = $(ARCHS_STANDARD_32_64_BIT);
 
@@ -19,5 +20,7 @@ SDKROOT = $(SDKROOT_$(USE_INTERNAL_SDK));
 SDKROOT_ = macosx;
 SDKROOT_YES = macosx.internal;
 
+WK_DEFAULT_LTO_MODE = $(WK_USER_LTO_MODE_none);
+
 WK_CCACHE_DIR = $(SRCROOT)/../../../Tools/ccache;
 #include "../../../../Tools/ccache/ccache.xcconfig"
index eb4f21b..69c674c 100644 (file)
@@ -1,3 +1,17 @@
+2018-08-27  Keith Rollin  <krollin@apple.com>
+
+        Build system support for LTO
+        https://bugs.webkit.org/show_bug.cgi?id=187785
+        <rdar://problem/42353132>
+
+        Reviewed by Dan Bernstein.
+
+        Update Base.xcconfig and DebugRelease.xcconfig to optionally enable
+        LTO.
+
+        * Configurations/Base.xcconfig:
+        * Configurations/DebugRelease.xcconfig:
+
 2018-08-23  youenn fablet  <youennf@gmail.com>
 
         Remove libwebrtc unneeded .exe file.
index 8796a86..513d82e 100644 (file)
@@ -103,3 +103,18 @@ WK_USE_OVERRIDE_FRAMEWORKS_DIR = $(WK_NOT_$(WK_EMPTY_$(WK_OVERRIDE_FRAMEWORKS_DI
 
 WK_OVERRIDE_FRAMEWORKS_DIR = $(WK_OVERRIDE_FRAMEWORKS_DIR_USE_STAGING_INSTALL_PATH_$(USE_STAGING_INSTALL_PATH));
 WK_OVERRIDE_FRAMEWORKS_DIR_USE_STAGING_INSTALL_PATH_YES = $(SYSTEM_LIBRARY_DIR)/StagedFrameworks/Safari;
+
+LLVM_LTO = $(WK_LLVM_LTO_$(WK_XCODE_SUPPORTS_LTO));
+WK_LLVM_LTO_NO = NO;
+WK_LLVM_LTO_YES = $(WK_USER_LTO_MODE);
+
+WK_XCODE_SUPPORTS_LTO = $(WK_NOT_$(WK_XCODE_VERSION_BEFORE_9_$(XCODE_VERSION_MAJOR)));
+WK_XCODE_VERSION_BEFORE_9_0800 = YES;
+WK_XCODE_VERSION_BEFORE_9_0700 = YES;
+
+WK_USER_LTO_MODE = $(WK_USER_LTO_MODE_$(WK_LTO_MODE));
+WK_USER_LTO_MODE_full = YES;
+WK_USER_LTO_MODE_thin = YES_THIN;
+WK_USER_LTO_MODE_none = NO;
+WK_USER_LTO_MODE_ = $(WK_DEFAULT_LTO_MODE);
+WK_DEFAULT_LTO_MODE = $(WK_USER_LTO_MODE_full);
index 5df1074..143f4a8 100644 (file)
@@ -1,4 +1,5 @@
 #include "Base.xcconfig"
+#include? "../../../../LocalOverrides.xcconfig"
 
 ARCHS = $(ARCHS_STANDARD_32_64_BIT);
 
@@ -21,5 +22,7 @@ SDKROOT_YES = macosx.internal;
 
 WK_RELOCATABLE_FRAMEWORKS = YES;
 
+WK_DEFAULT_LTO_MODE = $(WK_USER_LTO_MODE_none);
+
 WK_CCACHE_DIR = $(SRCROOT)/../../../Tools/ccache;
 #include "../../../../Tools/ccache/ccache.xcconfig"
index c2f1efa..292c640 100644 (file)
@@ -1,3 +1,17 @@
+2018-08-27  Keith Rollin  <krollin@apple.com>
+
+        Build system support for LTO
+        https://bugs.webkit.org/show_bug.cgi?id=187785
+        <rdar://problem/42353132>
+
+        Reviewed by Dan Bernstein.
+
+        Update Base.xcconfig and DebugRelease.xcconfig to optionally enable
+        LTO.
+
+        * Configurations/Base.xcconfig:
+        * Configurations/DebugRelease.xcconfig:
+
 2018-08-25  Yusuke Suzuki  <yusukesuzuki@slowstart.org>
 
         Shrink size of XMLHttpRequest
index c7bef5b..123576a 100644 (file)
@@ -145,3 +145,18 @@ WTF_INSTALL_PATH_PREFIX_DEPLOYMENT_YES_USE_ALTERNATE_YES = $(WK_ALTERNATE_FRAMEW
 WK_PLATFORM_NAME = $(WK_PLATFORM_NAME_USE_ALTERNATE_FRAMEWORKS_DIR_$(WK_USE_ALTERNATE_FRAMEWORKS_DIR));
 WK_PLATFORM_NAME_USE_ALTERNATE_FRAMEWORKS_DIR_YES = iosmac;
 WK_PLATFORM_NAME_USE_ALTERNATE_FRAMEWORKS_DIR_NO = $(PLATFORM_NAME);
+
+LLVM_LTO = $(WK_LLVM_LTO_$(WK_XCODE_SUPPORTS_LTO));
+WK_LLVM_LTO_NO = NO;
+WK_LLVM_LTO_YES = $(WK_USER_LTO_MODE);
+
+WK_XCODE_SUPPORTS_LTO = $(WK_NOT_$(WK_XCODE_VERSION_BEFORE_9_$(XCODE_VERSION_MAJOR)));
+WK_XCODE_VERSION_BEFORE_9_0800 = YES;
+WK_XCODE_VERSION_BEFORE_9_0700 = YES;
+
+WK_USER_LTO_MODE = $(WK_USER_LTO_MODE_$(WK_LTO_MODE));
+WK_USER_LTO_MODE_full = YES;
+WK_USER_LTO_MODE_thin = YES_THIN;
+WK_USER_LTO_MODE_none = NO;
+WK_USER_LTO_MODE_ = $(WK_DEFAULT_LTO_MODE);
+WK_DEFAULT_LTO_MODE = $(WK_USER_LTO_MODE_full);
index e41c019..490dbe9 100644 (file)
@@ -22,6 +22,7 @@
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 
 #include "Base.xcconfig"
+#include? "../../../LocalOverrides.xcconfig"
 
 ARCHS = $(ARCHS_STANDARD_32_64_BIT);
 ONLY_ACTIVE_ARCH = YES;
@@ -41,5 +42,7 @@ SDKROOT = $(SDKROOT_$(USE_INTERNAL_SDK));
 SDKROOT_ = macosx;
 SDKROOT_YES = macosx.internal;
 
+WK_DEFAULT_LTO_MODE = $(WK_USER_LTO_MODE_none);
+
 WK_CCACHE_DIR = $(SRCROOT)/../../Tools/ccache;
 #include "../../../Tools/ccache/ccache.xcconfig"
index f474f97..a0b9a02 100644 (file)
@@ -1,3 +1,19 @@
+2018-08-27  Keith Rollin  <krollin@apple.com>
+
+        Build system support for LTO
+        https://bugs.webkit.org/show_bug.cgi?id=187785
+        <rdar://problem/42353132>
+
+        Reviewed by Dan Bernstein.
+
+        Update Base.xcconfig and DebugRelease.xcconfig to optionally enable
+        LTO.
+
+        No new tests -- no new WebKit functionality.
+
+        * Configurations/Base.xcconfig:
+        * Configurations/DebugRelease.xcconfig:
+
 2018-08-27  Daniel Bates  <dabates@apple.com>
 
         [iOS] Make color of spelling dots match UIKit
index 93ae84b..1a0bbbc 100644 (file)
@@ -145,3 +145,26 @@ WK_COCOA_TOUCH_watchsimulator = cocoatouch;
 WK_COCOA_TOUCH_appletvos = cocoatouch;
 WK_COCOA_TOUCH_appletvsimulator = cocoatouch;
 WK_IS_COCOA_TOUCH = $(WK_NOT_$(WK_EMPTY_$(WK_COCOA_TOUCH)));
+
+// Attempting to build WebCore with full LTO for i386 results in the following
+// linker error, so we drop down to "thin" for that architecture if we were to
+// otherwise attempt to use "full".
+//
+// LLVM ERROR: Section too large, can't encode r_address (0x1000216) into 24 bits of scattered relocation entry.
+// clang: error: linker command failed with exit code 1 (use -v to see invocation)
+
+LLVM_LTO = $(WK_LLVM_LTO_$(WK_XCODE_SUPPORTS_LTO));
+WK_LLVM_LTO_NO = NO;
+WK_LLVM_LTO_YES = $(WK_USER_LTO_MODE);
+
+WK_XCODE_SUPPORTS_LTO = $(WK_NOT_$(WK_XCODE_VERSION_BEFORE_9_$(XCODE_VERSION_MAJOR)));
+WK_XCODE_VERSION_BEFORE_9_0800 = YES;
+WK_XCODE_VERSION_BEFORE_9_0700 = YES;
+
+WK_USER_LTO_MODE = $(WK_USER_LTO_MODE_$(WK_LTO_MODE));
+WK_USER_LTO_MODE_full[arch=i386] = $(WK_USER_LTO_MODE_thin);
+WK_USER_LTO_MODE_full = YES;
+WK_USER_LTO_MODE_thin = YES_THIN;
+WK_USER_LTO_MODE_none = NO;
+WK_USER_LTO_MODE_ = $(WK_DEFAULT_LTO_MODE);
+WK_DEFAULT_LTO_MODE = $(WK_USER_LTO_MODE_full);
index 8f1c773..5f26ed0 100644 (file)
@@ -22,6 +22,7 @@
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 #include "Base.xcconfig"
+#include? "../../../LocalOverrides.xcconfig"
 
 ARCHS = $(ARCHS_STANDARD_32_64_BIT);
 
@@ -44,5 +45,7 @@ SDKROOT_YES = macosx.internal;
 
 WK_RELOCATABLE_FRAMEWORKS = YES;
 
+WK_DEFAULT_LTO_MODE = $(WK_USER_LTO_MODE_none);
+
 WK_CCACHE_DIR = $(SRCROOT)/../../Tools/ccache;
 #include "../../../Tools/ccache/ccache.xcconfig"
index a9c4bbc..5ec5e21 100644 (file)
@@ -1,3 +1,17 @@
+2018-08-27  Keith Rollin  <krollin@apple.com>
+
+        Build system support for LTO
+        https://bugs.webkit.org/show_bug.cgi?id=187785
+        <rdar://problem/42353132>
+
+        Reviewed by Dan Bernstein.
+
+        Update Base.xcconfig and DebugRelease.xcconfig to optionally enable
+        LTO.
+
+        * Configurations/Base.xcconfig:
+        * Configurations/DebugRelease.xcconfig:
+
 2018-08-26  Andy Estes  <aestes@apple.com>
 
         [Apple Pay] Introduce new values for -apple-pay-button-type
index d921b6e..6720942 100644 (file)
@@ -142,3 +142,26 @@ WK_COCOA_TOUCH_watchsimulator = cocoatouch;
 WK_COCOA_TOUCH_appletvos = cocoatouch;
 WK_COCOA_TOUCH_appletvsimulator = cocoatouch;
 WK_IS_COCOA_TOUCH = $(WK_NOT_$(WK_EMPTY_$(WK_COCOA_TOUCH)));
+
+// Attempting to build WebCore with full LTO for i386 results in the following
+// linker error, so we drop down to "thin" for that architecture if we were to
+// otherwise attempt to use "full".
+//
+// LLVM ERROR: Section too large, can't encode r_address (0x1000216) into 24 bits of scattered relocation entry.
+// clang: error: linker command failed with exit code 1 (use -v to see invocation)
+
+LLVM_LTO = $(WK_LLVM_LTO_$(WK_XCODE_SUPPORTS_LTO));
+WK_LLVM_LTO_NO = NO;
+WK_LLVM_LTO_YES = $(WK_USER_LTO_MODE);
+
+WK_XCODE_SUPPORTS_LTO = $(WK_NOT_$(WK_XCODE_VERSION_BEFORE_9_$(XCODE_VERSION_MAJOR)));
+WK_XCODE_VERSION_BEFORE_9_0800 = YES;
+WK_XCODE_VERSION_BEFORE_9_0700 = YES;
+
+WK_USER_LTO_MODE = $(WK_USER_LTO_MODE_$(WK_LTO_MODE));
+WK_USER_LTO_MODE_full[arch=i386] = $(WK_USER_LTO_MODE_thin);
+WK_USER_LTO_MODE_full = YES;
+WK_USER_LTO_MODE_thin = YES_THIN;
+WK_USER_LTO_MODE_none = NO;
+WK_USER_LTO_MODE_ = $(WK_DEFAULT_LTO_MODE);
+WK_DEFAULT_LTO_MODE = $(WK_USER_LTO_MODE_full);
index 6067c6f..5c4e699 100644 (file)
@@ -22,6 +22,7 @@
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 #include "Base.xcconfig"
+#include? "../../../../LocalOverrides.xcconfig"
 
 ARCHS = $(ARCHS_STANDARD_32_64_BIT);
 
@@ -44,5 +45,7 @@ SDKROOT_YES = macosx.internal;
 
 WK_RELOCATABLE_FRAMEWORKS = YES;
 
+WK_DEFAULT_LTO_MODE = $(WK_USER_LTO_MODE_none);
+
 WK_CCACHE_DIR = $(SRCROOT)/../../../Tools/ccache;
 #include "../../../../Tools/ccache/ccache.xcconfig"
index 237a6cc..02de4fb 100644 (file)
@@ -1,3 +1,17 @@
+2018-08-27  Keith Rollin  <krollin@apple.com>
+
+        Build system support for LTO
+        https://bugs.webkit.org/show_bug.cgi?id=187785
+        <rdar://problem/42353132>
+
+        Reviewed by Dan Bernstein.
+
+        Update Base.xcconfig and DebugRelease.xcconfig to optionally enable
+        LTO.
+
+        * Configurations/Base.xcconfig:
+        * Configurations/DebugRelease.xcconfig:
+
 2018-08-27  Devin Rousso  <drousso@apple.com>
 
         Web Inspector: REGRESSION: virtualized TreeOutline is empty when filtering
index dc643f2..8dfd75c 100644 (file)
@@ -106,3 +106,18 @@ WK_COCOA_TOUCH_watchsimulator = cocoatouch;
 WK_COCOA_TOUCH_appletvos = cocoatouch;
 WK_COCOA_TOUCH_appletvsimulator = cocoatouch;
 WK_IS_COCOA_TOUCH = $(WK_NOT_$(WK_EMPTY_$(WK_COCOA_TOUCH)));
+
+LLVM_LTO = $(WK_LLVM_LTO_$(WK_XCODE_SUPPORTS_LTO));
+WK_LLVM_LTO_NO = NO;
+WK_LLVM_LTO_YES = $(WK_USER_LTO_MODE);
+
+WK_XCODE_SUPPORTS_LTO = $(WK_NOT_$(WK_XCODE_VERSION_BEFORE_9_$(XCODE_VERSION_MAJOR)));
+WK_XCODE_VERSION_BEFORE_9_0800 = YES;
+WK_XCODE_VERSION_BEFORE_9_0700 = YES;
+
+WK_USER_LTO_MODE = $(WK_USER_LTO_MODE_$(WK_LTO_MODE));
+WK_USER_LTO_MODE_full = YES;
+WK_USER_LTO_MODE_thin = YES_THIN;
+WK_USER_LTO_MODE_none = NO;
+WK_USER_LTO_MODE_ = $(WK_DEFAULT_LTO_MODE);
+WK_DEFAULT_LTO_MODE = $(WK_USER_LTO_MODE_full);
index a702183..0f6f444 100644 (file)
@@ -1,4 +1,5 @@
 #include "Base.xcconfig"
+#include? "../../../LocalOverrides.xcconfig"
 
 ARCHS = $(ARCHS_STANDARD_32_64_BIT);
 
@@ -23,3 +24,5 @@ SDKROOT_YES = macosx.internal;
 
 COMBINE_INSPECTOR_RESOURCES = NO;
 COMBINE_TEST_RESOURCES = YES;
+
+WK_DEFAULT_LTO_MODE = $(WK_USER_LTO_MODE_none);
index 51faa89..4b69334 100644 (file)
@@ -1,3 +1,17 @@
+2018-08-27  Keith Rollin  <krollin@apple.com>
+
+        Build system support for LTO
+        https://bugs.webkit.org/show_bug.cgi?id=187785
+        <rdar://problem/42353132>
+
+        Reviewed by Dan Bernstein.
+
+        Update Base.xcconfig and DebugRelease.xcconfig to optionally enable
+        LTO.
+
+        * Configurations/Base.xcconfig:
+        * Configurations/DebugRelease.xcconfig:
+
 2018-08-27  Daniel Bates  <dabates@apple.com>
 
         Remove extern variable and simplify state initialization in TextCheckerMac.mm
index 600d2eb..1988d13 100644 (file)
@@ -159,3 +159,18 @@ WK_MACOS_WEAK_FRAMEWORK_cocoatouch = -framework
 WK_MACOS_WEAK_FRAMEWORK_ = -weak_framework
 
 WK_USE_RESTRICTED_ENTITLEMENTS = $(USE_INTERNAL_SDK);
+
+LLVM_LTO = $(WK_LLVM_LTO_$(WK_XCODE_SUPPORTS_LTO));
+WK_LLVM_LTO_NO = NO;
+WK_LLVM_LTO_YES = $(WK_USER_LTO_MODE);
+
+WK_XCODE_SUPPORTS_LTO = $(WK_NOT_$(WK_XCODE_VERSION_BEFORE_9_$(XCODE_VERSION_MAJOR)));
+WK_XCODE_VERSION_BEFORE_9_0800 = YES;
+WK_XCODE_VERSION_BEFORE_9_0700 = YES;
+
+WK_USER_LTO_MODE = $(WK_USER_LTO_MODE_$(WK_LTO_MODE));
+WK_USER_LTO_MODE_full = YES;
+WK_USER_LTO_MODE_thin = YES_THIN;
+WK_USER_LTO_MODE_none = NO;
+WK_USER_LTO_MODE_ = $(WK_DEFAULT_LTO_MODE);
+WK_DEFAULT_LTO_MODE = $(WK_USER_LTO_MODE_full);
index 83744a0..2e74391 100644 (file)
@@ -22,6 +22,7 @@
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 
 #include "Base.xcconfig"
+#include? "../../../LocalOverrides.xcconfig"
 
 ARCHS = $(ARCHS_STANDARD_32_64_BIT);
 
@@ -55,5 +56,7 @@ WK_LIBRARY_VALIDATION_ENABLED = NO;
 WK_WEBCONTENT_SERVICE_NEEDS_XPC_DOMAIN_EXTENSION_ENTITLEMENT = NO;
 WK_WEBCONTENT_SERVICE_NEEDS_VERSIONED_FRAMEWORK_PATH_LDFLAG[sdk=macosx*] = YES;
 
+WK_DEFAULT_LTO_MODE = $(WK_USER_LTO_MODE_none);
+
 WK_CCACHE_DIR = $(SRCROOT)/../../Tools/ccache;
 #include "../../../Tools/ccache/ccache.xcconfig"
index b28f3b4..b89a4af 100644 (file)
@@ -1,3 +1,17 @@
+2018-08-27  Keith Rollin  <krollin@apple.com>
+
+        Build system support for LTO
+        https://bugs.webkit.org/show_bug.cgi?id=187785
+        <rdar://problem/42353132>
+
+        Reviewed by Dan Bernstein.
+
+        Update Base.xcconfig and DebugRelease.xcconfig to optionally enable
+        LTO.
+
+        * Configurations/Base.xcconfig:
+        * Configurations/DebugRelease.xcconfig:
+
 2018-08-24  Ryosuke Niwa  <rniwa@webkit.org>
 
         Pass in IsComposed flag to Event constructors
index 4ffb03b..609b65c 100644 (file)
@@ -143,3 +143,18 @@ WK_COCOA_TOUCH_watchsimulator = cocoatouch;
 WK_COCOA_TOUCH_appletvos = cocoatouch;
 WK_COCOA_TOUCH_appletvsimulator = cocoatouch;
 WK_IS_COCOA_TOUCH = $(WK_NOT_$(WK_EMPTY_$(WK_COCOA_TOUCH)));
+
+LLVM_LTO = $(WK_LLVM_LTO_$(WK_XCODE_SUPPORTS_LTO));
+WK_LLVM_LTO_NO = NO;
+WK_LLVM_LTO_YES = $(WK_USER_LTO_MODE);
+
+WK_XCODE_SUPPORTS_LTO = $(WK_NOT_$(WK_XCODE_VERSION_BEFORE_9_$(XCODE_VERSION_MAJOR)));
+WK_XCODE_VERSION_BEFORE_9_0800 = YES;
+WK_XCODE_VERSION_BEFORE_9_0700 = YES;
+
+WK_USER_LTO_MODE = $(WK_USER_LTO_MODE_$(WK_LTO_MODE));
+WK_USER_LTO_MODE_full = YES;
+WK_USER_LTO_MODE_thin = YES_THIN;
+WK_USER_LTO_MODE_none = NO;
+WK_USER_LTO_MODE_ = $(WK_DEFAULT_LTO_MODE);
+WK_DEFAULT_LTO_MODE = $(WK_USER_LTO_MODE_full);
index 6e0c723..9ee72b3 100644 (file)
@@ -22,6 +22,7 @@
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 
 #include "Base.xcconfig"
+#include? "../../../../LocalOverrides.xcconfig"
 
 ARCHS = $(ARCHS_STANDARD_32_64_BIT);
 
@@ -44,5 +45,7 @@ SDKROOT_YES = macosx.internal;
 
 WK_RELOCATABLE_FRAMEWORKS = YES;
 
+WK_DEFAULT_LTO_MODE = $(WK_USER_LTO_MODE_none);
+
 WK_CCACHE_DIR = $(SRCROOT)/../../Tools/ccache;
 #include "../../../../Tools/ccache/ccache.xcconfig"
index 8c606ac..82ff5fd 100644 (file)
@@ -1,3 +1,17 @@
+2018-08-27  Keith Rollin  <krollin@apple.com>
+
+        Build system support for LTO
+        https://bugs.webkit.org/show_bug.cgi?id=187785
+        <rdar://problem/42353132>
+
+        Reviewed by Dan Bernstein.
+
+        Update Base.xcconfig and DebugRelease.xcconfig to optionally enable
+        LTO.
+
+        * Configurations/Base.xcconfig:
+        * Configurations/DebugRelease.xcconfig:
+
 2018-08-16  Tomas Popela  <tpopela@redhat.com>
 
         bmalloc: Coverity scan issues
index 9dfa3c0..858cc6b 100644 (file)
@@ -137,3 +137,18 @@ BMALLOC_INSTALL_PATH_PREFIX_DEPLOYMENT_YES_USE_ALTERNATE_YES = $(WK_ALTERNATE_FR
 WK_PLATFORM_NAME = $(WK_PLATFORM_NAME_USE_ALTERNATE_FRAMEWORKS_DIR_$(WK_USE_ALTERNATE_FRAMEWORKS_DIR));
 WK_PLATFORM_NAME_USE_ALTERNATE_FRAMEWORKS_DIR_YES = iosmac;
 WK_PLATFORM_NAME_USE_ALTERNATE_FRAMEWORKS_DIR_NO = $(PLATFORM_NAME);
+
+LLVM_LTO = $(WK_LLVM_LTO_$(WK_XCODE_SUPPORTS_LTO));
+WK_LLVM_LTO_NO = NO;
+WK_LLVM_LTO_YES = $(WK_USER_LTO_MODE);
+
+WK_XCODE_SUPPORTS_LTO = $(WK_NOT_$(WK_XCODE_VERSION_BEFORE_9_$(XCODE_VERSION_MAJOR)));
+WK_XCODE_VERSION_BEFORE_9_0800 = YES;
+WK_XCODE_VERSION_BEFORE_9_0700 = YES;
+
+WK_USER_LTO_MODE = $(WK_USER_LTO_MODE_$(WK_LTO_MODE));
+WK_USER_LTO_MODE_full = YES;
+WK_USER_LTO_MODE_thin = YES_THIN;
+WK_USER_LTO_MODE_none = NO;
+WK_USER_LTO_MODE_ = $(WK_DEFAULT_LTO_MODE);
+WK_DEFAULT_LTO_MODE = $(WK_USER_LTO_MODE_full);
index e41c019..490dbe9 100644 (file)
@@ -22,6 +22,7 @@
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 
 #include "Base.xcconfig"
+#include? "../../../LocalOverrides.xcconfig"
 
 ARCHS = $(ARCHS_STANDARD_32_64_BIT);
 ONLY_ACTIVE_ARCH = YES;
@@ -41,5 +42,7 @@ SDKROOT = $(SDKROOT_$(USE_INTERNAL_SDK));
 SDKROOT_ = macosx;
 SDKROOT_YES = macosx.internal;
 
+WK_DEFAULT_LTO_MODE = $(WK_USER_LTO_MODE_none);
+
 WK_CCACHE_DIR = $(SRCROOT)/../../Tools/ccache;
 #include "../../../Tools/ccache/ccache.xcconfig"
index bde6783..ebc5ac0 100644 (file)
@@ -1,3 +1,22 @@
+2018-08-27  Keith Rollin  <krollin@apple.com>
+
+        Build system support for LTO
+        https://bugs.webkit.org/show_bug.cgi?id=187785
+        <rdar://problem/42353132>
+
+        Reviewed by Dan Bernstein.
+
+        Add tools/scripts support for controlling LTO builds.
+
+        * Scripts/build-webkit: Add --lto-mode={none,thin,full}.
+        * Scripts/set-webkit-configuration: Add support for saving LTO
+        configuration to WebKitBuild/LTO.
+        * Scripts/webkitdirs.pm: Add support for reading configuration from
+        WebKitBuild/LTO and providing it to xcodebuild.
+        (determineLTOMode):
+        (ltoMode):
+        (XcodeOptions):
+
 2018-08-27  Daniel Bates  <dabates@apple.com>
 
         lldb-webkit: Pretty-print OptionSet
index 23d2ec4..dcdbaa5 100755 (executable)
@@ -72,6 +72,7 @@ my $onlyWebKitProject = 0;
 my $coverageSupport = 0;
 my $shouldRunStaticAnalyzer = 0;
 my $noExperimentalFeatures = 0;
+my $ltoMode = "default";
 my $startTime = time();
 my $archs32bit = 0;
 my $skipLibraryUpdate = 0;
@@ -113,6 +114,7 @@ Usage: $programName [options] [options to pass to build system]
   --simulator                       DEPRECATED alias of --ios-simulator
   --coverage                        Enable code coverage support (Mac only)
   --analyze                         Enable static anaylsis (iOS and Mac only)
+  --lto-mode=<mode>                 Set Link Time Optimization mode (full, thin, or none) (Xcode only)
 
   --gtk                             Build the GTK+ port
   --wpe                             Build the WPE port
@@ -149,6 +151,7 @@ my %options = (
     'coverage' => \$coverageSupport,
     'analyze' => \$shouldRunStaticAnalyzer,
     'no-experimental-features' => \$noExperimentalFeatures,
+    'lto-mode=s' => \$ltoMode,
     'skip-library-update' => \$skipLibraryUpdate,
     'use-ccache!' => \$useCCache,
 );
@@ -331,6 +334,7 @@ if (isAppleWinWebKit() || isWinCairo()) {
         my @local_options = @options;
         push @local_options, XcodeCoverageSupportOptions() if $coverageSupport;
         push @local_options, XcodeStaticAnalyzerOption() if $shouldRunStaticAnalyzer;
+        push @local_options, "WK_LTO_MODE=$ltoMode" if ($ltoMode ne "default");
         my $projectPath = $project =~ /gtest/ ? "xcode/gtest" : $project;
         $result = buildXCodeProject($projectPath, $clean, @local_options, @ARGV);
 
index c484fb8..eab7130 100755 (executable)
@@ -38,6 +38,7 @@ Usage: $programName [options]
   --32-bit                Set the default architecture to 32-bit
   --64-bit                Set the default architecture to 64-bit
   --[no-]asan             Enable or disable clang address sanitizer
+  --lto-mode=<mode>       Set LTO mode: full, thin, or none
   --debug                 Set the default configuration to debug
   --release               Set the default configuration to release
   --reset                 Reset configurations
@@ -47,6 +48,10 @@ my $configuration = passedConfiguration();
 my $architecture = passedArchitecture();
 my $enableASAN = checkForArgumentAndRemoveFromARGV("--asan");
 my $disableASAN = checkForArgumentAndRemoveFromARGV("--no-asan");
+my $ltoMode;
+if (!checkForArgumentAndRemoveFromARGVGettingValue("--lto-mode", \$ltoMode)) {
+    $ltoMode="";
+}
 
 if (!$architecture) {
     # Handle --64-bit explicitly here, as we don't want our other scripts to accept it
@@ -66,10 +71,16 @@ if (checkForArgumentAndRemoveFromARGV("--reset")) {
     unlink "$baseProductDir/Configuration";
     unlink "$baseProductDir/Architecture";
     unlink "$baseProductDir/ASan";
+    unlink "$baseProductDir/LTO";
     exit 0;
 }
 
-if (!$configuration && !$architecture && !$enableASAN && !$disableASAN || ($enableASAN && $disableASAN)) {
+if ((!$configuration && !$architecture && !$enableASAN && !$disableASAN && !$ltoMode) || ($enableASAN && $disableASAN)) {
+    print STDERR $usage;
+    exit 1;
+}
+
+if ($ltoMode && $ltoMode ne "full" && $ltoMode ne "thin" && $ltoMode ne "none") {
     print STDERR $usage;
     exit 1;
 }
@@ -97,3 +108,9 @@ if ($enableASAN) {
 } elsif ($disableASAN) {
     unlink "$baseProductDir/ASan";
 }
+
+if ($ltoMode) {
+    open LTO, ">", "$baseProductDir/LTO" or die;
+    print LTO "$ltoMode";
+    close LTO;
+}
index 2f39c7c..6d70f8e 100755 (executable)
@@ -129,6 +129,7 @@ our @EXPORT_OK;
 
 my $architecture;
 my $asanIsEnabled;
+my $ltoMode;
 my $numberOfCPUs;
 my $maxCPULoad;
 my $baseProductDir;
@@ -422,6 +423,18 @@ sub determineASanIsEnabled
     }
 }
 
+sub determineLTOMode
+{
+    return if defined $ltoMode;
+    determineBaseProductDir();
+
+    if (open LTO, "$baseProductDir/LTO") {
+        $ltoMode = <LTO>;
+        close LTO;
+        chomp $ltoMode;
+    }
+}
+
 sub determineNumberOfCPUs
 {
     return if defined $numberOfCPUs;
@@ -844,6 +857,12 @@ sub asanIsEnabled()
     return $asanIsEnabled;
 }
 
+sub ltoMode()
+{
+    determineLTOMode();
+    return $ltoMode;
+}
+
 sub configurationForVisualStudio()
 {
     determineConfigurationForVisualStudio();
@@ -886,6 +905,7 @@ sub XcodeOptions
     determineConfiguration();
     determineArchitecture();
     determineASanIsEnabled();
+    determineLTOMode();
     determineXcodeSDK();
 
     my @options;
@@ -893,6 +913,7 @@ sub XcodeOptions
     push @options, "-UseSanitizedBuildSystemEnvironment=YES";
     push @options, ("-configuration", $configuration);
     push @options, ("-xcconfig", sourceDir() . "/Tools/asan/asan.xcconfig", "ASAN_IGNORE=" . sourceDir() . "/Tools/asan/webkit-asan-ignore.txt") if $asanIsEnabled;
+    push @options, "WK_LTO_MODE=$ltoMode" if $ltoMode;
     push @options, @baseProductDirOption;
     push @options, "ARCHS=$architecture" if $architecture;
     push @options, "SDKROOT=$xcodeSDK" if $xcodeSDK;