Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ctypes.utils.find_library broken on musl libc #33047

Open
tornaria opened this issue Dec 20, 2021 · 7 comments · May be fixed by #38675
Open

ctypes.utils.find_library broken on musl libc #33047

tornaria opened this issue Dec 20, 2021 · 7 comments · May be fixed by #38675

Comments

@tornaria
Copy link
Contributor

More precisely, ctypes.util.find_library('c') is broken which causes a failure doctesting src/sage/misc/gperftools.py.

The current commit adds a patch that I took from void linux, which in turn it's taken from alpine linux.

See: https://git.alpinelinux.org/aports/plain/main/python3/musl-find_library.patch.

CC: @orlitzky

Component: packages: standard

Author: Gonzalo Tornaría

Branch/Commit: u/tornaria/python3-musl-find_library @ dc1a0e8

Issue created by migration from https://trac.sagemath.org/ticket/33047

@mkoeppe
Copy link
Contributor

mkoeppe commented Dec 20, 2021

comment:2

We have another version of find_library in sage.misc.compat, could you take a look at that?

@tornaria
Copy link
Contributor Author

comment:3

I recompiled sage with musl libc, using the bundled python and without musl-find_library.patch so I can be more detailed about the situation:

  1. doctest failure in src/sage/misc/gperftools.py
sage -t --random-seed=78105796188891934420135729057135667648 src/sage/misc/gperftools.py
**********************************************************************
File "src/sage/misc/gperftools.py", line 118, in sage.misc.gperftools.Profiler._libc
Failed example:
    Profiler()._libc()
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/sage-9.5.beta8/local/var/lib/sage/venv-python3.9.7/lib/python3.9/site-packages/sage/doctest/forker.py", line 694, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/usr/lib/sage-9.5.beta8/local/var/lib/sage/venv-python3.9.7/lib/python3.9/site-packages/sage/doctest/forker.py", line 1088, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.misc.gperftools.Profiler._libc[1]>", line 1, in <module>
        Profiler()._libc()
      File "/usr/lib/sage-9.5.beta8/local/var/lib/sage/venv-python3.9.7/lib/python3.9/site-packages/sage/misc/gperftools.py", line 129, in _libc
        raise ImportError('failed to open libc')
    ImportError: failed to open libc
**********************************************************************

Explicitly:

sage: from sage.misc.gperftools import Profiler
sage: Profiler()._libc()
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-2-8776de42ff63> in <module>
----> 1 Profiler()._libc()

/usr/lib/sage-9.5.beta8/local/var/lib/sage/venv-python3.9.7/lib/python3.9/site-packages/sage/misc/gperftools.py in _libc(self)
    127             return libc
    128         else:
--> 129             raise ImportError('failed to open libc')
    130 
    131     def _libprofiler(self):

ImportError: failed to open libc

This can be traced to

sage: import sage.misc.compat
sage: sage.misc.compat.find_library('c') is None
True

But on sys.platform == linux the functionsage.misc.compat.find_library is just a proxy for the python function ctypes.util.find_library and

sage: import ctypes.util
sage: ctypes.util.find_library('c') is None
True

The patch I included fixes ctypes.util.find_library by patching python source, fixing all three above.

Are you suggesting instead to patch sage.misc.compat.find_library?

@slel
Copy link
Member

slel commented Jan 30, 2022

comment:4

Set milestone to sage-9.6 after Sage 9.5 release.

@slel slel modified the milestones: sage-9.5, sage-9.6 Jan 30, 2022
@orlitzky
Copy link
Contributor

orlitzky commented Feb 7, 2022

comment:5

Replying to @tornaria:

The patch I included fixes ctypes.util.find_library by patching python source, fixing all three above.

Are you suggesting instead to patch sage.misc.compat.find_library?

If possible, working around the issue in sage would be preferable. For example we aim to support musl in Gentoo as well and would like everyone to be able to use the system python without patching it.

@mkoeppe mkoeppe modified the milestones: sage-9.6, sage-9.7 May 3, 2022
@mkoeppe mkoeppe modified the milestones: sage-9.7, sage-9.8 Sep 19, 2022
@mkoeppe mkoeppe removed this from the sage-9.8 milestone Jan 29, 2023
@orlitzky
Copy link
Contributor

What is this line of code in gperftools.py doing, anyway? To me it looks like a circuitous way of setting the OS handler for SIGPROF to SIG_DFL. Doesn't cysignals do that without having to guess the path to my libc.so?

@orlitzky
Copy link
Contributor

And naturally, this file hasn't worked since we switched to python3.

@orlitzky orlitzky linked a pull request Sep 18, 2024 that will close this issue
@orlitzky
Copy link
Contributor

Should be fixed in #38675

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants