A homebrew standard C
library for the userland of LensorOS.
To build the LensorOS Standard C
Library (really needs a
name), the LensorOS toolchain needs to be built already.
For further instructions, see the toolchain README.
NOTE: This step does not need to be completed, as these binaries are provided pre-built with the repository.
For startup and destruction of programs in the standard C
library, a few different libraries are utilized:
- crt0.o
- crti.o
- crtn.o
Use the freestanding LensorOS toolchain compiler to generate object files from the corresponding assembly files:
x86_64-lensor-gcc -c /Path/to/LensorOS/user/libc/crt0.s
x86_64-lensor-gcc -c /Path/to/LensorOS/user/libc/crti.s
x86_64-lensor-gcc -c /Path/to/LensorOS/user/libc/crtn.s
Once the object files have been generated, copy them into the
system libraries directory within the sysroot (/lib
).
Alternatively, one could use the -o
option to specify the correct output path.
Generate a build system using CMake, then invoke it:
cd /Path/to/LensorOS/user/libc/
cmake -S . -B bld
cmake --build bld
This will generate a libc.a
library file that may be stored in the
system library directory within the sysroot (/lib
).
From here, if a program is built that links to the standard C
library,
it will link to the LensorOS implementation, allowing the
generated executable to be run from LensorOS in userland.
To rebuild the C Library for LensorOS, there are multiple steps required:
-
Build the C Library
Follow the instructions above.
-
Copy built library,
libc.a
, intobase/lib/
subdirectory of repository. -
Run sysroot creation script at
scripts/sysroot.sh
to rebuild system root. -
Re-compile any and all userspace programs to be able to link with new libc.