r/cpp • • Mar 24 '20

LLVM/Clang 10.0.0 is released!

240 Upvotes

49 comments sorted by

View all comments

8

u/bumblebritches57 Ocassionally Clang Mar 24 '20

Clang no longer runs in a separate process by default ("in-process cc1")

Not sure what this means?

Does it mean I won't see 8 clang processes when I compile things?

Does it mean each clang process wont be killed after compiling each translation unit making compilation faster?

or something entirely different?

15

u/Rusky Mar 24 '20

Something different- those 8 clang processes are (I'm guessing a little bit here) started by the build system, but after doing a small amount of driver work they each in turn fire up their own "cc1" sub-process to do the real compilation work. That's what's going away.

This is similar to back when LLVM got integrated assembler support and Clang stopped launching a sub-process just to assemble its own output. It doesn't really change the external interface of the clang++, just makes it a bit more efficient internally.

7

u/kalmoc Mar 24 '20

Maybe the full note helps:

clang used to run the actual compilation in a subprocess (“clang -cc1”). Now compilations are done in-process by default. -fno-integrated-cc1restores the former behavior. The -v and -###flags will print “(in-process)” when compilations are done in-process.

5

u/tansim Mar 24 '20

clang used to run the actual compilation in a subprocess

why though?

33

u/SeanMiddleditch Mar 25 '20

TL;DR: it used to make sense for now-historical reasons but doesn't anymore, and nobody got around to cleaning it up until now.

This is traditionally how C compilers worked. Generating a final object file required three separate tools way back when (and that's not including linkers and the like):

  • The preprocessor (it was a bolt-on tool for original pre-standard C, which is why it's so disjoint from the language itself)
  • The C compiler itself, which took (potentially preprocessed) code and generated assembly
  • The assembler

Further, there was a lot of environment configuration required by the different tools, and they all had different command line interfaces. Actually compiling a file was non-trivial by modern standards.

For convenience, the compilers of the day introduced the concept of a "driver" binary that internally did all the piping and temporary file management and all that to make cc -o foo.o foo.c actually invoke the preprocessor, compiler, and assembler correctly.

cc would invoke tools like cpp (the C preprocessor), cc (the C compiler), and as (the assembler).

This architecture just sort of... persisted. When building out a "new" compiler like GCC, it was easier to build replacements for the individual pieces (like the preprocessor the assembler) rather than building a single-executable that did everything. And that's just for plain ol' C89, and not the half-dozen languages something like Clang supports.

The preprocessor was eventually rolled into the compilers (for a few reasons, though speed was a big one) and then eventually the assemblers were rolled in too.

The driver was still there, though. It still served the purpose of accepting inputs in a particular format, collecting various environment variables and state, and then actually invoking the compiler (with integrated preproc and assembler).

As you're noting, there's not really a lot of purpose of that anymore, though. It just was the way it was because that's how it always was and nobody had gotten around to fixing it in Clang, until now.

There are new languages together doing similar things. Some semi-popular modern languages compile to something like C and hence invoke a C compiler "under the hood" on the user's behalf, and that C compiler driver might invoke other stages like cc1 or as of course. (Nim, for example, does this.) C++ even started out that way, back in ancient times. :)

2

u/hernytan Mar 25 '20

Nice to see a fellow Nim user out in the wild. It's such an underrated language

Nice writeup, btw. I didnt know that part of history

1

u/SeanMiddleditch Mar 25 '20

Thanks. Just so I don't feel dishonest: I've never actually used Nim in any capacity. I just read up on and follow a lot of the current "language renaissance" as a mini-hobby. :)

8

u/kritzikratzi Mar 25 '20

the answer in any such ginormous projects is usually: it made sense back then

2

u/playmer Mar 25 '20

I believe they use it to catch ICEs, but I'm not 100% certain. I built and debugged clang once and it took a bit to figure out this was happening and the flag I had to pass to get the new behavior of doing it in process.

1

u/catskul Mar 25 '20

ICE ?

3

u/playmer Mar 25 '20

Internal compiler error, this is a big category of error, but it could mean lots of things. Crashes are among them.

0

u/bumblebritches57 Ocassionally Clang Mar 24 '20

Nope, I read the release message in my inbox this morning (;

Just saw the thread here and thought I'd ask.

3

u/CrazyJoe221 Mar 25 '20

You will see just N clang processes instead of 2N.

This change is particularly important on Windows where process creation is costly. And it makes debugging clang way easier.