Skip to content

Commit b3884c5

Browse files
piscisaureusry
authored andcommitted
Autodetect no-strict-aliasing, propagate toolchain option to SCons
BUG=v8:884
1 parent 14475c7 commit b3884c5

File tree

2 files changed

+96
-28
lines changed

2 files changed

+96
-28
lines changed

deps/v8/SConstruct

+94-27
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import platform
2929
import re
30+
import subprocess
3031
import sys
3132
import os
3233
from os.path import join, dirname, abspath
@@ -142,6 +143,9 @@ LIBRARY_FLAGS = {
142143
# Use visibility=default to disable this.
143144
'CXXFLAGS': ['-fvisibility=hidden']
144145
},
146+
'strictaliasing:off': {
147+
'CCFLAGS': ['-fno-strict-aliasing']
148+
},
145149
'mode:debug': {
146150
'CCFLAGS': ['-g', '-O0'],
147151
'CPPDEFINES': ['ENABLE_DISASSEMBLER', 'DEBUG'],
@@ -651,8 +655,16 @@ def Abort(message):
651655
sys.exit(1)
652656

653657

654-
def GuessToolchain(os):
655-
tools = Environment()['TOOLS']
658+
def GuessOS(env):
659+
return utils.GuessOS()
660+
661+
662+
def GuessArch(env):
663+
return utils.GuessArchitecture()
664+
665+
666+
def GuessToolchain(env):
667+
tools = env['TOOLS']
656668
if 'gcc' in tools:
657669
return 'gcc'
658670
elif 'msvc' in tools:
@@ -661,7 +673,9 @@ def GuessToolchain(os):
661673
return None
662674

663675

664-
def GuessVisibility(os, toolchain):
676+
def GuessVisibility(env):
677+
os = env['os']
678+
toolchain = env['toolchain'];
665679
if (os == 'win32' or os == 'cygwin') and toolchain == 'gcc':
666680
# MinGW / Cygwin can't do it.
667681
return 'default'
@@ -671,27 +685,35 @@ def GuessVisibility(os, toolchain):
671685
return 'hidden'
672686

673687

674-
OS_GUESS = utils.GuessOS()
675-
TOOLCHAIN_GUESS = GuessToolchain(OS_GUESS)
676-
ARCH_GUESS = utils.GuessArchitecture()
677-
VISIBILITY_GUESS = GuessVisibility(OS_GUESS, TOOLCHAIN_GUESS)
688+
def GuessStrictAliasing(env):
689+
# There seems to be a problem with gcc 4.5.x
690+
# see http://code.google.com/p/v8/issues/detail?id=884
691+
# it can be worked around by disabling strict aliasing
692+
toolchain = env['toolchain'];
693+
if toolchain == 'gcc':
694+
env = Environment(tools=['gcc'])
695+
version = subprocess.Popen([env['CC'], '-dumpversion'],
696+
stdout=subprocess.PIPE).communicate()[0]
697+
if version.find('4.5.') == 0:
698+
return 'off'
699+
return 'default'
678700

679701

680702
SIMPLE_OPTIONS = {
681703
'toolchain': {
682704
'values': ['gcc', 'msvc'],
683-
'default': TOOLCHAIN_GUESS,
684-
'help': 'the toolchain to use (%s)' % TOOLCHAIN_GUESS
705+
'guess': GuessToolchain,
706+
'help': 'the toolchain to use'
685707
},
686708
'os': {
687709
'values': ['freebsd', 'linux', 'macos', 'win32', 'android', 'openbsd', 'solaris', 'cygwin'],
688-
'default': OS_GUESS,
689-
'help': 'the os to build for (%s)' % OS_GUESS
710+
'guess': GuessOS,
711+
'help': 'the os to build for'
690712
},
691713
'arch': {
692714
'values':['arm', 'ia32', 'x64', 'mips'],
693-
'default': ARCH_GUESS,
694-
'help': 'the architecture to build for (%s)' % ARCH_GUESS
715+
'guess': GuessArch,
716+
'help': 'the architecture to build for'
695717
},
696718
'regexp': {
697719
'values': ['native', 'interpreted'],
@@ -800,8 +822,15 @@ SIMPLE_OPTIONS = {
800822
},
801823
'visibility': {
802824
'values': ['default', 'hidden'],
803-
'default': VISIBILITY_GUESS,
804-
'help': 'shared library symbol visibility (%s)' % VISIBILITY_GUESS
825+
'guess': GuessVisibility,
826+
'depends': ['os', 'toolchain'],
827+
'help': 'shared library symbol visibility'
828+
},
829+
'strictaliasing': {
830+
'values': ['default', 'off'],
831+
'guess': GuessStrictAliasing,
832+
'depends': ['toolchain'],
833+
'help': 'assume strict aliasing while optimizing'
805834
},
806835
'pgo': {
807836
'values': ['off', 'instrument', 'optimize'],
@@ -811,19 +840,55 @@ SIMPLE_OPTIONS = {
811840
}
812841

813842

843+
def AddOption(result, name, option):
844+
if 'guess' in option:
845+
# Option has a guess function
846+
guess = option.get('guess')
847+
guess_env = Environment(options=result)
848+
# Check if all options that the guess function depends on are set
849+
if 'depends' in option:
850+
for dependency in option.get('depends'):
851+
if not dependency in guess_env:
852+
return False
853+
default = guess(guess_env)
854+
else:
855+
# Option has a fixed default
856+
default = option.get('default')
857+
858+
help = '%s (%s)' % (option.get('help'), ", ".join(option['values']))
859+
result.Add(name, help, default)
860+
return True
861+
862+
814863
def GetOptions():
815864
result = Options()
816865
result.Add('mode', 'compilation mode (debug, release)', 'release')
817866
result.Add('sample', 'build sample (shell, process, lineprocessor)', '')
818867
result.Add('cache', 'directory to use for scons build cache', '')
819868
result.Add('env', 'override environment settings (NAME0:value0,NAME1:value1,...)', '')
820869
result.Add('importenv', 'import environment settings (NAME0,NAME1,...)', '')
821-
for (name, option) in SIMPLE_OPTIONS.iteritems():
822-
help = '%s (%s)' % (name, ", ".join(option['values']))
823-
result.Add(name, help, option.get('default'))
870+
options = SIMPLE_OPTIONS
871+
while len(options):
872+
postpone = {}
873+
for (name, option) in options.iteritems():
874+
if not AddOption(result, name, option):
875+
postpone[name] = option
876+
options = postpone
824877
return result
825878

826879

880+
def GetTools(opts):
881+
env = Environment(options=opts)
882+
os = env['os']
883+
toolchain = env['toolchain']
884+
if os == 'win32' and toolchain == 'gcc':
885+
return ['mingw']
886+
elif os == 'win32' and toolchain == 'msvc':
887+
return ['msvc', 'mslink', 'mslib', 'msvs']
888+
else:
889+
return ['default']
890+
891+
827892
def GetVersionComponents():
828893
MAJOR_VERSION_PATTERN = re.compile(r"#define\s+MAJOR_VERSION\s+(.*)")
829894
MINOR_VERSION_PATTERN = re.compile(r"#define\s+MINOR_VERSION\s+(.*)")
@@ -904,7 +969,7 @@ def VerifyOptions(env):
904969
print env['simulator']
905970
Abort("Option unalignedaccesses only supported for the ARM architecture.")
906971
for (name, option) in SIMPLE_OPTIONS.iteritems():
907-
if (not option.get('default')) and (name not in ARGUMENTS):
972+
if (not name in env):
908973
message = ("A value for option %s must be specified (%s)." %
909974
(name, ", ".join(option['values'])))
910975
Abort(message)
@@ -1032,7 +1097,7 @@ def ParseEnvOverrides(arg, imports):
10321097
return overrides
10331098

10341099

1035-
def BuildSpecific(env, mode, env_overrides):
1100+
def BuildSpecific(env, mode, env_overrides, tools):
10361101
options = {'mode': mode}
10371102
for option in SIMPLE_OPTIONS:
10381103
options[option] = env[option]
@@ -1085,7 +1150,7 @@ def BuildSpecific(env, mode, env_overrides):
10851150
(object_files, shell_files, mksnapshot) = env.SConscript(
10861151
join('src', 'SConscript'),
10871152
build_dir=join('obj', target_id),
1088-
exports='context',
1153+
exports='context tools',
10891154
duplicate=False
10901155
)
10911156

@@ -1105,21 +1170,21 @@ def BuildSpecific(env, mode, env_overrides):
11051170
library = env.SharedLibrary(library_name, object_files, PDB=pdb_name)
11061171
context.library_targets.append(library)
11071172

1108-
d8_env = Environment()
1173+
d8_env = Environment(tools=tools)
11091174
d8_env.Replace(**context.flags['d8'])
11101175
context.ApplyEnvOverrides(d8_env)
11111176
shell = d8_env.Program('d8' + suffix, object_files + shell_files)
11121177
context.d8_targets.append(shell)
11131178

11141179
for sample in context.samples:
1115-
sample_env = Environment()
1180+
sample_env = Environment(tools=tools)
11161181
sample_env.Replace(**context.flags['sample'])
11171182
sample_env.Prepend(LIBS=[library_name])
11181183
context.ApplyEnvOverrides(sample_env)
11191184
sample_object = sample_env.SConscript(
11201185
join('samples', 'SConscript'),
11211186
build_dir=join('obj', 'sample', sample, target_id),
1122-
exports='sample context',
1187+
exports='sample context tools',
11231188
duplicate=False
11241189
)
11251190
sample_name = sample + suffix
@@ -1132,7 +1197,7 @@ def BuildSpecific(env, mode, env_overrides):
11321197
cctest_program = cctest_env.SConscript(
11331198
join('test', 'cctest', 'SConscript'),
11341199
build_dir=join('obj', 'test', target_id),
1135-
exports='context object_files',
1200+
exports='context object_files tools',
11361201
duplicate=False
11371202
)
11381203
context.cctest_targets.append(cctest_program)
@@ -1142,7 +1207,9 @@ def BuildSpecific(env, mode, env_overrides):
11421207

11431208
def Build():
11441209
opts = GetOptions()
1145-
env = Environment(options=opts)
1210+
tools = GetTools(opts)
1211+
env = Environment(options=opts, tools=tools)
1212+
11461213
Help(opts.GenerateHelpText(env))
11471214
VerifyOptions(env)
11481215
env_overrides = ParseEnvOverrides(env['env'], env['importenv'])
@@ -1156,7 +1223,7 @@ def Build():
11561223
d8s = []
11571224
modes = SplitList(env['mode'])
11581225
for mode in modes:
1159-
context = BuildSpecific(env.Copy(), mode, env_overrides)
1226+
context = BuildSpecific(env.Copy(), mode, env_overrides, tools)
11601227
libraries += context.library_targets
11611228
mksnapshots += context.mksnapshot_targets
11621229
cctests += context.cctest_targets

deps/v8/src/SConscript

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ root_dir = dirname(File('SConstruct').rfile().abspath)
3131
sys.path.append(join(root_dir, 'tools'))
3232
import js2c
3333
Import('context')
34+
Import('tools')
3435

3536

3637
SOURCES = {
@@ -305,7 +306,7 @@ def Abort(message):
305306

306307

307308
def ConfigureObjectFiles():
308-
env = Environment()
309+
env = Environment(tools=tools)
309310
env.Replace(**context.flags['v8'])
310311
context.ApplyEnvOverrides(env)
311312
env['BUILDERS']['JS2C'] = Builder(action=js2c.JS2C)

0 commit comments

Comments
 (0)