indygreg / python-build-standalone

Produce redistributable builds of Python
BSD 3-Clause "New" or "Revised" License
1.71k stars 107 forks source link

What is libpython3.so for? #168

Closed lijunsong closed 11 months ago

lijunsong commented 1 year ago

We want to create a slim python package (remove all unnecessary Build, man pages, test modules, etc.), so we're considering to delete it. Suggestions?

total 37M
drwxr-xr-x  4 user user 4.0K Apr 19 03:16 Tix8.4.3
drwxr-xr-x  2 user user 4.0K Apr 19 03:16 itcl4.2.2
lrwxrwxrwx  1 user user   20 Jan  1  2021 libpython3.10.so -> libpython3.10.so.1.0
-rwxr-xr-x  1 user user  37M Jan  1  2021 libpython3.10.so.1.0
-rwxr-xr-x  1 user user  17K Jan  1  2021 libpython3.so <-------------------------------- this 17K shared library

It's unclear what this install/lib/libpython3.so is and how import are those by inspecting it's symbol table:

SYMBOL TABLE:
0000000000000000 l    df *ABS*  0000000000000000              crtstuff.c
0000000000001040 l     F .text  0000000000000000              deregister_tm_clones
0000000000001070 l     F .text  0000000000000000              register_tm_clones
00000000000010b0 l     F .text  0000000000000000              __do_global_dtors_aux
0000000000004008 l     O .bss   0000000000000001              completed.0
0000000000003df0 l     O .fini_array    0000000000000000              __do_global_dtors_aux_fini_array_entry
00000000000010f0 l     F .text  0000000000000000              frame_dummy
0000000000003de8 l     O .init_array    0000000000000000              __frame_dummy_init_array_entry
0000000000000000 l    df *ABS*  0000000000000000              crtstuff.c
0000000000002000 l     O .eh_frame      0000000000000000              __FRAME_END__
0000000000000000 l    df *ABS*  0000000000000000              
0000000000004000 l     O .data  0000000000000000              __dso_handle
0000000000003df8 l     O .dynamic       0000000000000000              _DYNAMIC
0000000000004008 l     O .data  0000000000000000              __TMC_END__
0000000000003fe8 l     O .got.plt       0000000000000000              _GLOBAL_OFFSET_TABLE_
0000000000000000  w      *UND*  0000000000000000              _ITM_deregisterTMCloneTable
00000000000010f8 g     F .fini  0000000000000000              _fini
0000000000000000  w      *UND*  0000000000000000              __gmon_start__
0000000000000000  w      *UND*  0000000000000000              _ITM_registerTMCloneTable
0000000000000000  w    F *UND*  0000000000000000              __cxa_finalize@GLIBC_2.2.5
0000000000001000 g     F .init  0000000000000000              _init
indygreg commented 1 year ago

libpython3 exists to (re)export the stable subset of the Python API. See https://peps.python.org/pep-0652/.

Applications coding against the stable Python API may link against python3 instead of python3.x.

The library is in our distributions because it is part of standard Python distributions and some consumers expect it to exist.

If your application doesn't use the library, then it can be safely deleted.

I want to say that Python extension modules shouldn't be linking against libpython3 - only binaries wanting to link against Python. But stranger things have happened. If your application allows loading custom extension modules, you may want to keep libpython3 around just in case.

Does this answer your question? If so, feel free to close this issue.