@@ -996,6 +996,10 @@ def _find_libraries_with_dl_iterate_phdr(self):
996996 """
997997 libc = self ._get_libc ()
998998 if not hasattr (libc , "dl_iterate_phdr" ): # pragma: no cover
999+ warnings .warn (
1000+ "Could not find dl_iterate_phdr in the C standard library." ,
1001+ RuntimeWarning ,
1002+ )
9991003 return []
10001004
10011005 # Callback function for `dl_iterate_phdr` which is called for every
@@ -1028,6 +1032,10 @@ def _find_libraries_with_dyld(self):
10281032 """
10291033 libc = self ._get_libc ()
10301034 if not hasattr (libc , "_dyld_image_count" ): # pragma: no cover
1035+ warnings .warn (
1036+ "Could not find _dyld_image_count in the C standard library." ,
1037+ RuntimeWarning ,
1038+ )
10311039 return []
10321040
10331041 n_dyld = libc ._dyld_image_count ()
@@ -1219,16 +1227,13 @@ def _get_libc(cls):
12191227 """Load the lib-C for unix systems."""
12201228 libc = cls ._system_libraries .get ("libc" )
12211229 if libc is None :
1222- libc_name = find_library ("c" )
1223- if libc_name is None : # pragma: no cover
1224- warnings .warn (
1225- "libc not found. The ctypes module in Python"
1226- f" { sys .version_info .major } .{ sys .version_info .minor } is maybe"
1227- " too old for this OS." ,
1228- RuntimeWarning ,
1229- )
1230- return None
1231- libc = ctypes .CDLL (libc_name , mode = _RTLD_NOLOAD )
1230+ # Remark: If libc is statically linked or if Python is linked against an
1231+ # alternative implementation of libc like musl, find_library will return
1232+ # None and CDLL will load the main program itself which should contain the
1233+ # libc symbols. We still name it libc for convenience.
1234+ # If the main program does not contain the libc symbols, it's ok because
1235+ # we check their presence later anyway.
1236+ libc = ctypes .CDLL (find_library ("c" ), mode = _RTLD_NOLOAD )
12321237 cls ._system_libraries ["libc" ] = libc
12331238 return libc
12341239
0 commit comments