Decentralize Python native module linkage

We can now link even smaller Python binaries. For example, the hello.com
program in the Python build directory is a compiled linked executable of
hello.py which just prints hello world. Using decentralized sections, we
can make that binary 1.9mb in size (noting that python.com is 6.3 megs!)

This works for nontrivial programs too. For example, say we want an APE
binary that's equivalent to python.com -m http.server. Our makefile now
builds such a binary using the new launcher and it's only 3.2mb in size
since Python sources get turned into ELF objects, which tell our linker
that we need things like native hashing algorithm code.
This commit is contained in:
Justine Tunney 2021-09-07 11:40:11 -07:00
parent dfa0359b50
commit 559b024e1d
129 changed files with 2798 additions and 13514 deletions

15
third_party/python/Lib/launchpy.py vendored Normal file
View file

@ -0,0 +1,15 @@
import sys
from importlib import _bootstrap_external
def run_module_as_main(mod_name):
path = "/zip/.python/%s.pyc" % (mod_name.replace(".", "/"))
loader = _bootstrap_external.SourcelessFileLoader(mod_name, path)
code = loader.get_code(mod_name)
globs = sys.modules["__main__"].__dict__
globs["__name__"] = "__main__"
globs["__file__"] = path
globs["__package__"] = None
globs["__loader__"] = loader
globs["__spec__"] = None
exec(code, globs)
return globs