XCode 4 ships a buggy compiler »
Created at: 31.12.2011 03:04, source: Phusion Corporate Blog, tagged: os x programming Ruby Enterprise Edition
You may have heard of LLVM, a compiler infrastructure library. You may have heard of GCC, the GNU C and C++ compiler. Those two are completely separate software products, but there exists llvm-gcc which is a GCC frontend that utilizes LLVM. All OS X versions <= Snow Leopard originally shipped with regular gcc, but as of Xcode 4 (which is also the default on OS X Lion) Apple has switched to llvm-gcc as their default compiler. “Hurray”, some people may think, as they heard that LLVM generates better code and/or is faster than default GCC. Unfortunately, the reality is not that great.
llvm-gcc is unmaintained and is considered deprecated by its developers. It has many bugs that will never be fixed. Unfortunately these are not obscure bugs that few people will notice: today, while working on Ruby Enterprise Edition, we encountered several! Calling alloca(0) should return a pointer to the top of the stack. On llvm-gcc however, that code returns NULL but only when compiled with -O2! llvm-gcc also generates subtly different code that causes the MBARI patch set to fail completely.
To make matters worse, consider this program:
#include <alloca.h>
int
main() {
if (alloca(0) != NULL) {
return 0;
} else {
return 1;
}
}
Question: when compiled with “llvm-gcc -O2″, does this program exit with 0 or with 1?
That was a trick question. It always returns with 0, even when alloca(0) is broken and actually returns NULL. Turns out the optimizer in -O2 thinks that alloca(0) doesn’t return NULL (even though it does) and replaces if (alloca(0) != NULL) with if (true).
It is unfortunate that we have to declare OS X’s default compiler as being broken. We do not recommend its use. Instead, we recommend people to use /usr/bin/gcc-4.2 (which is the non-LLVM GCC compiler) instead of /usr/bin/gcc (which is a symlink to /usr/bin/llvm-gcc). You can enable this on most build systems by setting these two environment variables:
export CC=gcc-4.2 export CXX=g++-4.2
On a side note, Ruby Enterprise Edition 2011.12 is being released. The official announcement hasn’t been written yet, but we’ve made haste because of the recent Ruby security vulnerability. You can already get the files on the Ruby Enterprise Edition website. An announcement will follow soon.
Update
some people have pointed out that they consider alloca(0) undefined. I guess it depends on the way you interpret the documentation. It would seem pretty clear to me what alloca(0) means, just like what memcpy(x, y, 0) means, but it’s understandable when some people would interpret it as undefined.
Still, alloca(0) failing is only one of the problems that prevented Ruby from compiling properly.
Why alloca(0)?
alloca(0) is used in Ruby Enterprise Edition’s conservative garbage collector, as a way to detect the end of the stack. There’s a bunch of fallback #ifdefs in the code: on platforms that don’t have alloca, it detects the end of the stack by calling a forced-non-inline function which returns the address of its sole local variable, but that assumes that the compiler supports the ‘noinline’ keyword. In any case, all of versions depend on highly platform-specific behavior.
more »
Double Shot #646 »
Created at: 11.02.2010 13:50, source: A Fresh Cup, tagged: Double Shot bash cerberus git iPhone os x PostgreSQL ripple
Another semi-random walk through my corner of the internet.
- ripple - Ruby client for the Riak distributed database.
- Cerberus 0.7.5 Released - New version of the Ruby CI server that I'm happiest with at the moment, now with Mercurial support.
- GLTerminal - If OS X leaves you pining for the distorted fuzzy green-screen thin clients of yore, this little piece of freeware is the cure.
- Turn Off Google Buzz With One Click - Really, the only thing you need to know.
- The iPhone obsession - Doomed argument that web devs should care about standards instead of candy.
- Easiest Postgres Install Ever - Mac Edition - Script from Wayne Seguin, passed on by Philip Ingram.
- Git Autocomplete in Mac OS X - A tiny little bit of shell convenience. If you use the Git for OS X Installer, you already have the script on your drive.
- HoudahSpot - Search/Find utility for OS X that actually finds what I'm looking for, unlike Spotlight. Yeah, if I was a Spotlight pro there are probably commands to do all this. It's easier to spend money than time, though.
- rake_cap_bash_autocomplete - More autocomplete fun for bash. A bit slow though on my Mac.
more »
Double Shot #641 »
Created at: 04.02.2010 14:17, source: A Fresh Cup, tagged: Double Shot dterm haml localization maps os x tableau toto
Sleep seems overrated until you have to skip it for a while.
- gMap - jQuery plugin for Google Maps. Looks way easier than the last way I've done it.
- webtranslateit - Gem to integrate a Rails app with Web Translate It, a web service to help provide localization.
- Why use HAML (and SASS)? I already know HTML. - Another argument in favor of switching to HAML/SASS. This is rapidly becoming the vi vs. emacs of templating languages.
- toto - Blog engine built atop rack and aimed at heroku deployment.
- Ubiquitous Analytics and Tableau Public - This looks nice; the Tableau data visualization app is one of the things I remember from Windows days, and now they're bringing it to the web.
- DTerm - Popup command line for OS X.
more »
Double Shot #625 »
Created at: 13.01.2010 14:06, source: A Fresh Cup, tagged: Double Shot bombax cms jquery os x sandstone workflow
Next couple of weeks are looking super busy. Better than the alternative by far.
- I Have No Talent - Words well worth reading from John Nunemaker. There are ample ways to succeed in this business without being some sort of uber-coding genius. Trust me, I know.
- I Am Not a Master but a Solutionist - And Rob Bazinet chimes in to promote getting the job done.
- Sandstone - One more approach to CMS in Rails. Looks like there are several active branches with no one merging them though.
- Vote for Barbie's Next Career - "Computer engineer" is in the running.
- TotalFinder - Using SIMBL to make Finder better in Snow Leopard.
- TipTip JjQuery Plugin - A simple custom tooltip plugin.
- Bombax - Objective-C and Cocoa web development framework. No thanks.
- workflow - Another state machine alternative for Ruby.
more »
Double Shot #621 »
Created at: 07.01.2010 11:58, source: A Fresh Cup, tagged: Double Shot jruby minitest os x quantity
I'm not sure I can recommend insomnia as a business strategy, but it works for me.
- Mount options to improve ext4 file system performance - Speed up tests by using a box where you run a bit looser on file reliability.
- quantity - Units and conversions in a ruby gem.
- Today 2.0 Released! - Easy interface for events and tasks under OS X.
- minitest version 1.5.0 has been released - Tests, specs, and mocks made small and fast.
- JRuby BugMash! - Looks like Rails isn't the only one with a BugMash now.
- Create schema-less, dynamic model attributes - Via a new plugin from Joel Moss.
more »
