LWN.net Logo

LLVM gets its own C++ standard library

The LLVM libc++ project has announced its existence. "libc++ is an implementation of the C++ Standard Library, with a focus on standards compliance, highly efficient generated code, and with an aim to support C++'0x when the standard is ratified." The project is said to be "approximately 85% complete at this point."
(Log in to post comments)

LLVM gets its own C++ standard library

Posted May 12, 2010 14:31 UTC (Wed) by Cyberax (✭ supporter ✭, #52523) [Link]

Yet another C++ lib.

Thanks, that's exactly what we need.

-1

Posted May 12, 2010 14:40 UTC (Wed) by Webexcess (subscriber, #197) [Link]

I think it's time for some comment moderation on LWN. The days of "oh look, a comment! Someone must have invested the time to add something useful for everyone to read" are past.

-1

Posted May 12, 2010 15:48 UTC (Wed) by foom (subscriber, #14868) [Link]

Oh come on. Sure, he just said what most everyone was thinking anyways, but that's not *that* terrible a thing.

LLVM gets its own C++ standard library

Posted May 12, 2010 15:18 UTC (Wed) by foom (subscriber, #14868) [Link]

Yeah.

But I think it's likely that this one will actually stick, unlike the other attempts at alternative c++ stdlib implementations (for example, apache stdcxx, which seems to have been essentially abandoned).

Apple has been putting *serious* resources into getting rid of their dependency upon GCC, ever since the switch to GPLv3. I guess they feel they have no choice: either invest in a compiler infrastructure with a different license and bring it up to speed, or be left behind with an old release of GCC forever.

So, LLVM is now very close to being competitive with GCC. With the resources being expended, I have little doubt that libc++ will soon be competitive with libstdc++, as well.

Interesting times in the OSS compiler world -- a license change is always a dangerous prospect for a project, you risk upsetting the status quo, as has happened here. GCC was unchallenged for so long, and there was very little indication that they would be, until they switched to GPLv3.

It's a bit ironic that the end result of that license switch might be to make the GPL's restrictions less relevant than before, though, due to it triggering the development of a good alternative under a permissive license. But I am glad Apple is doing this work in such a way (BSD licensed) that everyone else can benefit from their investment...even though it does undermine a bit the FSF's goals.

Hopefully both LLVM and GCC continue to live long and prosperous lives -- competition is often healthy for both projects, and I hope that remains the situation in this case.

LLVM gets its own C++ standard library

Posted May 12, 2010 15:39 UTC (Wed) by Cyberax (✭ supporter ✭, #52523) [Link]

I don't really understand why we even NEED faster libstdc++. It's quite basic, there's not much places where you can gain more performance without violating C++ Standard.

Also, there's STLPort and Roguewave's libstdc++ if I'm not mistaken. All under very liberal licenses.

LLVM gets its own C++ standard library

Posted May 12, 2010 20:39 UTC (Wed) by da4089 (subscriber, #1195) [Link]

The Roguewave code became the Apache STDCXX project: http://stdcxx.apache.org/

LLVM gets its own C++ standard library

Posted May 12, 2010 21:12 UTC (Wed) by foom (subscriber, #14868) [Link]

And then abandoned.

LLVM gets its own C++ standard library

Posted May 14, 2010 15:47 UTC (Fri) by rriggs (subscriber, #11598) [Link]

Details of what happened can be found here: http://stdcxx.apache.org/status/2009-05.text

Basically the key developers were all RogueWave employees and were either let go or reassigned. As a result, there has been virtually no progress in adding C++0x support to the library.

I wonder what this means for Sun's decision back in '08 to adopt this as the default C++ standard library for Solaris.

http://arc.opensolaris.org/caselog/PSARC/2008/549/opinion...

It would seem rather foolish to adopt a stalled project as a core component of one's OS.

LLVM gets its own C++ standard library

Posted May 14, 2010 16:33 UTC (Fri) by jwakely (subscriber, #60262) [Link]

As opposed to the even more stagnant C++ standard library they ship currently?

LLVM gets its own C++ standard library

Posted May 12, 2010 21:49 UTC (Wed) by elanthis (guest, #6227) [Link]

Just because you don't understand the need doesn't mean it isn't there.

Some of us actually do give a damn about speed and don't believe that "buy a bigger CPU" is an actually feasible solution to every lazily implemented piss-poor library out there. Some people actually develop software for systems that don't have 4GB+ of RAM and 3GHZ+ CPUs. Some people actually deliver software that runs on old PCs, most of which don't even have two cores much less four or six. Some people realize that just because a CPU can handle a less efficient algorithm at acceptable speeds that doesn't mean that the battery of the device appreciates that extra workload. Some people just need to get really, really complex sets of algorithms processed over massive amounts of data in at least 30 or 60 frames per second on modest hardware. Lo and behold, many of those people are using C++ and the STL, and it turns out that even very modest efficiency gains in a piece of code used millions of times over the course of a single algorithm actually adds up to very measurable gains.

There are people who actually need to rewrite such basic STL containers as std::vector because the implementation that comes with their compiler is utter crap. MSVC's std::vector::iterator for example imposes massive efficiency losses over a sane pointer-based implementation. The ability to eliminate copies results in a quite massive performance improvement on even very modern hardware. Adding SSE/NEON/AltiVec/etc.-optimized versions of various core STL algorithms and helpers can have a huge impact on performance, especially when you remember that those SIMD instructions can be used for a lot more than just optimizing vector and matrix math. Simply restructuring the implementation of algorithm for a different compiler can help ensure that the targeted compiler's optimization passes work more efficiently. In many cases, the entire algorithm used to back a particular STL algorithm or container can be replaced for better performance (for a particular workload) without any violation of the STL standard. Look at how many different ways std::map or std::string or std::deque or std::sort can be implemented and remain compliant with the STL standard, for example.

LLVM gets its own C++ standard library

Posted May 12, 2010 21:56 UTC (Wed) by dlang (✭ supporter ✭, #313) [Link]

another reason for speed/efficiancy is that while you may have a nice fast processor dedicated to you in your desktop/laptop, when you use 'the cloud' you are sharing the processor with a few thousand other people at the same time.

I've seen websites configured so that you could run several hundred sites on a single server, and then move to different software (with the same end-user features) and require a dozen servers to support half a dozen sites.

Such inefficiancies can just plain rule out the use of software in many situations.

LLVM gets its own C++ standard library

Posted May 13, 2010 5:50 UTC (Thu) by cpeterso (guest, #305) [Link]

And efficient C++ is needed on the other end of the spectrum from the cloud: mobile devices with slow processors and limited battery life. Embedded devices have notoriously crappy, proprietary toolchains. (And I must use them every day.)

LLVM gets its own C++ standard library

Posted May 12, 2010 15:44 UTC (Wed) by eparis123 (guest, #59739) [Link]

It's a bit ironic that the end result of that license switch might be to make the GPL's restrictions less relevant than before, though

Protecting freedom is 'like a fencer who's learning to hold his sword as if it was a bird: too tight and the bird will be injured; too loose and it will fly away'

Adapted from Tom Demarco's paper on control :)

LLVM gets its own C++ standard library

Posted May 12, 2010 16:30 UTC (Wed) by bronson (subscriber, #4806) [Link]

Good analogy. To me, GPLv3 feels like it's injuring the bird.

LLVM gets its own C++ standard library

Posted May 12, 2010 17:07 UTC (Wed) by drag (subscriber, #31333) [Link]

Well all of this is fine and dandy, but Apple started investing in LLVM prior to any draft version of the GPLv3 being available.

And while I agree that Apple probably really dislikes GPLv3, one of the big reasons would be that LLVM's license would allow them to contribute code while retaining their patent rights.

That being said it's probably good for both GCC and LLVM that there is now starting to have serious competition between the two projects. It shows that you can still have a competitive and innovative landscape with OSS software.

LLVM gets its own C++ standard library

Posted May 13, 2010 19:56 UTC (Thu) by rahvin (subscriber, #16953) [Link]

And those patent rights will one day be used offensively against a Linux company. I have no doubt of that.

LLVM gets its own C++ standard library

Posted May 13, 2010 16:05 UTC (Thu) by madscientist (subscriber, #16861) [Link]

Maybe I missed something: what difference does it make to the user of the compiler, whether the compiler is under GPLv2 or GPLv3?

Or, are you talking about modifications they want to make to the compiler itself? In that case, what changes in GPLv3, beyond GPLv2, are they worried about for changes they want to make?

LLVM gets its own C++ standard library

Posted May 13, 2010 16:36 UTC (Thu) by foom (subscriber, #14868) [Link]

It matters to the distributor (e.g. Apple), not the user.

I'd guess they don't like the anti-DRM clauses (might forbid what they're doing with the iPhone?), but who knows, it might be the new patent clauses too. Or something else entirely.

I don't have any inside knowledge, and Apple has never actually stated publicly what they find objectionable about GPLv3. But it is well known at this point that Apple does find it objectionable for some reason, and will not distribute GPLv3 covered code. And furthermore, won't let their employees even touch GPLv3 code.

LLVM gets its own C++ standard library

Posted May 13, 2010 17:06 UTC (Thu) by madscientist (subscriber, #16861) [Link]

Hrm. Well, I personally don't see anything in GPLv3 that would preclude them using GCC, and if they're not going to be clear about the problems they have I see very little incentive to discussing it further, or blaming the situation on GPLv3.

I remember not so very long ago where almost every company had exactly this attitude about GPLv2 (find it objectionable, won't distribute code covered by it, won't let their employees touch it). Was that a reason to not adopt GPLv2? Those companies, by and large, came to grips with their own FUD when they realized the upside they were missing out on. Maybe that won't be the case here... but maybe it will.

LLVM gets its own C++ standard library

Posted May 13, 2010 20:04 UTC (Thu) by foom (subscriber, #14868) [Link]

To be clear, I wasn't blaming the GPLv3 itself, nor saying people shouldn't adopt the GPLv3 -- I was attempting to say that any change to a license has the potential to cause some of users to abandon the project due to fears of the new license, whether those fears are founded in reality or not.

LLVM gets its own C++ standard library

Posted May 13, 2010 22:52 UTC (Thu) by elanthis (guest, #6227) [Link]

There is a big difference with the GPLv3, though. The GPLv2 only really covered the actual code being distributed, not patent rights. If a company didn't directly inject any copyrighted code into the GPLv2 code they distributed then they had nothing to worry about. The GPLv3 basically states that if they distribute GPLv3 code then they automatically give up patent enforcement rights that the code happens to use (even though they may not have written that code).

The GPLv2 is always safe to distribute unmodified; it's only "dangerous" when mixed with their proprietary code. The GPLv3 can be very "dangerous" just to distribute, with or without modifying it.

The GPLv2 is weak because a company can distribute code to you under the GPLv2 and then still sue you for using it without a patent license, which is why the FSF deprecated it.

GPL version doesn't matter

Posted May 13, 2010 17:33 UTC (Thu) by sbishop (guest, #33061) [Link]

I don't think that Apple's work on Clang and LLVM has anything to do with the GCC license switch. The first draft of GPL version 3 wasn't published until 2006, but Apple had taken on the LLVM project the year before.

The parts of GCC were not intended to be reused separately, especially as an integrated part of proprietary software such as Apple's Xcode. This is reflected in its license and design. (The latter was part of the reason why Linus Torvalds didn't use any parts of GCC when writing sparse.)

I don't trust Apple. But it's interesting to note that Adobe--of all companies--is a strong fellow contributor to LLVM. (They're often seen on the mailing lists, and they're sponsors of the LLVM developer meetings.) That and the fact that contributions don't have to be signed over to Apple makes me think that it would be safe for LLVM to become part of the standard Linux software stack. Not to the point of replacing GCC, though! I don't trust them that much.

GPL version doesn't matter

Posted May 13, 2010 18:09 UTC (Thu) by hharrison (subscriber, #39162) [Link]

You do however have to assign the copyright for your contributions over to the University of Illinois. While I don't think they require you to sign anything, look at the developer agreement (the very end)

http://llvm.org/docs/DeveloperPolicy.html#clp

LLVM gets its own C++ standard library

Posted May 12, 2010 14:46 UTC (Wed) by Trelane (subscriber, #56877) [Link]

This looks like an Apple code dump.

Looking at the src/ directory shows two checkins in all of the files I've looked at, e.g.
http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/algo...
"Revision 103516 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Tue May 11 16:36:01 2010 CDT (17 hours, 5 minutes ago) by hhinnant
File length: 3792 byte(s)
Diff to previous 103490 (colored)

Wiped out some non-ascii characters that snuck into the copyright.

Revision 103490 - (view) (download) (as text) (annotate) - [select for diffs]
Added Tue May 11 14:42:16 2010 CDT (18 hours, 58 minutes ago) by hhinnant
File length: 3792 byte(s)

libcxx initial import"

(except the www directory)

LLVM gets its own C++ standard library

Posted May 12, 2010 15:01 UTC (Wed) by cowsandmilk (guest, #55475) [Link]

Yes, it is pretty obvious that it is starting as an apple code dump, but that gives no indication of future prospects for the project. Apple has had projects that continued to be periodic code dumps, while others that started as code dumps, but now are collaborations with committers external to the company. LLVM seems to have done a good job building a community, and this coming out of the same group within apple and being a subproject of LLVM gives it good prospects.

LLVM gets its own C++ standard library

Posted May 12, 2010 15:39 UTC (Wed) by JoeBuck (subscriber, #2330) [Link]

LLVM has some great developers, people that I deeply respect. But it's fair to warn that the last 15% of the library is likely to consume at least 2/3 of the work, and getting such a huge library up to the standard of correctness that libstdc++ meets will take even longer.

LLVM gets its own C++ standard library

Posted May 12, 2010 15:47 UTC (Wed) by foom (subscriber, #14868) [Link]

It'd also be fair to note that libstdc++ is also not at 100%. It's missing large chunks like regex as well.

LLVM gets its own C++ standard library

Posted May 12, 2010 16:23 UTC (Wed) by HelloWorld (guest, #56129) [Link]

100% of what? The C++98 and C++03 standards don't currently include a regex library.

LLVM gets its own C++ standard library

Posted May 12, 2010 16:29 UTC (Wed) by foom (subscriber, #14868) [Link]

C++0x of course.

From libc++'s webpage:
"libc++ is a new implementation of the C++ standard library, targeting C++0X."
"libc++ is still under development. It has about 85% of N3092 implemented/tested."
(with N3092 being the the latest C++0x draft standard)

LLVM gets its own C++ standard library

Posted May 12, 2010 16:40 UTC (Wed) by HelloWorld (guest, #56129) [Link]

Claiming that libstdc++ doesn't support the C++0x fully is redundant. No C++ standard library implementation supports C++0x fully, because the C++0x standard isn't done yet.

LLVM gets its own C++ standard library

Posted May 12, 2010 17:11 UTC (Wed) by dlang (✭ supporter ✭, #313) [Link]

if you go back in the message thread you will see that this was in response to a post about the new library not fully supporting it yet.

LLVM gets its own C++ standard library

Posted May 12, 2010 17:30 UTC (Wed) by blitzkrieg3 (subscriber, #57873) [Link]

I think you mean the C++1x standard...

LLVM gets its own C++ standard library

Posted May 12, 2010 19:08 UTC (Wed) by HelloWorld (guest, #56129) [Link]

OH, trying to be a smart-ass, huh? So, who said that x stands for a decimal digit?

LLVM gets its own C++ standard library

Posted May 13, 2010 0:16 UTC (Thu) by kragil (guest, #34373) [Link]

OH, trying to be a smart-ass, huh? So, who said that 1 stands for a decimal digit?

LLVM gets its own C++ standard library

Posted May 13, 2010 2:18 UTC (Thu) by ccurtis (guest, #49713) [Link]

Stands for? I think it's a literal. The next version may be C++0x0a.

LLVM gets its own C++ standard library

Posted May 12, 2010 19:23 UTC (Wed) by ohmantics (guest, #66150) [Link]

One of the primary developers of libc++ is Howard Hinnant.

You may recognize his name from the C++0x effort (deep involvement in rvalue references and move semantics). You may also recognize his name as the developer of the Metrowerks Standard Library (part of CodeWarrior), so it's safe to say that he's well aware of how to accomplish that last 15% since he's done it before.

LLVM gets its own C++ standard library

Posted May 12, 2010 23:14 UTC (Wed) by jwakely (subscriber, #60262) [Link]

Howard is also the chair of the committee's Library Working Group and a first-class library writer. I expect to see a lot of enhancement requests coming to libstdc++ once users start comparing it with libc++ :)

One area I know we could do better in libstdc++ is compilation speed, which libc++ lists as a goal. I'm very pleased to see libc++ will follow the same ABI for the language support pieces of the library, so that it will (in theory) be possible to link together objects using different standard library implementations.

LLVM gets its own C++ standard library

Posted May 12, 2010 23:15 UTC (Wed) by theICEBear (subscriber, #23193) [Link]

Thank you for mentioning that. That was really useful additional information. Having a guy doing the STL library again, who has done it before must be an advantage. I mean most people here will know that the 2nd generation of an implementation is often an improvement over the last.

LLVM gets its own C++ standard library

Posted May 13, 2010 10:47 UTC (Thu) by tialaramex (subscriber, #21167) [Link]

Oooh, zing. (references to Second System Effect, in a thread about C++, a better opportunity may never come)

LLVM gets its own C++ standard library

Posted May 13, 2010 12:29 UTC (Thu) by cjayachandran (subscriber, #45677) [Link]

The same book that introduced the second system effect, has another important concept "build one to throw away". It is too early to say under which heading libc++ will come under.

MetroWerks

Posted May 13, 2010 18:38 UTC (Thu) by kolk (guest, #36699) [Link]

AFAIK MSL was an implementation of Dinkumware, along with ICC, MSVC and others. IMHO only widget toolkits and Classic platform bindings were their own.

MetroWerks

Posted May 13, 2010 22:57 UTC (Thu) by bcombee (guest, #40068) [Link]

I worked extensively on the Metrowerks Standard Library... there was considerable original implementation there. There may have been an early version based in Dinkumware, but around 1998-2000 MSL was close to 100% code developed at Metrowerks. I worked closely with Howard, as I was one of the engineers on the x86 compiler and C++ front-end, and he's a great coder and very standards-focused.

This looks like a great project.

Copyright © 2010, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds