Skip to content


Restore -O3 default when we build with clang #351

merged 1 commit into from

6 participants


When we set the -Wno-error=shorten-64-to-32 cflags, Ruby says "oh, someone set cflags, I won't set any" and we lose its default -O3. That kills 1.9.3 and 2.0.0 perf.

Since clang can only build 1.9/2.0, we can safely assume that if we're adding the -Wno-error flag, we should also provide -O3 (-O2 is default for 1.8).

We set -O3 first since later -O options take precedence, so you can override with RUBY_CFLAGS="-Os" ...

@sstephenson sstephenson merged commit 2f8dcaf into rbenv:master
@jeremy jeremy deleted the jeremy:restore-o3-cflags branch

This is great! Could we please get a more recent v release version tag of the repository that contains it?




@sferik excellent, thanks!

@mroth mroth referenced this pull request in boxen/puppet-ruby

bump ruby-build version to fix compiler optimization bug #24


I just grabbed source and did a 2.0.0-p0 install, ran my test suite and it half a minute slower than it is on a manual install of 2.0.0-p0


@SamSaffron did you diagnose why?


not yet ... need to read through the logs, which means I need to reinstall


@SamSaffron you can check RbConfig::CONFIG['CC'] for your compiler and RbConfig::CONFIG['CFLAGS'] for -O3


I am seeing:

config.status: creating Makefile
config.status: creating ruby-2.0.pc
CC = gcc
LD = ld
LDSHARED = gcc -shared
XCFLAGS = -include ruby/config.h -include ruby/missing.h -D_FORTIFY_SOURCE=2 -fstack-protector -fno-strict-overflow -fvisibility=hidden -DRUBY_EXPORT -fPIE
CPPFLAGS = -I'/home/sam/.rbenv/versions/2.0.0-p0/include' -I. -I.ext/include/x86_64-linux -I./include -I.
DLDFLAGS = -fstack-protector -pie


something that is probably not that good.

where do I look up RbConfig::CONFIG['CFLAGS'] ?


Yeah my manual install has:

irb(main):002:0> RbConfig::CONFIG['CFLAGS']
=> " -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Werror=pointer-arith -Werror=write-strings -Werror=declaration-after-statement -Werror=implicit-function-declaration"

Brand new ruby-build install

irb(main):004:0> RbConfig::CONFIG['CFLAGS']
=> " "

maybe related to me running autoconf prior to configuring local when I did it manually ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 26, 2013
  1. @jeremy
Showing with 5 additions and 1 deletion.
  1. +5 −1 bin/ruby-build
6 bin/ruby-build
@@ -730,8 +730,12 @@ fi
# Work around warnings building Ruby 2.0 on Clang 2.x:
# pass -Wno-error=shorten-64-to-32 if the compiler accepts it.
+# When we set CFLAGS, Ruby won't apply its default flags, though. Since clang
+# builds 1.9.x and 2.x only, where -O3 is default, we can safely set that flag.
+# Ensure it's the first flag since later flags take precedence.
if "${CC:-cc}" -x c /dev/null -E -Wno-error=shorten-64-to-32 &>/dev/null; then
- RUBY_CFLAGS="$RUBY_CFLAGS -Wno-error=shorten-64-to-32"
+ RUBY_CFLAGS="-O3 -Wno-error=shorten-64-to-32 $RUBY_CFLAGS"
if [ -z "$MAKE" ]; then
Something went wrong with that request. Please try again.