Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
build: disable -fstrict-aliasing if gcc < 4.6.0
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bnoordhuis authored and isaacs committed Mar 2, 2012
1 parent 0613af0 commit 30b29d8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
17 changes: 8 additions & 9 deletions 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
Expand Down Expand Up @@ -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': {
Expand Down
31 changes: 19 additions & 12 deletions configure
Expand Up @@ -2,6 +2,7 @@
import optparse
import os
import pprint
import re
import subprocess
import sys
from distutils.version import StrictVersion
Expand Down Expand Up @@ -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
Expand All @@ -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))

This comment has been minimized.

Copy link
@shigeki

shigeki Mar 3, 2012

@bnoordhuis o['variables']['strict_aliasing'] is always false. Fixed in 031e9b3 . I can pay off my debt, Ben :-)

This comment has been minimized.

Copy link
@bnoordhuis

bnoordhuis Mar 3, 2012

Author Member

You're right, what a silly mistake. I broke up your patch into b6595c4 and d6f0ecc. Thanks, Shigeki!


# 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)
Expand Down

1 comment on commit 30b29d8

@shigeki
Copy link

@shigeki shigeki commented on 30b29d8 Mar 3, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent! #2830 was completely identified and solved. I respect and admire your efforts.

Please sign in to comment.