at master 4.0 kB view raw
1From 66f492d2eda94bd64db833839a325caf6ba0fed5 Mon Sep 17 00:00:00 2001 2From: Greg Roodt <greg@canva.com> 3Date: Wed, 9 Dec 2020 17:59:24 +1100 4Subject: [PATCH] Don't use ldconfig 5 6--- 7 Lib/ctypes/util.py | 77 ++-------------------------------------------- 8 1 file changed, 2 insertions(+), 75 deletions(-) 9 10diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py 11index 0c2510e161..7fb98af308 100644 12--- a/Lib/ctypes/util.py 13+++ b/Lib/ctypes/util.py 14@@ -100,53 +100,7 @@ elif os.name == "posix": 15 return thefile.read(4) == elf_header 16 17 def _findLib_gcc(name): 18- # Run GCC's linker with the -t (aka --trace) option and examine the 19- # library name it prints out. The GCC command will fail because we 20- # haven't supplied a proper program with main(), but that does not 21- # matter. 22- expr = os.fsencode(r'[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name)) 23- 24- c_compiler = shutil.which('gcc') 25- if not c_compiler: 26- c_compiler = shutil.which('cc') 27- if not c_compiler: 28- # No C compiler available, give up 29- return None 30- 31- temp = tempfile.NamedTemporaryFile() 32- try: 33- args = [c_compiler, '-Wl,-t', '-o', temp.name, '-l' + name] 34- 35- env = dict(os.environ) 36- env['LC_ALL'] = 'C' 37- env['LANG'] = 'C' 38- try: 39- proc = subprocess.Popen(args, 40- stdout=subprocess.PIPE, 41- stderr=subprocess.STDOUT, 42- env=env) 43- except OSError: # E.g. bad executable 44- return None 45- with proc: 46- trace = proc.stdout.read() 47- finally: 48- try: 49- temp.close() 50- except FileNotFoundError: 51- # Raised if the file was already removed, which is the normal 52- # behaviour of GCC if linking fails 53- pass 54- res = re.findall(expr, trace) 55- if not res: 56- return None 57- 58- for file in res: 59- # Check if the given file is an elf file: gcc can report 60- # some files that are linker scripts and not actual 61- # shared objects. See bpo-41976 for more details 62- if not _is_elf(file): 63- continue 64- return os.fsdecode(file) 65+ return None 66 67 68 if sys.platform == "sunos5": 69@@ -268,34 +222,7 @@ elif os.name == "posix": 70 else: 71 72 def _findSoname_ldconfig(name): 73- import struct 74- if struct.calcsize('l') == 4: 75- machine = os.uname().machine + '-32' 76- else: 77- machine = os.uname().machine + '-64' 78- mach_map = { 79- 'x86_64-64': 'libc6,x86-64', 80- 'ppc64-64': 'libc6,64bit', 81- 'sparc64-64': 'libc6,64bit', 82- 's390x-64': 'libc6,64bit', 83- 'ia64-64': 'libc6,IA-64', 84- } 85- abi_type = mach_map.get(machine, 'libc6') 86- 87- # XXX assuming GLIBC's ldconfig (with option -p) 88- regex = r'\s+(lib%s\.[^\s]+)\s+\(%s' 89- regex = os.fsencode(regex % (re.escape(name), abi_type)) 90- try: 91- with subprocess.Popen(['/sbin/ldconfig', '-p'], 92- stdin=subprocess.DEVNULL, 93- stderr=subprocess.DEVNULL, 94- stdout=subprocess.PIPE, 95- env={'LC_ALL': 'C', 'LANG': 'C'}) as p: 96- res = re.search(regex, p.stdout.read()) 97- if res: 98- return os.fsdecode(res.group(1)) 99- except OSError: 100- pass 101+ return None 102 103 def _findLib_ld(name): 104 # See issue #9998 for why this is needed 105-- 1062.24.3 (Apple Git-128)