RegExKitLite v. Clang

July 23rd, 2010

I finally updated to Xcode 3.2.3. I was a little late because I had other priorities, but I wanted to get my iPhone projects building and installing onto my iPhone OS 4.0 devices, so I decided to download and install the latest SDK.

Unfortunately, this seemingly minor update presented a major failure in my debug builds, which I’m adventurously compiling using the LLVM clang compiler. They built fine with Xcode 3.2.2, but starting in 3.2.3, I got a linkage failure, tracing back to the popular open source RegExKitLite:

Undefined symbols:
  "___gxx_personality_v0", referenced from:
      _rkl_debugCacheSpinLock in RegexKitLite.o
      ...
  "__ZSt9terminatev", referenced from:
      +[NSString(RegexKitLiteAdditions) clearStringCache]
      in RegexKitLite.o

What? Those symbols smack of C++, but there isn’t any C++ code in my project. At least, I don’t think there is. RegExKitLite is so famously advanced in its designed, I couldn’t easily tell you whether there was stuff in there intended as C++ or not. On a whim, I tried to switch the file type to C++ to see if that made clang any happier. No, it screamed bloody murder. It agrees with me, RegExKitLite is not C++ code.

So why the link errors? I examined the compile line carefully for RegExKitLite and confirmed that it’s using clang in a manner that should only be generating plain C linkage:

/Developer/usr/bin/clang -x objective-c -arch x86_64 ...

But when I look at the resulting RegExKitLite.o with the “nm” command-line tool, it shows the culprits symbols have been listed as references in the binary object file:

% nm RegexKitLite.o | grep -e terminate\\\|personality 
                 U __ZSt9terminatev
                 U ___gxx_personality_v0

Normally when I’m getting some kind of issue like this, I just type in the problematic symbols in to Google and usually find somebody else has found and solved the problem. No such luck this time. There are lots of false positives for the typical reason somebody runs into this link error: they are compiling legitimate C++ code but neglecting to link with the stdc++ library. But in our case, we are not compiling C++ code, but we’re ending up with C++ dependencies nonetheless.

I hopped on to the #clang IRC channel on irc.oftc.net, where a couple extremely helpful clang engineers (thanks to dgregor and rjmccall) helped talk me through the problem, and determine that it does seem to be a clang 1.5 bug. They confirmed that with their latest and greatest clang the bug seems to be fixed, but I was curious to confirm it myself, so I checked out and built the latest clang, too. Sure enough, all is well for future generations!

But what do we do now, stuck with the clang 1.5 that ships with Xcode? There is a crude workaround: simply link to stdc++. But yuck! All that C++ linkage dirtying up my pristine Objective-C project? Since I only use clang (for now) to build debug builds, I don’t have too much of a problem doing this. But if I was shipping these binaries I would be very hesitant to make that concession.

Radar #8230225: clang 1.5 forces linkage to C++ for non-C++ source file
(Open Radar Link)

The best we can do is report the issue to Apple and let them decide whether it’s worth their time to backport whatever fix in later clang is missing from clang 1.5. If you have other suggestions for how to work around the problem in the mean time, please do chime in with a comment below.

Update: The author of RegExKitLite kindly chimed in below with a pointer to the revision in the clang source repository that that fixes the issue. He also suggests a simple, and seemingly safe workaround, involving a slight tweak to the RegExKitLite source code.

Surviving Success

July 19th, 2010

Apple is taking a beating, even while at its most victorious.

After the launch of the iPhone 4, a well-designed device with one easily-demonstrable flaw, the company is losing its famous control over the emphasis of press coverage. Apple is typically brilliant at walking the line between humility and pomposity, adjusting its tone to suit the current situation.

When Apple was suffering in the late 1990’s, it played to historic core values with campaigns like “Think Different,” but held on to the sliver of confident superiority that helps to sell its brand. Now that it’s on top of the world, it tends more toward a triumphant strut, with just a dash of idealism. Recent blunders paint the company as both arrogant and user-hostile, two attributes that incite pundits to attack without mercy.

Nobody likes a sore winner. Whatever the fight, struggle, ambition, the odds are good that judgement will be harshest on the one who emerges victorious. Anybody who ever received an A+ on an exam in grade-school, only to have the teacher publicly celebrate it among classmates, knows that success turns you into a target. Surviving that success requires careful management of one’s own image, as perceived by the audience that was most invested in the outcome.

Imagine you’ve just achieved something incredible. Bystanders will react with one of three reactions: praise, indifference, or scorn. You can ignore the majority, who don’t care a whit one way or another. Your fate will be decided by the passionate minority, so you must inspire fans to be more passionate and tireless than detractors. A small, energized core of supporters can outlast even a large, committed group of critics. At its best, Apple inspires passionate users to identify more with the company’s egalitarian rhetoric than with the billions of dollars that are flowing into the company’s bank accounts. (The billions are pretty inspirational to stockholders, however).

Apple makes fantastic products that are, by and large, defect free. In my opinion, they deserve to win. I applaud the company, and in particular, its employees. As the years go by, almost every part of the company seems to be improving. They routinely launch new products that stun and delight us with a combination of obviousness-in-hindsight, and that futuristic “Apple magic.” Kudos to them.

Apple is also brilliant at public relations. They produce beautiful, inspiring advertisements. Their web content strikes the balance of confidence and customer-centric humility. And their rank-and-file employees show off their passion for the company in email lists, internet fora, and on Twitter. But at the height of success, the fact that critics are gaining the upper hand is evidence that the company is failing to control its image.

Most of Apple’s recent PR gaffes trace back directly to Steve Jobs. His famous arrogance was exactly what the company needed while it restored itself to, and then surpassed, its former glory. During Apple’s recovery, detractors belittled and dismissed Apple as an “also-ran” company, suggesting they should give up and yield to the obvious victories of companies like Dell and Microsoft. But Jobs ignored the critics and spoke to the fans, inspiring us to stand by and loudly defend Apple.

Now that Apple is on top again, Jobs seems to be losing that knack for inspiring fans. He’s turning into a sore winner. He defensively chides his own customers for holding their iPhone 4 “the wrong way.” He tersely defends questionable Apple practices in one-liner email responses. He spins the truth in that barely plausible manner that used to be celebrated as the “reality distortion field,” but now comes off as purposefully dishonest and manipulative.

I believe Jobs is an idealist product visionary who wants the best for Apple and for its customers. But he’s lost his ability to manage his own image, and thus the image of the company. Apple’s PR department is in charge of manipulating how the company is perceived, but their efforts are being drowned out by the live-wire personality at the helm of the ship. Jobs needs to quiet down now and let cooler heads speak. No more arrogant, terse email replies. No more defensive press conferences. No more snarky interview quips. Just chill out and try to get your groove back.

At his best, Steve Jobs is a brilliant, inspirational spokesman for the company. At his worst, he is the pompous winner who begs to be taken down a notch. Jobs is the kid who, having been celebrated for the A+ exam grade, reacts by chiding his classmates: “You all are a bunch of idiots.” Fans lose their faith, detractors gain momentum. This guy’s in for a rough victory.


This entry was inspired by Michael Tsai’s Tone.

Say Yes

July 3rd, 2010

Derek Sivers captures the human side of business and just about everything else on his life-lessony blog.

His latest, My Loss, reminds us that even successful entrepreneurs have gone through the wringer more than once, and have made their share of mistakes.

I especially like the “moral” of this latest post:

Say “no” where you used to say “yes”. Say “yes” where you used to say “no”. Do the thing that scares you the most, then get up and go.

This captures the essence of one of my own self-motivational mantras: “Say Yes.”

When someone asks me to speak at a conference, write an article, give a toast at a wedding, attend a conference, or just to have lunch, my gut reaction is to refuse.

Almost every public thing I do that pulls me away from my computer and out of my house, comes from saying yes when I want to say no. I psyche myself up, remember that this life isn’t going to drive itself where I want it to go, and step up to the plate.

Say yes.

 

Pain Is A Gift

May 27th, 2010

Fans of Apple’s iPhone and iPad platforms should be thrilled by the exciting news coming out of Google last week.

At the company’s I/O conference they announced Android 2.2, or “Froyo,” a significant update to their mobile phone OS. The open platform powers many of the iPhone’s most viable competitors, including the Verizon Droid, and Google’s own Nexus One.

Why is this good for the iPhone? Because it’s doomed without a proper competitor, and thus far, it’s been lacking one. What happens to fighters who nobody spars with? Regardless of size, skill, or strength of weapon, they end up flopping about the arena alone. Never defeated, but never victorious.

Apple came out swinging with the launch of iPhone in 2007, and has done an admirable job of shadowboxing: enhancing the device and expanding the platform with iPod touch and iPad. In the absence of serious competition Apple’s legendary paranoia has served some of the same function, but grit and independence of vision will only get you so far.

The details of Android 2.2 are not that interesting to me. What’s important and inspiring is that they are iterating on the product, and not throwing their arms up in defeat. Google lets us know they will not be sitting this round out, and their fighting posture sends a message to Apple, and to the world: the iPhone is assailable.

In order for Apple to benefit from this fight, they need to zero in on the qualities of Android that actually pose a threat. Sam Pullara attempted to give them a hand, by identifying Android 2.2’s lightning-fast Java VM as a potentially deadly blow. I think Sam is overstating the performance overhead in Objective-C. The language’s message-dispatch features have been so finely-tuned by Apple that any criticisms should come pre-loaded with proof of specific performance problems.

Even if we assume that Android’s fast VM does trump Objective-C for speed, is it meaningful to the competition? Duncan Davidson, an excellent photographer who happens to also be a legendary Java expert, says no:

“A faster VM will certainly help things out. But Android’s eventual fate will have little to do with how fast the VM is or how long method dispatches take on the iPhone. Instead, it’ll have to do with harder things like user experience, service plans, interoperability, and excellent applications.”

By most accounts, Android phones still fail to match iPhone when it comes to all those things that Apple does best: simplicity, attractiveness, and refinement of the user experience. But Google knows there is much about Android that pleases: more features, and fewer limitations. They’re using this allure to push the Nexus One on folks who would otherwise be naturally aligned with the iPhone.

The flow of free phones out of Google is measurable by the amount of surprising, casual-switcher chatter I’m seeing on Twitter and in blogs. I got one email from a colleague who announced, “I’m switching to a Nexus One for the week, so please use my Google Voice number to contact me.” If somebody is switching phone platforms, and they know in advance that it’s only a 1-week trial, there’s a good bet they didn’t pay for the phone.

The free-phone strategy is working, prompting fair feedback from folks who nonetheless find plenty of negatives to criticize. Justin Williams demonstrates this with his guarded praise:

“Android is certainly a capable smartphone operating system. In fact, if the iPhone never existed, it’d be pretty great.”

The fact that its greatness hinges on the iPhone not existing is a problem, but it also underscores that iPhone is the primary challenge to Android’s success. Even though Justin stops short of declaring Android a winner over iPhone, he concedes that he’ll probably keep using it until the 4G iPhone is released.

Mike Ash offers similarly candid feedback:

“First full day with the Nexus One. Verdict: substantially uglier, harder to use, but VASTLY more powerful than an iPhone.”

This impression from Mike fits perfectly into the marketing message from Google and its mobile allies. I barely watch any television, and even I know that evidently “Droid Does.” The world is more thuggish than frilly, more impressed by strength than finesse, and this message will work. Android is the gigantic, Dunkin Donuts Coffee Coolatta to Apple’s dainty espresso cup. Still, if you’re only going to offer a couple advantages over the iPhone, power and freedom are not poor choices.

As John Gruber points out, even if Android or another platform takes a dominant position, it doesn’t necessarily spell disaster for the iPhone. Apple’s advantage, as demonstrated by the Mac, is they don’t need to serve the masses to succeed:

“Apple could positively thrive with a long-term mobile market share of, say, 20-25 percent” … “In the phone industry today — all mobile phones, not just smartphones — Nokia sells more than 10 times as many units as Apple, but Apple generates more profit.”

Playing the underdog suits Apple well. I have enjoyed, as a fan and stockholder, their success over the past several years, but it’s changed them. From a company that balanced its own ideals against the demands of developers and competitors, to one that holds a firehose to repel all naysayers.

The risk to Apple is not in losing the masses, but in losing the faithful core. In their unchallenged position, Apple made a lot of right decisions, but they also made mistakes, particularly in the form of political moves that limit what developers can distribute on the platform. These restrictions are done in the name of quality control, but anybody who has browsed the App Store knows that all this autonomy has done little to stem the flow of trashy, embarrassing apps.

What they have done is alienated developers, and ultimately deprived users of software they want to see on the platform. My fear is these botched decisions are hurting Apple, but they aren’t feeling it. Pain is a gift: the signal that prevents a burned finger tip from becoming a body engulfed in flames. Apple is numb from success, and I hope the emerging competition from Google and others will re-sensitize them to the threat of failure.

Google’s Android is the best challenge yet to the political and technical decisions made by Apple for its iPhone and related products. I welcome the challenge, and look forward to Apple’s scrappier, revitalized retaliation.