From 30b29d8f8745263475d67576c4b81ff164482676 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 2 Mar 2012 02:14:27 +0100 Subject: [PATCH] build: disable -fstrict-aliasing if gcc < 4.6.0 A compiler bug in older versions of gcc makes it do unsafe optimizations at -O1 and higher. This manifested itself with (at least) gcc 4.5.2 on SmartOS because it made V8 hang in a busy loop. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45883 --- common.gypi | 17 ++++++++--------- configure | 31 +++++++++++++++++++------------ 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/common.gypi b/common.gypi index 699230ac337..6e13b6091ad 100644 --- a/common.gypi +++ b/common.gypi @@ -1,5 +1,6 @@ { 'variables': { + 'strict_aliasing%': 'false', # turn on/off -fstrict-aliasing 'visibility%': 'hidden', # V8's visibility setting 'target_arch%': 'ia32', # set v8's target architecture 'host_arch%': 'ia32', # set v8's host architecture @@ -34,19 +35,17 @@ }, }, 'Release': { + 'cflags': [ '-O3', '-fdata-sections', '-ffunction-sections' ], 'conditions': [ - [ 'OS!="solaris"', { - 'cflags': [ '-O3','-fomit-frame-pointer', '-fdata-sections', '-ffunction-sections' ], - }], - [ 'OS=="solaris" and gcc_optimize_level =="-O3"', { - 'cflags': [ '-O3', '-fdata-sections', '-ffunction-sections' ], - }], - [ 'OS=="solaris" and gcc_optimize_level =="-O"', { - 'cflags': [ '-O', '-fdata-sections', '-ffunction-sections' ], # For bug fix of #2830 - }], ['target_arch=="x64"', { 'msvs_configuration_platform': 'x64', }], + ['OS=="solaris"', { + 'cflags': [ '-fno-omit-frame-pointer' ], + }], + ['strict_aliasing!="true"', { + 'cflags': [ '-fno-strict-aliasing' ], + }], ], 'msvs_settings': { 'VCCLCompilerTool': { diff --git a/configure b/configure index 0b5254e1b2b..42ea12e9cb8 100755 --- a/configure +++ b/configure @@ -2,6 +2,7 @@ import optparse import os import pprint +import re import subprocess import sys from distutils.version import StrictVersion @@ -185,17 +186,17 @@ def host_arch(): def target_arch(): return host_arch() -def gcc_optimize_level(): - cc = ['gcc'] - cmd = cc + [ '-dumpversion' ] - p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - p.stdin.write('\n') - out = p.communicate()[0] - gcc_version = (str(out).split('\n'))[0] - if StrictVersion(gcc_version) >= '4.6.1': - return '-O3' - else: - return '-O' + +def gcc_version(): + try: + proc = subprocess.Popen('gcc -v'.split(), stderr=subprocess.PIPE) + except OSError: + return None + version = proc.communicate()[1].split('\n')[-2] + match = re.match('gcc version (\d+)\.(\d+)\.(\d+)', version) + assert match, 'Failed to parse gcc version `%s`' % version + return ['LLVM' in version] + map(int, match.groups()) + def configure_node(o): # TODO add gdb @@ -207,10 +208,16 @@ def configure_node(o): o['variables']['target_arch'] = options.dest_cpu or target_arch() o['default_configuration'] = 'Debug' if options.debug else 'Release' + # turn off strict aliasing if gcc < 4.6.0 unless it's llvm-gcc + # see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45883 + # see http://code.google.com/p/v8/issues/detail?id=884 + # TODO handle CC=clang + o['variables']['strict_aliasing'] = b(gcc_version() >= (False, 4, 6, 0)) + # TODO move to node.gyp if sys.platform == 'sunos5': o['variables']['visibility'] = '' # FIXME -fvisibility=hidden, should be a gcc check - o['variables']['gcc_optimize_level'] = gcc_optimize_level() # For bug fix of #2830 + def configure_libz(o): o['variables']['node_shared_zlib'] = b(options.shared_zlib)