Hacker News new | ask | show | jobs
by Raphael_Amiard 4538 days ago
There are very real differences between Clang and GCC - not when you use them as a client, to compile your code in the CLI, where gcc did indeed make big improvements in the areas it was not as good as clang, and was already pretty kick ass anyway, but when you try to use them as libraries, eg. use the AST to do source transformations, or use the code generator to make a backend for a new language.

Using clang/llvm for this is a breeze. They were concieved for that from the get go. Using gcc's AST to do anything is an horrible nightmare, and you pretty much have to fork the whole gcc code base to do that anyway.

Using gcc to implement a backend for a new language is possible, but still a lot harder than doing so with LLVM, which actually has a spec for its IR, and is well documented.

Those things are not going to be easy to change because GCC wasn't designed to account those needs.

2 comments

It's not too surprising that the IR is LLVM's strength, since that was originally the sole point of the project: the Low Level Virtual Machine was a research project at the University of Illinois to produce a target-independent low-level assembly infrastructure, in particular to be able to serve as the code-gen backend for managed/VM languages (vs. the GHC/SBCL approach of the language runtime bundling its own custom codegen). C-- was another project in that space.

GCC by contrast started as a project to replace AT&T's CC, and has since grown into a project to provide a free compiler suite, but in general an AOT compiler suite, not a backend for VM-based languages (even the Java support, the now-mostly-dead gcj, was an AOT approach). Its main competitors for years were proprietary compilers like icc, Sun Studio, and IBM VisualAge, and the main focus of comparison was language feature support and optimization performance. So that produced a pretty different development focus in each case for quite some time, though they've converged more in recent years. Nowadays the LLVM project has put a lot more resources into the compiler than they used to (including AOT-compiled languages), and GCC has been cleaning up the compiler internals and producing a plugin API. But for much of the lifetime of the two projects they weren't really in the same space.

> Using gcc's AST to do anything is an horrible nightmare, and you pretty much have to fork the whole gcc code base to do that anyway.

GCC supports Plugins which allow you to access all internal structures.

> Those things are not going to be easy to change because GCC wasn't designed to account those needs.

They are working towards modularization. It will certainly not be an easy task. But I hope they accomplish that.

>They are working towards modularization. It will certainly not be an easy task. But I hope they accomplish that.

gcc-xml was already written and the gcc devs refused to merge it. Has that changed in the last year?

http://gccxml.github.io/HTML/News.html

Looks quite dead to me, and I recall reading that the author do not recommend using it anymore.

There are still commits (latest ~1 month ago) https://github.com/gccxml/gccxml/commits/master
When was that? 10 years ago?