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

View file

@ -4,6 +4,7 @@
Python 3
https://docs.python.org/3/license.html │
*/
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Modules/cjkcodecs/cjkcodecs.h"
#include "third_party/python/Modules/cjkcodecs/mappings_cn.inc"
@ -477,3 +478,8 @@ BEGIN_CODECS_LIST
END_CODECS_LIST
I_AM_A_MODULE_FOR(cn)
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__codecs_cn = {
"_codecs_cn",
PyInit__codecs_cn,
};

View file

@ -5,6 +5,7 @@
https://docs.python.org/3/license.html │
*/
#define USING_IMPORTED_MAPS
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Modules/cjkcodecs/cjkcodecs.h"
#include "third_party/python/Modules/cjkcodecs/mappings_hk.inc"
@ -202,3 +203,8 @@ BEGIN_CODECS_LIST
END_CODECS_LIST
I_AM_A_MODULE_FOR(hk)
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__codecs_hk = {
"_codecs_hk",
PyInit__codecs_hk,
};

View file

@ -22,6 +22,7 @@
#include "third_party/python/Modules/cjkcodecs/emu_jisx0213_2000.inc"
#include "third_party/python/Modules/cjkcodecs/cjkcodecs.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Modules/cjkcodecs/mappings_jisx0213_pair.inc"
PYTHON_PROVIDE("_codecs_iso2022");
@ -1153,3 +1154,8 @@ BEGIN_CODECS_LIST
END_CODECS_LIST
I_AM_A_MODULE_FOR(iso2022)
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__codecs_iso2022 = {
"_codecs_iso2022",
PyInit__codecs_iso2022,
};

View file

@ -19,6 +19,7 @@
#include "third_party/python/Modules/cjkcodecs/mappings_jisx0213_pair.inc"
#include "third_party/python/Modules/cjkcodecs/alg_jisx0201.inc"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Modules/cjkcodecs/emu_jisx0213_2000.inc"
PYTHON_PROVIDE("_codecs_jp");
@ -780,3 +781,8 @@ BEGIN_CODECS_LIST
END_CODECS_LIST
I_AM_A_MODULE_FOR(jp)
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__codecs_jp = {
"_codecs_jp",
PyInit__codecs_jp,
};

View file

@ -14,6 +14,7 @@
#include "third_party/python/Modules/cjkcodecs/cjkcodecs.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Modules/cjkcodecs/mappings_kr.inc"
PYTHON_PROVIDE("_codecs_kr");
@ -481,3 +482,8 @@ BEGIN_CODECS_LIST
END_CODECS_LIST
I_AM_A_MODULE_FOR(kr)
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__codecs_kr = {
"_codecs_kr",
PyInit__codecs_kr,
};

View file

@ -7,6 +7,7 @@
#include "third_party/python/Modules/cjkcodecs/cjkcodecs.h"
#include "third_party/python/Include/yoink.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Modules/cjkcodecs/mappings_tw.inc"
PYTHON_PROVIDE("_codecs_tw");
@ -148,3 +149,8 @@ BEGIN_CODECS_LIST
END_CODECS_LIST
I_AM_A_MODULE_FOR(tw)
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__codecs_tw = {
"_codecs_tw",
PyInit__codecs_tw,
};

View file

@ -8,6 +8,7 @@
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/codecs.h"
#include "third_party/python/Include/descrobject.h"
#include "third_party/python/Include/import.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/objimpl.h"
@ -1952,3 +1953,8 @@ PyInit__multibytecodec(void)
}
return m;
}
_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__multibytecodec = {
"_multibytecodec",
PyInit__multibytecodec,
};