You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit fb80a75
Browse filesBrowse the repository at this point in the historyBrowse files
Build with -O3 -fno-strict-overflow; drop -march=native (#8)
Steelmanning -march=native turned up the opposite of what we assumed, plus a
bigger problem underneath it.
-march=native is slower. ~12% behind plain -O3 on Zen 4, worst on the numeric
loops it should help most: -16% integer, -21% float. Two runs, 21 interleaved
passes, best-of. Microbenchmarks are the friendliest case it gets, so there's
no reason to expect a win on real work. Dropped.
The bigger find: the other four definitions were building unoptimized. Leaving
RUBY_CFLAGS empty doesn't mean "use configure's default" — ruby-build exports
it as CFLAGS, which supersedes configure's optflags in the compile line, so an
empty value is -O0. Measured 2.2-3.5x slower across method calls, integer math,
string building, hash churn and array ops. rbconfig still reports optflags: -O3
in that state, which is why it went unnoticed; the timings are what to trust.
Unintended fallout from b719789, which made RUBY_CFLAGS="" unconditional where
it had previously only been set under clang.
Turning optimization on activates two things -O0 was silently masking, and
neither is caught by "does it compile and run":
-fno-strict-overflow is mandatory, not caution. These sources assume signed
overflow wraps; GCC treats that as UB and exploits it from -O2 up. 1.8.7 built
at -O3 without it compiles clean, runs, loads every stdlib — and evaluates
2**64 to 0, typed Fixnum. Silent wrong arithmetic. Confirmed -O2 breaks it too,
and that the flag costs nothing measurable (within noise on 2.7.8, two of five
benchmarks nominally faster with it).
1.9.3 additionally caps _FORTIFY_SOURCE at 2 under GCC. Ubuntu's GCC raises it
to 3 whenever optimizing, and level 3's object-size inference aborts the build
with "*** buffer overflow detected ***" while running the freshly built
miniruby. Not a hardening regression: fortify does nothing without optimization,
so at -O0 there was none at all. Scoped to 1.9.3; the rest build fine at 3.
So test/build now asserts overflow arithmetic. The existing checks would have
passed a Ruby computing 2**64 == 0 — verified by building the unsafe variant and
watching it clear ruby --version, openssl, digest and zlib before the new
assertion caught it. Failures also dump ruby-build's own log now, and strip
curl's progress meter: several definitions send compiler output to that log
rather than stdout, and diagnosing the 1.9.3 abort meant reproducing it by hand
because the container took the log with it.
Full matrix green, 12/12 on Arch and Ubuntu Noble.
0 commit comments