[cfe-dev] Why clang needs to fork into itself?
devlists at shadowlab.org
Mon Jan 27 16:37:35 PST 2014
Le 27 janv. 2014 à 21:02, Yuri <yuri at rawbw.com> a écrit :
> I noticed that even the simple command 'clang -c -emit-llvm c.cpp' calls fork, and forks into itself.
> Why does it need to do this? This would potentially complicate profiling, debugging, etc. All tools should be fork-aware.
> Also unnecessary operation must cause some performance hit.
> It is understandable when compiler would, for example, fork into an external macro preprocessor, or assembler, or linker, but why into itself?
If you want to debug/profile clang, you can invoke it directly with the -cc1 flag, and passing the right arguments.
To get the full command line used to invoke the real compilation process, you can use the -### argument:
clang -### -c -emit-llvm c.cpp
For the record, in the early days, the clang driver was a separate binary that used to invoke the compiler (which was called ccc IIRC).
Some time ago, the driver and the compiler were merged into a single clang binary, but it continue to work the same way it used to do. That explains why it executes itself.
> I don't see your point with catching compiler errors and crashes. Isn't this the caller responsibility?
The caller can't give as much information about the crash than the driver does.
The driver is able to generate a preprocessed file, and a shell script to reproduce the clang invocation that crashed, and it also logs a message to tell the user how to report the bug.
Moreover, you can't expect that all callers do that, and it is very helpful to get proper bug report when the compilation process crashes.
More information about the cfe-dev