Bug 1336978 - Add --enable-lld to link with lld instead of ld r?glandium draft
authorSylvestre Ledru <sledru@mozilla.com>
Wed, 22 Feb 2017 16:58:51 +0100
changeset 488111 30751b5023a423b6ba4e1ec8def6395f0d97a2c4
parent 487236 d84beb192e57e26846c82d3df3599381f4663792
child 546642 18b480fd5e7c285f77b16461095144fb72ebc68c
push id46427
push userbmo:sledru@mozilla.com
push dateWed, 22 Feb 2017 16:01:34 +0000
reviewersglandium
bugs1336978
milestone54.0a1
Bug 1336978 - Add --enable-lld to link with lld instead of ld r?glandium MozReview-Commit-ID: 9dpUi44NDdN
build/autoconf/compiler-opts.m4
build/moz.configure/old.configure
build/moz.configure/toolchain.configure
config/config.mk
--- a/build/autoconf/compiler-opts.m4
+++ b/build/autoconf/compiler-opts.m4
@@ -124,58 +124,16 @@ AC_DEFUN([MOZ_COMPILER_OPTS],
 if test "$CLANG_CXX"; then
     ## We disable return-type-c-linkage because jsval is defined as a C++ type but is
     ## returned by C functions. This is possible because we use knowledge about the ABI
     ## to typedef it to a C type with the same layout when the headers are included
     ## from C.
     _WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Wno-unknown-warning-option -Wno-return-type-c-linkage"
 fi
 
-if test -n "$DEVELOPER_OPTIONS"; then
-    MOZ_FORCE_GOLD=1
-fi
-
-MOZ_ARG_ENABLE_BOOL(gold,
-[  --enable-gold           Enable GNU Gold Linker when it is not already the default],
-    MOZ_FORCE_GOLD=1,
-    MOZ_FORCE_GOLD=
-    )
-
-if test "$GNU_CC" -a -n "$MOZ_FORCE_GOLD"; then
-    dnl if the default linker is BFD ld, check if gold is available and try to use it
-    dnl for local builds only.
-    if $CC -Wl,--version 2>&1 | grep -q "GNU ld"; then
-        GOLD=$($CC -print-prog-name=ld.gold)
-        case "$GOLD" in
-        /*)
-            ;;
-        *)
-            GOLD=$(which $GOLD)
-            ;;
-        esac
-        if test -n "$GOLD"; then
-            mkdir -p $_objdir/build/unix/gold
-            rm -f $_objdir/build/unix/gold/ld
-            ln -s "$GOLD" $_objdir/build/unix/gold/ld
-            if $CC -B $_objdir/build/unix/gold -Wl,--version 2>&1 | grep -q "GNU gold"; then
-                LDFLAGS="$LDFLAGS -B $_objdir/build/unix/gold"
-            else
-                rm -rf $_objdir/build/unix/gold
-            fi
-        fi
-    fi
-fi
-if test "$GNU_CC"; then
-    if $CC $LDFLAGS -Wl,--version 2>&1 | grep -q "GNU ld"; then
-        LD_IS_BFD=1
-    fi
-fi
-
-AC_SUBST([LD_IS_BFD])
-
 if test "$GNU_CC"; then
     if test -z "$DEVELOPER_OPTIONS"; then
         CFLAGS="$CFLAGS -ffunction-sections -fdata-sections"
         CXXFLAGS="$CXXFLAGS -ffunction-sections -fdata-sections"
     fi
     CFLAGS="$CFLAGS -fno-math-errno"
     CXXFLAGS="$CXXFLAGS -fno-exceptions -fno-math-errno"
 fi
--- a/build/moz.configure/old.configure
+++ b/build/moz.configure/old.configure
@@ -176,17 +176,16 @@ def old_configure_options(*options):
     '--enable-extensions',
     '--enable-faststripe',
     '--enable-feeds',
     '--enable-gamepad',
     '--enable-gconf',
     '--enable-gczeal',
     '--enable-gio',
     '--enable-gnomeui',
-    '--enable-gold',
     '--enable-hardware-aec-ns',
     '--enable-icf',
     '--enable-install-strip',
     '--enable-ion',
     '--enable-ios-target',
     '--enable-jitspew',
     '--enable-libjpeg-turbo',
     '--enable-libproxy',
--- a/build/moz.configure/toolchain.configure
+++ b/build/moz.configure/toolchain.configure
@@ -967,8 +967,40 @@ set_define('HAVE_VISIBILITY_ATTRIBUTE',
 set_config('WRAP_SYSTEM_INCLUDES', wrap_system_includes)
 set_config('VISIBILITY_FLAGS', visibility_flags)
 
 @depends(target)
 def is_windows(target):
     return target.kernel == 'WINNT'
 
 include('windows.configure', when=is_windows)
+
+
+
+# Linker
+# ==============================================================
+# Choice between LLD / LD
+js_option('--enable-linker', nargs=1,
+                 choices=('bft', 'ld', 'gold', 'lld'),
+                 help='Select the linker')
+
+@deprecated_option('--enable-gold')
+def select_linker(value):
+        return True
+
+@depends('--enable-linker', select_linker, c_compiler)
+def select_linker(value, gold, c_compiler):
+
+    if not gold:
+        linker = value[0]
+    else:
+        # Option --enable-gold has been used. Force gold
+        linker = 'gold'
+
+    if linker == 'ld' or linker == "bfd":
+        linker = "bfd"
+        set_define('LD_IS_BFD', 1)
+    elif linker == 'lld':
+        if c_compiler.type != 'clang':
+            die("lld requires clang (version >= 3.8)")
+    return "-fuse-ld=" + linker
+
+set_config('LINKER_LDFLAGS', select_linker)
--- a/config/config.mk
+++ b/config/config.mk
@@ -220,16 +220,20 @@ OS_CFLAGS += $(if $(filter $(notdir $<),
 OS_CXXFLAGS += $(if $(filter $(notdir $<),$(notdir $(NO_PROFILE_GUIDED_OPTIMIZE))),,$(PROFILE_USE_CFLAGS))
 OS_LDFLAGS += $(PROFILE_USE_LDFLAGS)
 ifeq (WINNT,$(OS_ARCH))
 AR_FLAGS += -LTCG
 endif
 endif # MOZ_PROFILE_USE
 endif # NO_PROFILE_GUIDED_OPTIMIZE
 
+# linker
+OS_LDFLAGS += $(LINKER_LDFLAGS)
+
+
 MAKE_JARS_FLAGS = \
 	-t $(topsrcdir) \
 	-f $(MOZ_JAR_MAKER_FILE_FORMAT) \
 	$(NULL)
 
 ifdef USE_EXTENSION_MANIFEST
 MAKE_JARS_FLAGS += -e
 endif