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

@ -17,6 +17,7 @@
*/
#include "libc/mem/mem.h"
#include "libc/stdio/stdio.h"
#include "libc/str/blake2.h"
#include "third_party/mbedtls/common.h"
#include "third_party/mbedtls/error.h"
#include "third_party/mbedtls/md.h"
@ -69,6 +70,7 @@ asm(".include \"libc/disclaimer.inc\"");
* Reminder: update profiles in x509_crt.c when adding a new hash!
*/
static const uint8_t supported_digests[] = {
MBEDTLS_MD_BLAKE2B256,
#if defined(MBEDTLS_SHA512_C)
MBEDTLS_MD_SHA512,
#if !defined(MBEDTLS_SHA512_NO_SHA384)
@ -154,6 +156,8 @@ const mbedtls_md_info_t *mbedtls_md_info_from_string( const char *md_name )
if( !strcasecmp( "SHA512", md_name ) )
return mbedtls_md_info_from_type( MBEDTLS_MD_SHA512 );
#endif
if( !strcasecmp( "BLAKE2B256", md_name ) )
return mbedtls_md_info_from_type( MBEDTLS_MD_BLAKE2B256 );
return( NULL );
}
@ -200,6 +204,8 @@ const mbedtls_md_info_t *mbedtls_md_info_from_type( mbedtls_md_type_t md_type )
case MBEDTLS_MD_SHA512:
return( &mbedtls_sha512_info );
#endif
case MBEDTLS_MD_BLAKE2B256:
return( &mbedtls_blake2b256_info );
default:
return( NULL );
}
@ -237,6 +243,8 @@ static int16_t GetMdContextSize(mbedtls_md_type_t t)
case MBEDTLS_MD_SHA512:
return sizeof(mbedtls_sha512_context);
#endif
case MBEDTLS_MD_BLAKE2B256:
return sizeof(struct Blake2b);
default:
return( MBEDTLS_ERR_MD_BAD_INPUT_DATA );
}