Creating a C Library: Difference between revisions

m
Add links to libgcc article
[unchecked revision][unchecked revision]
m (Fix the null rip pointer not being in the first stack frame linked list entry.)
m (Add links to libgcc article)
Line 2:
 
= Building =
Now that you have an OS-specific freestanding toolchain that can build your kernel, there is a problem of bootstrapping. To build a OS-specific toolchain that supports a hosted environment, you need the headers of your standard C library installed. To build your libc you need a compiler that supports a hosted environment (building a user-space libc as in a freestanding environment is a logical mistake). The solution is to create a make target that installs your C library and kernel headers into your sysroot's include directory without needing a compiler. Then you can simply build your cross-compiler with --with-sysroot="$SYSROOT" (and not giving the --without-headers option), and you should get a cross-compiler that offers a freestanding environmment for your kernel, and a hosted environment for your user-space. Note that [[libgcc]] may depend on a few things from your C library: if you get errors during building libgcc, then simply add the declarations to your header files. You will get undeclared symbols if GCC deems it appropriate to call a libgcc function that needs a libc symbol, so it is a good idea to implement what libgcc needs early on. Note that [[libgcc]] is <em>not</em> optional, and gcc <em>will</em> emit calls to it if it thinks it is a good idea.
 
Then you can simply build your C library source files using:
Anonymous user