From 202df30aabc78fa571cf77ad93146b3c4d99fc6e Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 12 Jul 2012 15:42:44 +0200 Subject: [PATCH] build: disable unsafe optimizations Compile at -O2 and disable optimizations that trigger gcc bugs. Some people still reported mksnapshot crashes after commit b40f813 ("build: fix spurious mksnapshot crashes for good" - so much for that). Average performance of the -O2 binary is on par with the -O3 binary. Variance on the http_simple bytes/8 benchmark appears to be slightly greater but small enough that the possibly of it being noise cannot be excluded. The new binary very slightly but consistently outperforms the -O3 binary (by about 0.5%) on the mostly CPU-bound bytes/102400 benchmark. That could be an artifact of the system I benchmarked it on, a Core 2 Duo with a puny 32 kB of L1 instruction cache. The smaller binary seems to play nicer with the cache. --- common.gypi | 20 ++++++++++++++------ configure | 1 - deps/v8/build/common.gypi | 4 ---- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/common.gypi b/common.gypi index e12469ff459..6661166cbbe 100644 --- a/common.gypi +++ b/common.gypi @@ -8,6 +8,10 @@ 'component%': 'static_library', # NB. these names match with what V8 expects 'msvs_multi_core_compile': '0', # we do enable multicore compiles, but not using the V8 way + # Turn on optimizations that may trigger compiler bugs. + # Use at your own risk. Do *NOT* report bugs if this option is enabled. + 'node_unsafe_optimizations%': 0, + # Enable V8's post-mortem debugging only on unix flavors. 'conditions': [ ['OS != "win"', { @@ -41,13 +45,17 @@ }, }, 'Release': { - # Do *NOT* enable -ffunction-sections or -fdata-sections again. - # We don't link with -Wl,--gc-sections so they're effectively no-ops. - # Worse, they trigger very nasty bugs in some versions of gcc, notably - # v4.4.6 on x86_64-redhat-linux (i.e. RHEL and CentOS). - 'cflags!': [ '-ffunction-sections', '-fdata-sections' ], - 'cflags': [ '-O3' ], 'conditions': [ + ['node_unsafe_optimizations==1', { + 'cflags': [ '-O3', '-ffunction-sections', '-fdata-sections' ], + 'ldflags': [ '-Wl,--gc-sections' ], + }, { + 'cflags': [ '-O2', '-fno-strict-aliasing', '-fno-tree-vrp' ], + 'cflags!': [ '-O3', + '-fstrict-aliasing', + '-ffunction-sections', + '-fdata-sections' ], + }], ['target_arch=="x64"', { 'msvs_configuration_platform': 'x64', }], diff --git a/configure b/configure index b7d8498abdc..6ce54b8b655 100755 --- a/configure +++ b/configure @@ -297,7 +297,6 @@ def configure_node(o): # SunOS, and we haven't implemented it.) if sys.platform.startswith('sunos'): o['variables']['node_use_dtrace'] = b(not options.without_dtrace) - o['variables']['v8_no_strict_aliasing'] = 1 # work around compiler bug elif b(options.with_dtrace) == 'true': raise Exception('DTrace is currently only supported on SunOS systems.') else: diff --git a/deps/v8/build/common.gypi b/deps/v8/build/common.gypi index 2d8dc11b70d..16091978763 100644 --- a/deps/v8/build/common.gypi +++ b/deps/v8/build/common.gypi @@ -332,10 +332,6 @@ 'conditions': [ ['OS=="linux" or OS=="freebsd" or OS=="openbsd" or OS=="netbsd" \ or OS=="android"', { - 'cflags!': [ - '-O2', - '-Os', - ], 'cflags': [ '-fdata-sections', '-ffunction-sections',