Not that easy. That's why I recommended to fork musl and tailor it's interface to your needs. There are functions which are required by the C standard. Some compilers, like gcc can provide built-ins for those, others, like Clang demand a user-space implementation.mmdmine wrote:This was what I want to hear. I dont need to have a library same as glibc and others e.g. I can have memory_allocate() instead of malloc() or have a different string library. only problem is that it's not compatible with existing softwares that's not my goal,
Not really. With your final kernel, you'll have to provide your own C Library which looks like any other C Library from above, but uses your kernel interface under the hood (or alternatively you could use the same kernel API as Linux does, and then you could allow the user to freely choose musl / glibc etc.) Only libcs with exactly the same kernel interface are interchangable.mmdmine wrote:instead I can allow user to have a 3rd party C Library to install these softwarrs.
The idea behind libc is to provide a standardized interface to user-space programs so that they don't have to worry about the actual kernel interface. Printf() is printf() for applications, regardless if the underlying kernel interface uses int 0x80 or syscall, or if console is implemented as a pipe write or something else. For example, you can't use musl with a vanilla BSD kernel either, because it's kernel interface differs to Linux's (however an installable compatibility layer exists). Of course, libc also has many low-level routines that doesn't use the kernel, but are extremely useful, like qsort or strlen for example (those are the easiest to port). You could choose not to implement those in your libc, but then writing applications for your user-space would be problematic.
So to summarize, there are three kinds of functions in a libc:
1. required by the C standard (like memset or the C runtime _start)
2. ones that hide the kernel interface behind a standardized API (like printf, malloc)
3. convenient and useful functions (like bsearch or atoi)
You can't avoid 1., you must implement those without modifying their API (except if you can add a new ABI to the compilers or if you compile ALL user-space applications in freestanding mode, not a good idea).
You might redefine 2., but you'll be still tied to a specific kernel interface implementation with those. But certainly doable, Windows for example does not have opendir() but has FindFirstFileA() / FindNextFileA().
You can omit 3., but life is going to be miserable without those (but feel free to avoid or redefine those).
NOTE: for the functions in 2. I deliberately used the phrase "standardized API" and not "POSIX", because it could be another standard as well. Windows has it's own standard for example, calling malloc MemAlloc. EFI for example has another, where memcmp is called CompareMem. Except for the functions defined by the C standard, your OS (or Linux user space) may define it's own standard.
Cheers,
bzt