Reputation: 15
Say I have a C compiler written in C. That C compiler would then be compiled using an earlier version of that compiler or by itself (by first compiling the source with an older version and then again with the new compiler assume).
What if the implementation of that C compiler would have a bug in it? That would mean the C compiler produces binaries that are possibly incorrect. If I were to fix the bug that code would still have to be compiled using the bugged version of the compiler, again resulting in a compiler that possibly does not behave correctly.
If the bug was caught right away I can see how to deal with this by just using an older version o the compiler. But what if the bug goes undetected for a number of iterations? It seems to me almost impossible to track down the source of the bug at that point as the incorrect behavior could possibly be a result from any of the previous version of that compiler that has propagated through the various iterations.
Upvotes: 1
Views: 189
Reputation: 13171
"Language" is an abstract concept; a compiler is a specific, real, running program that implements the language. A compiler might well be written in the same language it compiles, but it is compiled by a specific version of a specific implementation of that language, so dealing with bugs is specific to that implementation.
It might be compiled with an implementation of the language from some other source, or from an earlier version of itself, or a limited version of itself, for example. It's quite possible for the code to contain workarounds for bugs in that other compiler. But again, such bugs exist in specific implementations, not in the abstract language, and they are dealt with the same way you would deal with compiler bugs in any other program.
Upvotes: 0
Reputation: 780724
Theere are several possibilities:
If there are other implementations of the compiler, you can use one of them to recompile your compiler. Most languages have multiple implementations, so this is often an option.
If you know what triggers the buggy behavior, look for the triggering code in your source code, and rewrite it. If this is suboptimal code, you only have to do it temporarily: compile this altered version, then compile the original version with the (now non-buggy) compiler.
Monkey-patch the compiler to "fix" the bug, then recompile. Or do this by hand in the debugger if the buggy situation doesn't arise too many times while compiling.
BTW, your concern is not dissimilar to a more insidious (theoretical) problem that was described by Ken Thompson in his Turing Award lecture, Reflections on Trusting Trust. He described a situation where the compiler has intentional code that detects when it's compiling the OS and inserts security vulnerabilities; it also detects when it's recompiling the compiler, and inserts the detection code.
Upvotes: 4