Re: Compiler bootstrapping and the standard header files

Christopher F Clark <christopher.f.clark@compiler-resources.com>
Sun, 22 Mar 2020 13:51:55 -0400

          From comp.compilers

Related articles
Compiler bootstrapping and the standard header files codevisio@gmail.com (2020-03-19)
Re: Compiler bootstrapping and the standard header files DrDiettrich1@netscape.net (Hans-Peter Diettrich) (2020-03-20)
Re: Compiler bootstrapping and the standard header files auriocus@gmx.de (Christian Gollwitzer) (2020-03-20)
Re: Compiler bootstrapping and the standard header files christopher.f.clark@compiler-resources.com (Christopher F Clark) (2020-03-20)
Re: Compiler bootstrapping and the standard header files codevisio@gmail.com (cvo) (2020-03-20)
Re: Compiler bootstrapping and the standard header files gah4@u.washington.edu (2020-03-21)
Re: Compiler bootstrapping and the standard header files DrDiettrich1@netscape.net (Hans-Peter Diettrich) (2020-03-22)
Re: Compiler bootstrapping and the standard header files christopher.f.clark@compiler-resources.com (Christopher F Clark) (2020-03-22)
Re: Compiler bootstrapping and the standard header files 493-878-3164@kylheku.com (Kaz Kylheku) (2020-03-23)
| List of all articles for this month |

From: Christopher F Clark <christopher.f.clark@compiler-resources.com>
Newsgroups: comp.compilers
Date: Sun, 22 Mar 2020 13:51:55 -0400
Organization: Compilers Central
References: 20-03-018 20-03-019 20-03-021 20-03-023
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="43345"; mail-complaints-to="abuse@iecc.com"
Keywords: code, design, comment
Posted-Date: 22 Mar 2020 19:39:58 EDT

cvo asked:


Your assumptions up to this one seemed correct to me.


                  If so the the final and my first question is:
                        Given a gcc in a linux environment with its C headers and
                        with its C libraries, and given my compiler with its C headers
                        and with its C libraries, as long as my C headers and C libraries
                        conform semantically to the C standard, why cannot I use them
                        in the first step, point (1), in place of host ones?


If you header and libraries are written in standard C, and the
original compiler works properly when you use them with it. You can
use your headers and libraries in step 1. It won't change the number
of steps, but that's a different question, which you didn't ask.


But listen carefully, to John, our moderators, comments and consider
not writing your own library when writing your own compiler. I can
probably count on one hand with fingers left over the number of times
he's been wrong in the years I've been reading here. More importantly.
Don't make unnecessary work for yourself. Writing a compiler is
plenty to do. Adding more work on that pile, just means you won't do
as good a job on it as you would if you had it as your only task.


The reason you might need the host headers and libraries (supplied
with the compiler) is that they don't need to be written in standard
C. In theory (and even in practice), the standard header files (nor
the library) don't even need to exist. The compiler can use internal
versions of them when it sees the "include" preprocessor directives
and the internal versions don't even need to be C code, they just need
to make your C programs compile with the compiler (and run when
executed, so the runtime library can also be built into the code
generated by the compiler and not a separate library at all).


And, yes, I think I've seen compilers that do that. Before C, it was
common, since there were no "header files" just functions that the
language/compiler defined. We called them "built ins". For hardware
that had things line sin and cos instructions, you didn't have sin and
cos functions. On the other hand, if the hardware didn't have a
"double precision" divide instruction (which many didn't), you called
a runtime library routine for that, even though the user didn't write
it as a call, just as an expression.


In that way C was revolutionary, you were able to write large parts of
the C runtime in C. Before C, the runtime libraries were almost
always written in assembly language and didn't necessarily follow the
standard function call conventions. Burroughs (5000 series) Algol
might have been the exception as I have heard there wasn't even an
assembly language for it. Everything was written in Algol.


So if you can write the functions you need in standard C and you can
make all the parts work with header files written in standard C, yes
you can probably use your header files. I wonder how you are going to
get things like varargs and setjmp to work. That usually involves a
bit of compiler magic. That's why names starting with two underscores
are reserved, so that the compiler can use them to describe the
necessary magic.


However, I will admit that my knowledge on this topic is more than a
bit rusty. The last time I implemented a C compiler was at Honeywell,
when C was just being standardized and C++ was still new.


Just sharing my ignorance (i.e. what passes for knowledge in my mind)
and thoughts,
Chris


--
******************************************************************************
Chris Clark email: christopher.f.clark@compiler-resources.com
Compiler Resources, Inc. Web Site: http://world.std.com/~compres
23 Bailey Rd voice: (508) 435-5016
Berlin, MA 01503 USA twitter: @intel_chris
------------------------------------------------------------------------------
[For an example of library incompatibility problems, look at your
local version of setjmp.h and the source of setjmp() and longjmp().
On most systems the header file is written in standard C, but it's
also totally machine dependent because the size and contents of a
jmpbuf depends on the machine architecture and calling sequence.


For the machine independent parts of libc (most of it), take a look at
https://musl.libc.org/, an open source C library with a flexible MIT
license. -John]


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.