mirror of
https://github.com/python/cpython.git
synced 2025-10-31 21:51:50 +00:00
bpo-41976: Fix the fallback to gcc of ctypes.util.find_library when using gcc>9 (GH-22598)
(cherry picked from commit 27ac19cca2)
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
This commit is contained in:
parent
15e091f63f
commit
a4ac5fadf5
3 changed files with 38 additions and 7 deletions
|
|
@ -93,6 +93,12 @@ def find_library(name):
|
|||
# Andreas Degert's find functions, using gcc, /sbin/ldconfig, objdump
|
||||
import re, tempfile
|
||||
|
||||
def _is_elf(filename):
|
||||
"Return True if the given file is an ELF file"
|
||||
elf_header = b'\x7fELF'
|
||||
with open(filename, 'br') as thefile:
|
||||
return thefile.read(4) == elf_header
|
||||
|
||||
def _findLib_gcc(name):
|
||||
# Run GCC's linker with the -t (aka --trace) option and examine the
|
||||
# library name it prints out. The GCC command will fail because we
|
||||
|
|
@ -130,10 +136,17 @@ def _findLib_gcc(name):
|
|||
# Raised if the file was already removed, which is the normal
|
||||
# behaviour of GCC if linking fails
|
||||
pass
|
||||
res = re.search(expr, trace)
|
||||
res = re.findall(expr, trace)
|
||||
if not res:
|
||||
return None
|
||||
return os.fsdecode(res.group(0))
|
||||
|
||||
for file in res:
|
||||
# Check if the given file is an elf file: gcc can report
|
||||
# some files that are linker scripts and not actual
|
||||
# shared objects. See bpo-41976 for more details
|
||||
if not _is_elf(file):
|
||||
continue
|
||||
return os.fsdecode(file)
|
||||
|
||||
|
||||
if sys.platform == "sunos5":
|
||||
|
|
@ -299,9 +312,14 @@ def _findLib_ld(name):
|
|||
stderr=subprocess.PIPE,
|
||||
universal_newlines=True)
|
||||
out, _ = p.communicate()
|
||||
res = re.search(expr, os.fsdecode(out))
|
||||
if res:
|
||||
result = res.group(0)
|
||||
res = re.findall(expr, os.fsdecode(out))
|
||||
for file in res:
|
||||
# Check if the given file is an elf file: gcc can report
|
||||
# some files that are linker scripts and not actual
|
||||
# shared objects. See bpo-41976 for more details
|
||||
if not _is_elf(file):
|
||||
continue
|
||||
return os.fsdecode(file)
|
||||
except Exception:
|
||||
pass # result will be None
|
||||
return result
|
||||
|
|
@ -309,7 +327,7 @@ def _findLib_ld(name):
|
|||
def find_library(name):
|
||||
# See issue #9998
|
||||
return _findSoname_ldconfig(name) or \
|
||||
_get_soname(_findLib_gcc(name) or _findLib_ld(name))
|
||||
_get_soname(_findLib_gcc(name)) or _get_soname(_findLib_ld(name))
|
||||
|
||||
################################################################
|
||||
# test code
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue