Introduce dlopen() support

Every program built using Cosmopolitan is statically-linked. However
there are some cases, e.g. GUIs and video drivers, where linking the
host platform libraries is desirable. So what we do in such cases is
launch a stub executable using the host platform's libc, and longjmp
back into this executable. The stub executable passes back to us the
platform-specific dlopen() implementation, which we shall then wrap.

Here's the list of platforms that are supported so far:

- x86-64 Linux w/ Glibc
- x86-64 Linux w/ Musl Libc
- x86-64 FreeBSD
- x86-64 Windows
- aarch64 Linux w/ Glibc
- aarch64 MacOS

What this means is your Cosmo programs can call foreign functions on
your host operating system. However, it's important to note that any
foreign library you link won't have the ability to call functions in
your Cosmopolitan program. For example it's now technically possible
that Lua can load a module, however that almost certainly won't work
since the Lua module won't have access to Cosmo's Lua API.

Kudos to @jacereda for figuring out how to do this.
This commit is contained in:
Justine Tunney 2023-11-03 06:04:13 -07:00
parent 1eb6484c9c
commit 5e8c928f1a
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
27 changed files with 753 additions and 53 deletions

View file

@ -7,7 +7,7 @@
#include "third_party/python/Include/pystate.h"
#include "libc/errno.h"
#include "libc/intrin/pushpop.internal.h"
#include "libc/runtime/dlfcn.h"
#include "libc/dlopen/dlfcn.h"
#include "third_party/python/Include/ceval.h"
#include "third_party/python/Include/dictobject.h"
#include "third_party/python/Include/listobject.h"