Skip to content

Commit

Permalink
nmslib: DO NOT MERGE add a temporary check for removed glibc symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
valgur committed Oct 12, 2023
1 parent 3574c94 commit c529c73
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion recipes/nmslib/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.apple import fix_apple_shared_install_name
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get
from conan.tools.microsoft import is_msvc, check_min_vs

Expand Down Expand Up @@ -74,6 +75,51 @@ def package(self):
src=self.source_folder)
cmake = CMake(self)
cmake.install()
self._check_for_removed_glibc_symbols()

def _check_for_removed_glibc_symbols(self):
from conan.tools.scm import Version
from conan.errors import ConanException
import re
if self.settings.os not in ["Linux", "FreeBSD"]:
return
if self.settings.compiler == "clang" and Version(self.settings.compiler.version) >= 10:
return
external_symbols = self._list_external_elf_symbols()
finite_math_pattern = re.compile(r"\w*__\w+_finite")
removed_glibc_symbols = {"__dn_expand", "__res_nquery", "__xmknod", "__xmknodat"}
finite_math_warnings = []
for file, symbols in external_symbols.items():
forbidden_symbols = [sym for sym in symbols if finite_math_pattern.fullmatch(sym) or sym in removed_glibc_symbols]
if forbidden_symbols:
finite_math_warnings.append(f"{file}: {', '.join(sorted(forbidden_symbols))}")
if finite_math_warnings:
raise ConanException(f"Package contains files that link against functions removed from glibc >= v2.31:\n"
+ "\n".join(sorted(finite_math_warnings))
+ "\nPlease add -fno-finite-math-only to compiler flags to disable the use of these functions in optimizations.")

def _list_external_elf_symbols(self):
import subprocess
def _objdump(path, is_dynamic):
cmd = ["objdump", "--dynamic-syms" if is_dynamic else "--syms", path]
objdump_output = subprocess.check_output(cmd, cwd=self.package_folder).decode()
return [l.rsplit(" ", 1)[-1] for l in objdump_output.splitlines() if "*UND*" in l]

def _is_elf(path):
with path.open("rb") as f:
return f.read(4) == b"\x7fELF"

symbols = {}
for file in (self.package_path / "lib").rglob("*.a"):
if file.is_file() and not file.is_symlink():
symbols[file] = _objdump(file, is_dynamic=False)
for file in (self.package_path / "lib").rglob("*.so*"):
if file.is_file() and not file.is_symlink() and _is_elf(file):
symbols[file] = _objdump(file, is_dynamic=True)
for file in (self.package_path / "bin").rglob("*"):
if (file.is_file() and not file.is_symlink() and os.access(file, os.X_OK) and _is_elf(file)):
symbols[file] = _objdump(file, is_dynamic=True)
return {k.relative_to(self.package_path): v for k, v in symbols.items()}

def package_info(self):
self.cpp_info.libs = ["NonMetricSpaceLib"]
Expand Down

0 comments on commit c529c73

Please sign in to comment.