Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit 30b29d8f8745263475d67576c4b81ff164482676 1 parent 0613af0
@bnoordhuis bnoordhuis authored isaacs committed
Showing with 27 additions and 21 deletions.
  1. +8 −9 common.gypi
  2. +19 −12 configure
View
17 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': {
View
31 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))
@shigeki
shigeki added a note

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
# 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)

1 comment on commit 30b29d8

@shigeki

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

Please sign in to comment.
Something went wrong with that request. Please try again.