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

@ -1,55 +1,14 @@
#ifndef Py_WINREPARSE_H
#define Py_WINREPARSE_H
/* clang-format off */
#ifndef COSMOPOLITAN_THIRD_PARTY_PYTHON_MODULES_WINREPARSE_H_
#define COSMOPOLITAN_THIRD_PARTY_PYTHON_MODULES_WINREPARSE_H_
#include "libc/nt/struct/reparsedatabuffer.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
#ifdef MS_WINDOWS
#include <windows.h>
#ifdef __cplusplus
extern "C" {
#endif
/* The following structure was copied from
http://msdn.microsoft.com/en-us/library/ff552012.aspx as the required
include km\ntifs.h isn't present in the Windows SDK (at least as included
with Visual Studio Express). Use unique names to avoid conflicting with
the structure as defined by Min GW. */
typedef struct {
ULONG ReparseTag;
USHORT ReparseDataLength;
USHORT Reserved;
union {
struct {
USHORT SubstituteNameOffset;
USHORT SubstituteNameLength;
USHORT PrintNameOffset;
USHORT PrintNameLength;
ULONG Flags;
WCHAR PathBuffer[1];
} SymbolicLinkReparseBuffer;
struct {
USHORT SubstituteNameOffset;
USHORT SubstituteNameLength;
USHORT PrintNameOffset;
USHORT PrintNameLength;
WCHAR PathBuffer[1];
} MountPointReparseBuffer;
struct {
UCHAR DataBuffer[1];
} GenericReparseBuffer;
};
} _Py_REPARSE_DATA_BUFFER, *_Py_PREPARSE_DATA_BUFFER;
#define _Py_REPARSE_DATA_BUFFER struct NtReparseDataBuffer
#define _Py_PREPARSE_DATA_BUFFER struct NtReparseDataBuffer*
#define _Py_REPARSE_DATA_BUFFER_HEADER_SIZE \
FIELD_OFFSET(_Py_REPARSE_DATA_BUFFER, GenericReparseBuffer)
#define _Py_MAXIMUM_REPARSE_DATA_BUFFER_SIZE ( 16 * 1024 )
offsetof(_Py_REPARSE_DATA_BUFFER, GenericReparseBuffer)
#define _Py_MAXIMUM_REPARSE_DATA_BUFFER_SIZE (16 * 1024)
#ifdef __cplusplus
}
#endif
#endif /* MS_WINDOWS */
#endif /* !Py_WINREPARSE_H */
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_THIRD_PARTY_PYTHON_MODULES_WINREPARSE_H_ */