mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 00:05:36 +00:00
Bug 1455767 - As we have gcc 6 as requirement, use -fuse-ld everywhere instead of the -B trick r=glandium
+ simplify the code MozReview-Commit-ID: 1Qz5H8VkfpD --HG-- extra : rebase_source : cf7ef2945a112c592ae02d68c3825205497e079a
This commit is contained in:
parent
91cda569e3
commit
0584c2911d
@ -1500,59 +1500,43 @@ option('--enable-gold',
|
||||
|
||||
imply_option('--enable-linker', 'gold', when='--enable-gold')
|
||||
|
||||
js_option('--enable-linker', nargs=1,
|
||||
choices=('bfd', 'gold', 'lld', 'other'),
|
||||
help='Select the linker',
|
||||
when=is_linker_option_enabled)
|
||||
|
||||
|
||||
@depends('--enable-linker', c_compiler, developer_options,
|
||||
extra_toolchain_flags, when=is_linker_option_enabled)
|
||||
@checking('for linker', lambda x: x.KIND)
|
||||
@imports('os')
|
||||
@imports('shutil')
|
||||
def enable_gnu_linker(enable_gold_option, c_compiler, developer_options, build_env,
|
||||
toolchain_flags, linker_name):
|
||||
# Used to check the kind of linker
|
||||
def select_linker(linker, c_compiler, developer_options, toolchain_flags):
|
||||
|
||||
linker = linker[0] if linker else 'other'
|
||||
|
||||
# Check the kind of linker
|
||||
version_check = ['-Wl,--version']
|
||||
cmd_base = c_compiler.wrapper + [c_compiler.compiler] + c_compiler.flags
|
||||
# Generate the compiler flag
|
||||
linker_flag = ["-fuse-ld=" + linker] if linker != "other" else []
|
||||
cmd = cmd_base + linker_flag + version_check
|
||||
if toolchain_flags:
|
||||
cmd_base += toolchain_flags
|
||||
cmd += toolchain_flags
|
||||
|
||||
def resolve_gold():
|
||||
# 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'
|
||||
detection_cmd = cmd_base + [gold_detection_arg]
|
||||
gold = check_cmd_output(*detection_cmd).strip()
|
||||
if not gold:
|
||||
return
|
||||
|
||||
goldFullPath = find_program(gold)
|
||||
if goldFullPath is None:
|
||||
return
|
||||
|
||||
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 (linker == 'gold' or developer_options) and linker != 'bfd':
|
||||
if 'GNU gold' in check_cmd_output(*cmd).decode('utf-8'):
|
||||
# We have detected gold, will build with the -B workaround
|
||||
# We have detected gold, will build with -fuse-ld=gold
|
||||
return namespace(
|
||||
KIND='gold',
|
||||
LINKER_FLAG=linker,
|
||||
LINKER_FLAG=linker_flag,
|
||||
)
|
||||
else:
|
||||
# The -B trick didn't work, removing the directory
|
||||
shutil.rmtree(targetDir)
|
||||
|
||||
if (enable_gold_option or developer_options) and linker_name != 'bfd':
|
||||
result = resolve_gold()
|
||||
|
||||
if result:
|
||||
return result
|
||||
# gold is only required if --enable-gold is used.
|
||||
elif enable_gold_option:
|
||||
if linker == 'gold':
|
||||
die('Could not find gold')
|
||||
# Else fallthrough.
|
||||
|
||||
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
|
||||
@ -1568,41 +1552,22 @@ def enable_gnu_linker(enable_gold_option, c_compiler, developer_options, build_e
|
||||
KIND='gold'
|
||||
)
|
||||
|
||||
if 'LLD' in cmd_output:
|
||||
return namespace(
|
||||
KIND='lld',
|
||||
LINKER_FLAG=linker_flag,
|
||||
)
|
||||
elif linker == 'lld':
|
||||
# We forced the lld linker but could not find the string
|
||||
# when checking, fail the build
|
||||
die("Could not use lld as linker")
|
||||
|
||||
# For other platforms without gold or the GNU linker
|
||||
return namespace(
|
||||
KIND='other'
|
||||
)
|
||||
|
||||
|
||||
js_option('--enable-linker', nargs=1,
|
||||
choices=('bfd', 'gold', 'lld', 'other'),
|
||||
help='Select the linker',
|
||||
when=is_linker_option_enabled)
|
||||
|
||||
|
||||
@depends('--enable-linker', c_compiler, developer_options, check_build_environment,
|
||||
extra_toolchain_flags, when=is_linker_option_enabled)
|
||||
@checking('for linker', lambda x: x.KIND)
|
||||
def select_linker(linker, c_compiler, developer_options, build_env, toolchain_flags):
|
||||
linker = linker[0] if linker else 'other'
|
||||
if linker in ('gold', 'bfd', 'other'):
|
||||
return enable_gnu_linker(linker == 'gold', c_compiler, developer_options,
|
||||
build_env, toolchain_flags, linker)
|
||||
if linker == 'lld':
|
||||
version_check = ['-Wl,--version']
|
||||
cmd_base = c_compiler.wrapper + \
|
||||
[c_compiler.compiler] + c_compiler.flags
|
||||
lld = ["-fuse-ld=" + linker]
|
||||
cmd = cmd_base + lld + version_check
|
||||
if 'LLD' in check_cmd_output(*cmd).decode('utf-8'):
|
||||
return namespace(
|
||||
KIND='lld',
|
||||
LINKER_FLAG=lld,
|
||||
)
|
||||
else:
|
||||
die("Could not use lld as linker")
|
||||
|
||||
|
||||
set_config('LD_IS_BFD', depends(select_linker.KIND)
|
||||
(lambda x: x == 'bfd' or None))
|
||||
set_config('LINKER_LDFLAGS', select_linker.LINKER_FLAG)
|
||||
|
Loading…
Reference in New Issue
Block a user