-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Linux ABI Compatibility? #7
Comments
Focusing on high-level API calls, but ignoring things like dynamic linking, ELF, and internal-implementation-specific things (e.g. the execution flow, behind the system function calls), to run something like uname (PPC64/Fedora 28), we'd need to implement:
This wouldn't be impossible (Linux has an Open Source implementation, and I implemented a version of uname(), in Enryo, for instance), but it'd only be enough to run one command binary (uname), as a proof of concept... |
For a first run of "gcc -static hello.c", without following forks:
|
For what it's worth, it could be useful to implement the interfaces at https://github.com/NickStrupat/CacheLineSize/blob/master/CacheLineSize.c, for getting the size of the system cache lines, if this gets off the ground. |
Some of these, we can port from FreeBSD (https://github.com/freebsd/freebsd/tree/a4c47e1ddee5bbf6407a4c01a0274ed274a9beda/lib/libc/stdio) |
The stuff from the liblinux branch is now in master, and propagated into most of the other working branches, since it doesn't break anything. |
Since the userland kinda compiles, on x86-64, at the moment (still have to fix the kernel), with GCC6, I started trying to port some things (the Sony Clefia reference source compiles, and links, if I dump it in with /user/apps/system/, and add it to the Makefile), and investigated trying to plug in nedmalloc. Right now, in master, we have a
The L4-specific files were already present. Trying to build nedmalloc gets as far as this, right now:
|
Filtering the warnings, we don't implement the following, yet:
|
Imported FreeBSD version of errno.h, and created a stub version of sys/cdefs.h. On both Linux, and FreeBSD, |
This gets us to:
|
After importing the FreeBSD version of sys/cdefs.h, we now get to:
|
This apparently gets inherited from sys/cdefs.h, according to https://www.freebsd.org/cgi/man.cgi?query=errno&sektion=2&manpath=freebsd-release-ports |
Imported https://raw.githubusercontent.com/freebsd/freebsd/master/sys/sys/fcntl.h, and created a stub sys/_types.h, which gets us to:
We want to do things properly, so there's still more to do... |
https://jameshfisher.com/2017/02/24/what-is-mode_t/ has info on mode_t |
Importing https://raw.githubusercontent.com/freebsd/freebsd/master/sys/sys/_types.h, and a dummy machine/_types.h gets us to:
|
We need to carefully alias the L4 types, to the FreeBSD types, according to https://svnweb.freebsd.org/base?view=revision&revision=232261, and the bug at https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=186247, rather than just pasting in anything, to make it compile... On top of the integer types, a bunch of other typedefs for POSIX are also made, and we need to take account for little-endian, and big-endian PPC |
After wiring up more headers, and types:
|
After shadowing the __uint_least16_t, __uint_least32_t, and __uintmax_t, we get:
|
Right now, we don't copy everything from https://svnweb.freebsd.org/base/head/sys/amd64/include/_types.h?r1=232261&r2=232260&pathrev=232261 |
On FreeBSD, the mmap syscall is expressed in https://github.com/freebsd/freebsd/blob/master/sys/vm/vm_mmap.c, and https://github.com/freebsd/freebsd/blob/master/sys/sys/mman.h |
Importing https://raw.githubusercontent.com/freebsd/freebsd/master/sys/sys/mman.h, we get down to:
|
Importing https://raw.githubusercontent.com/freebsd/freebsd/master/include/stdio.h, we get to:
|
Testing with CacheLineSize:
We imported https://raw.githubusercontent.com/freebsd/freebsd/master/lib/libc/stdio/fopen.c |
Need to pull in https://raw.githubusercontent.com/lattera/freebsd/master/lib/libc/include/un-namespace.h, and https://raw.githubusercontent.com/lattera/freebsd/master/lib/libc/include/namespace.h, add a dummy sys/stat.h, local.h, and limits.h, and we receive:
|
Need a dummy sys/_timespec.h, and https://raw.githubusercontent.com/freebsd/freebsd/master/sys/sys/stat.h, to get
|
With https://raw.githubusercontent.com/freebsd/freebsd/master/include/time.h, we get
|
Pulled in https://raw.githubusercontent.com/freebsd/freebsd/master/sys/sys/stdint.h, fopen, fread, tempnam |
Implemented a workaround, for max/min short defines, and get
|
https://github.com/freebsd/freebsd/blob/master/lib/libc/sys/read.c does kernel-specific stuff |
An alternative implementation can be found in https://android.googlesource.com/platform/bionic/+/c8bae05/libc/stdio/stdio.c |
After importing a few more files from Bionic, temporarily, we get to :
|
Import https://raw.githubusercontent.com/freebsd/freebsd/master/sys/sys/timespec.h, to get past :
|
|
https://github.com/freebsd/freebsd/blob/af881ec390ca378ac573d58251e8626623a6d1ed/sys/x86/include/_types.h says that __clock_t can have at least 2 definitions, depending on architecture |
Now we get to:
|
Now we get to
|
Current status is
|
Now at
|
For CacheLineSize:
|
Rebuilding on PowerPC, we have some issues, now:
|
Looking at this:
We have https://github.com/vmlemon/Orion/blob/a88c786cbcc94f1e76a18fb812f1aff21968713e/user/include/l4/powerpc/specials.h, for 32-bit PowerPC, which uses the
Looking at https://github.com/vmlemon/Orion/blob/a88c786cbcc94f1e76a18fb812f1aff21968713e/user/include/l4/powerpc64/specials.h, we don't have __L4_Lsb, but we do have __L4_Msb:
The cntlzd operates on double-words, and the documentation has the following disclaimer:
The question is - what do we do, on 64-bit PPC, and little-endian POWER, if we're running a 32-bit application?
We need to find a better way, that doesn't potentially corrupt memory, but for now, we just override it, using a #define, which gets us to:
|
Missing API surface, for MojoELF/CacheLineSize:
|
https://openpowerfoundation.org/wp-content/uploads/2016/03/ABI64BitOpenPOWERv1.1_16July2015_pub4.pdf has information on the new OpenPOWER ELF V2 ABI . |
https://0xax.gitbooks.io/linux-insides/content/SysCall/linux-syscall-2.html documents the call despatch process |
Added some more |
Although we're a long way off having a buildable, usable system, it could be useful for us to implement compatibility with the Linux ABI (similar to FreeBSD/NetBSD, LynxOS, and Windows Subsystem for Linux), so that we can run PowerPC, and x86 Linux binaries, like the old kernel toolchain, to avoid having to maintain public VMs of ancient Linux versions, just so that we can rebuild our own kernel, and userland.
In the liblinux branch, I started reverse-engineering the system calls made by a few dynamically-linked binaries (git, ls, and gcc), to see what kind of functionality we'd need to provide, and dropped in a stub version of sys/vfs.h, with a shell for statfs().
Since we need to implement a VFS layer, anyway, it would make sense to have some level of UNIX/Linux/POSIX compatibility, for this project.
The text was updated successfully, but these errors were encountered: