I'm working with the LTTng (Linux Tracing) team and we came across a problem with our user-space tracer and Python default behaviour. We provide a libc wrapper that instrument free() and malloc() and is usable with a simple LD_PRELOAD. This lib *was* named "liblttng-ust-libc.so" and we came across python software registering to our trace registry daemon (meaning that somehow the python binary is using our in-process library). We dig a bit and found this: Lib/ctypes/utils.py: def _findLib_ldconfig(name): # XXX assuming GLIBC's ldconfig (with option -p) expr = r'/[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name) res = re.search(expr, os.popen('/sbin/ldconfig -p 2>/dev/null').read()) and, at least, also found in _findLib_gcc(name) and _findSoname_ldconfig(name). This cause Python to use any library ending with "libc.so" to be loaded.... I don't know the reasons behind this but we are concerned about "future issues" with this kind of behaviour. Thanks
'find_library' itself actually loads no libraries. I suspect what happened was that the following code in the 'uuid' module coupled with the 'find_library' bug caused 'liblttng-ust-libc.so' to be loaded: for libname in ['uuid', 'c']: try: lib = ctypes.CDLL(ctypes.util.find_library(libname)) except: continue if hasattr(lib, 'uuid_generate_random'): _uuid_generate_random = lib.uuid_generate_random if hasattr(lib, 'uuid_generate_time'): _uuid_generate_time = lib.uuid_generate_time This issue was fixed in 3.3 as a part of the optimization done in . I can still reproduce the problem in 2.7 and 3.2. I am just going to backport the 3.3 regex to 2.7 and 3.2. This is not an issue for the '_findLib_gcc' regex because the GCC output has a different format. '_findLib_ldconfig' is never actually called so I removed it. Patch attached.