@@ -71,8 +71,6 @@ const ELF_ALLOWED_LIBRARIES: &[&str] = &[
7171 "libpthread.so.0" ,
7272 "librt.so.1" ,
7373 "libutil.so.1" ,
74- // musl libc
75- "libc.so" ,
7674] ;
7775
7876const PE_ALLOWED_LIBRARIES : & [ & str ] = & [
@@ -920,26 +918,37 @@ fn validate_elf<Elf: FileHeader<Endian = Endianness>>(
920918 allowed_libraries. extend ( extra. iter ( ) . map ( |x| x. to_string ( ) ) ) ;
921919 }
922920
923- allowed_libraries. push ( format ! ( "libpython{}.so.1.0" , python_major_minor) ) ;
924- allowed_libraries. push ( format ! (
925- "$ORIGIN/../lib/libpython{}d.so.1.0" ,
926- python_major_minor
927- ) ) ;
928- allowed_libraries. push ( format ! (
929- "$ORIGIN/../lib/libpython{}t.so.1.0" ,
930- python_major_minor
931- ) ) ;
932- allowed_libraries. push ( format ! (
933- "$ORIGIN/../lib/libpython{}td.so.1.0" ,
934- python_major_minor
935- ) ) ;
936-
937- // On musl, we don't use `$ORIGIN`
938- if target_triple. contains ( "-musl" ) {
939- allowed_libraries. push ( format ! ( "libpython{}.so.1.0" , python_major_minor) ) ;
940- allowed_libraries. push ( format ! ( "libpython{}d.so.1.0" , python_major_minor) ) ;
941- allowed_libraries. push ( format ! ( "libpython{}t.so.1.0" , python_major_minor) ) ;
942- allowed_libraries. push ( format ! ( "libpython{}td.so.1.0" , python_major_minor) ) ;
921+ if json. libpython_link_mode == "shared" {
922+ if target_triple. contains ( "-musl" ) {
923+ // On musl, we link to `libpython` and rely on `RUN PATH`
924+ allowed_libraries. push ( format ! ( "libpython{}.so.1.0" , python_major_minor) ) ;
925+ allowed_libraries. push ( format ! ( "libpython{}d.so.1.0" , python_major_minor) ) ;
926+ allowed_libraries. push ( format ! ( "libpython{}t.so.1.0" , python_major_minor) ) ;
927+ allowed_libraries. push ( format ! ( "libpython{}td.so.1.0" , python_major_minor) ) ;
928+ } else {
929+ // On glibc, we can use `$ORIGIN` for relative, reloctable linking
930+ allowed_libraries. push ( format ! (
931+ "$ORIGIN/../lib/libpython{}.so.1.0" ,
932+ python_major_minor
933+ ) ) ;
934+ allowed_libraries. push ( format ! (
935+ "$ORIGIN/../lib/libpython{}d.so.1.0" ,
936+ python_major_minor
937+ ) ) ;
938+ allowed_libraries. push ( format ! (
939+ "$ORIGIN/../lib/libpython{}t.so.1.0" ,
940+ python_major_minor
941+ ) ) ;
942+ allowed_libraries. push ( format ! (
943+ "$ORIGIN/../lib/libpython{}td.so.1.0" ,
944+ python_major_minor
945+ ) ) ;
946+ }
947+ }
948+
949+ if !json. build_options . contains ( "static" ) && target_triple. contains ( "-musl" ) {
950+ // Allow linking musl `libc`
951+ allowed_libraries. push ( "libc.so" . to_string ( ) ) ;
943952 }
944953
945954 // Allow the _crypt extension module - and only it - to link against libcrypt,
0 commit comments