Overview
Now that I had picked mlibc as the implementation to port, and release-5.0 as the version, it was time to start working. I forked the GitHub repository to the PincerOS organization (pincerOS/mlibc), and cloned it to my local machine.
Starting the Port
-
Following the instructions in the README, I create a new
sysdepssubdirectory,pinceros. I add an emptymeson.buildfile, and then add a new entry to the top-levelmeson.buildfile to register the new sysdep, following the pattern of the other ports.
-
Then to verify that the new sysdep was being recognized, I try to
meson buildand just see what would happen. I get errors aboutlinux_kernel_headersnot being set, and scrolling up in the terminal, it looks like it was compiling for x86-64, rather than Aarch64. I had forgotten to configure meson to build for our system!

- To fix this, I create a cross compile configuration file, and tell meson about it by running
meson setup build --cross-file aarch64-pinceros.txt.- I eventually end up moving the file to the
scriptsdirectory, and renaming it to differentiate between compilers, but more on that later.

- I eventually end up moving the file to the
-
Now, there is a new error, but at least it lists the right host machine information. The error reports a directory not existing, which I resolve by simply creating an empty directory at that location. So now
meson setupsucceeds.

- As a side tangent, I noticed a list titled “Subprojects” which listed
cshim,cxxshim, andfrigg. Out of curiosity, I looked into the Managarm GitHub and found the repos for each of them.- cshim is “a collection of freestanding C headers, for use with GCC or Clang.” It contains header files such as
stdint.h,stddef.h,stdbool.h, andstdarg.h, which define types and macros, but not functions. - cxxshim is similar, but for C++. It contains header files such as
algorithm,cstddef,cstdint,iterator,memory,new,type_traits, andutility. - frigg provides “lightweight C++ utilities and algorithms for system programming” and contains many header files, including
mutex.hpp,optional.hpp, andunique.hpp.
- cshim is “a collection of freestanding C headers, for use with GCC or Clang.” It contains header files such as
- As a side tangent, I noticed a list titled “Subprojects” which listed
-
Now that meson setup works, I try compiling with
meson compile -C build. There are lots of build errors because I have not yet created the ABI header files.
Getting mlibc to Build
-
Following the instructions in the README, I know I have to create all of the ABI header files in the
abisdirectory and create a symlink to each of them insysdeps. There are a lot of them (45), so it would be kind of painful to do manually. There is a script in thescriptsdirectory calledabi-link.sh, but all it does is create the symlinks, not the actual header files themselves. At this point in time while I’m setting up mlibc, we don’t have a very fleshed out syscall ABI in our OS, so we do not have anything to put in the header files. But I know that there were specific named constants that have to be defined in each of them for mlibc to work, so I decide to just write a new script to copy the Linux headers and generate the symlinks, atscripts/gen-abi-bits.py.
-
Now, I get compiler errors relating to invalid instruction mnemonics, so despite providing the cross compile file, there is still something wrong with it. I update the cross file to not only set the cpu, but also pass the triple target argument
--target=aarch64-none-elfinto clang usingc_argsandcpp_args.

-
But now we’re back to failing meson setup…

-
I notice in the logs that it is failing to find
ld.lld, so I try installing it. And get errors fromld.lldbeing unable to findlibclang_rt.builtins,lc, andlm. I do havecompiler-rton my Linux system for x86-64, but not for Aarch64. I search for it in the Arch Linux package repository and in the AUR, but the only results I see are for armv6 and armv7, not for armv8/aarch64.

-
At this point I fear I will have to build llvm’s
compiler-rtfrom source (which I would prefer to not have to do), so I try pivoting to gcc first and see if I can make it further than with clang. So I installaarch64-linux-gnu-gccand create a new cross compile file for it,aarch64-pinceros-gcc.txt.
-
Now compiling yields a ton of undefined reference linker errors, which is actually a good sign because it means that it was at least able to compile everything, and then just fails to link because I have not provided any implementation for the necessary functions yet.
