Bug 1351109 - Move the gold linker support to the python configure r=glandium

MozReview-Commit-ID: 1FC0W7EqdCI

--HG--
extra : rebase_source : 6df832649a6130869b106cf8c79164b85d1f1ca6
This commit is contained in:
Sylvestre Ledru 2017-07-05 11:27:56 +02:00
Родитель b1c83de1b7
Коммит b4dc56b423
3 изменённых файлов: 76 добавлений и 43 удалений

Просмотреть файл

@ -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"

Просмотреть файл

@ -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',

Просмотреть файл

@ -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)