From b4dc56b4231ca428ab48e9ade33320362f9eed5c Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Wed, 5 Jul 2017 11:27:56 +0200 Subject: [PATCH] Bug 1351109 - Move the gold linker support to the python configure r=glandium MozReview-Commit-ID: 1FC0W7EqdCI --HG-- extra : rebase_source : 6df832649a6130869b106cf8c79164b85d1f1ca6 --- build/autoconf/compiler-opts.m4 | 42 -------------- build/moz.configure/old.configure | 1 - build/moz.configure/toolchain.configure | 76 +++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 43 deletions(-) diff --git a/build/autoconf/compiler-opts.m4 b/build/autoconf/compiler-opts.m4 index e2cda1be6cc4..1b178a82b308 100644 --- a/build/autoconf/compiler-opts.m4 +++ b/build/autoconf/compiler-opts.m4 @@ -119,48 +119,6 @@ if test "$CLANG_CXX"; then _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" diff --git a/build/moz.configure/old.configure b/build/moz.configure/old.configure index 188b1553761b..a7dca49cf6f8 100644 --- a/build/moz.configure/old.configure +++ b/build/moz.configure/old.configure @@ -181,7 +181,6 @@ def old_configure_options(*options): '--enable-gamepad', '--enable-gconf', '--enable-gczeal', - '--enable-gold', '--enable-hardware-aec-ns', '--enable-icf', '--enable-install-strip', diff --git a/build/moz.configure/toolchain.configure b/build/moz.configure/toolchain.configure index c010bc7572bc..fc08ea4b3b8f 100644 --- a/build/moz.configure/toolchain.configure +++ b/build/moz.configure/toolchain.configure @@ -1080,3 +1080,79 @@ def developer_options(value): return True add_old_configure_assignment('DEVELOPER_OPTIONS', developer_options) + +# Linker detection +# ============================================================== + +@depends(target) +def build_not_win_mac(target): + if target.kernel not in ('Darwin', 'WINNT'): + return True + + +option('--enable-gold', + env='MOZ_FORCE_GOLD', + help='Enable GNU Gold Linker when it is not already the default', + when=build_not_win_mac) + + +@depends('--enable-gold', c_compiler, developer_options, check_build_environment, when=build_not_win_mac) +@checking('for ld', lambda x: x.KIND) +@imports('os') +@imports('shutil') +def enable_gold(enable_gold_option, c_compiler, developer_options, build_env): + linker = None + # Used to check the kind of linker + version_check = ['-Wl,--version'] + cmd_base = c_compiler.wrapper + [c_compiler.compiler] + c_compiler.flags + if enable_gold_option or developer_options: + # Try to force the usage of gold + targetDir = os.path.join(build_env.topobjdir, 'build', 'unix', 'gold') + + gold_detection_arg = '-print-prog-name=ld.gold' + gold = check_cmd_output(c_compiler.compiler, gold_detection_arg).strip() + if not gold: + die('Could not find gold') + + goldFullPath = find_program(gold) + if goldFullPath is None: + die('Could not find gold') + + if os.path.exists(targetDir): + shutil.rmtree(targetDir) + os.makedirs(targetDir) + os.symlink(goldFullPath, os.path.join(targetDir, 'ld')) + + linker = ['-B', targetDir] + cmd = cmd_base + linker + version_check + if 'GNU gold' in check_cmd_output(*cmd).decode('utf-8'): + # We have detected gold, will build with the -B workaround + return namespace( + KIND='gold', + LINKER_FLAG=linker, + ) + else: + # The -B trick didn't work, removing the directory + shutil.rmtree(targetDir) + + cmd = cmd_base + version_check + cmd_output = check_cmd_output(*cmd).decode('utf-8') + # using decode because ld can be localized and python will + # have problems with french accent for example + if 'GNU ld' in cmd_output: + # We are using the normal linker + return namespace( + KIND='bfd' + ) + + # Special case for Android. In the ndk, it is gold + if 'GNU gold' in cmd_output: + return namespace( + KIND='gold' + ) + + die("Could not find any linker") + + +set_config('LD_IS_BFD', depends(enable_gold.KIND)(lambda x: x == 'bfd' or None)) +set_config('LINKER_LDFLAGS', enable_gold.LINKER_FLAG)