On Wed, 21 Apr 2021, 08:04 Tadeus Prastowo wrote: > On Wed, Apr 21, 2021 at 6:33 AM Peng Yu <pengyu.ut@xxxxxxxxx> wrote: > > > > > > Since it is *link*-time optimization, I suppose it is ld who does the > > actual work? > > Yes. > Well, sort of. The linker uses a plug-in to invoke the compiler again. The linker doesn't do the optimization itself, because it doesn't know how. So the gcc driver runs collect2 which runs ld which uses the lto-plugin.so to run the compiler again, then ld finishes linking. The optimization happens *during* linking, but it's still done by the compiler. > > If it were implemented in a shell language, it would be easier to see > > what is going on below the surface, instead of relying on the -v > > option. > > Yes. > > > (Probably it is easier to maintain shell scripts rather than C > > code? Also, just for calling others programs, it seems shell is a > > better implementation language than C.) > > Maybe. > That's debatable. The gcc driver is quite complex and would be a very large, complex shell script. It would not be easy to maintain. Writing it in C allows code to be shared with other parts of GCC (e.g. for command-line option processing). It also allows it to work on machines without a good shell.