[cfe-dev] Stripped-down Clang/LLVM

John McCall rjmccall at apple.com
Sun Mar 3 17:11:19 PST 2013

On Mar 3, 2013, at 1:49 PM, Dmitri Gribenko <gribozavr at gmail.com> wrote:
> On Sun, Mar 3, 2013 at 11:31 PM, Daniel Kudrow <dkudrow at gmail.com> wrote:
>> Hi all,
>> I'm modifying Clang and LLVM to build a compiler for a c-like
>> language. I would like to remove as much of the codebase that I am not
>> using as I can to bring down size and debugging time. I can do without
>> all of the Objective C and C++ specific elements of Clang and much of
>> the target specific code in both Clang and LLVM. Before I spend an
>> entire day hacking away at the Makefiles, has anyone done this
>> already? Are there modules that I shouldn't waste my time trying to
>> extricate from source tree?
> Unfortunately, all of them.  C, C++ and Objective-C frontends are
> implemented in Clang as a single frontend that is controlled by
> "language options" configuration struct.

Yes, we're not really designed to be pared down like this — not by targets,
not by language modes, not by dialect features, etc.

That said, if you're really focused on code size, especially "live" code size,
there are some simple source hacks you could make that would make a lot
of code trivially dead.  That might even be enough to let a linker strip a lot
of the language-specific functions away.

For example, you could hack LangOptions to define things like this:
  static const bool CPlusPlus = false;
  static const bool ObjC1 = false;

And an easy next step would be to define some explicit specializations
for getAs, e.g.
  template <> const ObjCPointerType Type::getAs<ObjCPointerType>() const {
    return 0;


More information about the cfe-dev mailing list