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

Don't support the PEP384 stable ABI in pydebug builds #72587

Closed
stefanor mannequin opened this issue Oct 9, 2016 · 8 comments
Closed

Don't support the PEP384 stable ABI in pydebug builds #72587

stefanor mannequin opened this issue Oct 9, 2016 · 8 comments
Labels
3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@stefanor
Copy link
Mannequin

stefanor mannequin commented Oct 9, 2016

BPO 28401
Nosy @brettcannon, @doko42, @ncoghlan, @ericsnowcurrently, @stefanor, @mitya57, @miss-islington
PRs
  • bpo-28401: prevent Py_DEBUG builds from trying to import limited ABI modules #1766
  • Files
  • pep384-pydbg.patch: Patch version 1
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2018-11-19.20:41:18.954>
    created_at = <Date 2016-10-09.17:31:32.073>
    labels = ['interpreter-core', 'type-bug', '3.7']
    title = "Don't support the PEP384 stable ABI in pydebug builds"
    updated_at = <Date 2018-11-21.22:16:48.293>
    user = 'https://github.com/stefanor'

    bugs.python.org fields:

    activity = <Date 2018-11-21.22:16:48.293>
    actor = 'brett.cannon'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-11-19.20:41:18.954>
    closer = 'brett.cannon'
    components = ['Interpreter Core']
    creation = <Date 2016-10-09.17:31:32.073>
    creator = 'stefanor'
    dependencies = []
    files = ['45040']
    hgrepos = []
    issue_num = 28401
    keywords = ['patch']
    message_count = 8.0
    messages = ['278381', '279540', '279542', '284853', '294273', '294276', '330014', '330221']
    nosy_count = 7.0
    nosy_names = ['brett.cannon', 'doko', 'ncoghlan', 'eric.snow', 'stefanor', 'mitya57', 'miss-islington']
    pr_nums = ['1766']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue28401'
    versions = ['Python 3.3', 'Python 3.4', 'Python 3.5', 'Python 3.6', 'Python 3.7']

    @stefanor
    Copy link
    Mannequin Author

    stefanor mannequin commented Oct 9, 2016

    setup.py build for a library using py_limited_api will always generate a stable ABI tagged shared library, even under the pydebug interpreter.

    This means that extensions that are built for a pydebug interpreter may be accidentally (and brokenly) imported in a non-dbg interpreter and vice-versa.

    e.g. in python-librtmp, with cffi 1.8.3:
    $ python3-dbg setup.py build
    ...
    x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,relro -g -Og -fdebug-prefix-map=/build/python3.5-H9Fri6/python3.5-3.5.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.5-pydebug/build/temp.linux-x86_64-3.5-pydebug/librtmp._librtmp.o -lrtmp -o build/lib.linux-x86_64-3.5-pydebug/librtmp/_librtmp.abi3.so

    Then:
    $ cd build/lib.linux-x86_64-3.5-pydebug
    $ python3 -c 'import librtmp'
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/python-librtmp-0.3.0/build/lib.linux-x86_64-3.5-pydebug/librtmp/__init__.py", line 8, in <module>
        from ._librtmp import ffi, lib as librtmp
    ImportError: /tmp/python-librtmp-0.3.0/build/lib.linux-x86_64-3.5-pydebug/librtmp/_librtmp.abi3.so: undefined symbol: _Py_RefTotal

    setuptools decides whether to use the stable ABI, by looking at imp.get_suffixes(). And obviously, the importer is looking at that too. So, the stable ABI tag should simply not be in there.

    PEP-3149 agrees with this. It has this quote from Martin v. Löwis:
    --with-pydebug would not be supported by the stable ABI because this changes the layout of PyObject , which is an exposed structure.

    So, here's a patch, to disable support for the stable ABI under pydebug builds.

    @stefanor stefanor mannequin added stdlib Python modules in the Lib dir 3.7 (EOL) end of life type-bug An unexpected behavior, bug, or error labels Oct 9, 2016
    @doko42
    Copy link
    Member

    doko42 commented Oct 27, 2016

    I'm not sure that you really want this, because it would make it impossible to build an extension for the stable ABI for a debug build. The problem is Debian specific, because we install the extension modules for normal and debug builds in the same location. A Debian solution would be to use a different soname for stable API debug mode extensions.

    @stefanor
    Copy link
    Mannequin Author

    stefanor mannequin commented Oct 27, 2016

    I wouldn't say it's *entirely* Debian-specific. It just bites anyone who actually needs these tags to differentiate between built extensions. (Mostly Debian)

    Yes, changing the tag is a more complete solution. It just seemed that that option was decided against, in the relevant PEPs.

    @mitya57
    Copy link
    Mannequin

    mitya57 mannequin commented Jan 6, 2017

    [Matthias Klose (doko) 2016-10-27 15:45]

    I'm not sure that you really want this, because it would make it impossible to build an extension for the stable ABI for a debug build.

    It looks like that is already impossible:

    /usr/include/python3.5dm/object.h:65:2: error: #error Py_LIMITED_API is incompatible with Py_DEBUG, Py_TRACE_REFS, and Py_REF_DEBUG
    #error Py_LIMITED_API is incompatible with Py_DEBUG, Py_TRACE_REFS, and Py_REF_DEBUG
    ^~~~~

    So in my opinion Stefano's patch makes sense.

    @brettcannon
    Copy link
    Member

    So limited ABI modules can't be imported by a Py_DEBUG build. Stefano's patch just skips over them. That seems reasonable, but one question I do have is whether this would confuse users since they will simply get an ImportError instead of some other error and thus will they be able to realize why there's a problem?

    @brettcannon brettcannon added interpreter-core (Objects, Python, Grammar, and Parser dirs) and removed stdlib Python modules in the Lib dir labels May 23, 2017
    @stefanor
    Copy link
    Mannequin Author

    stefanor mannequin commented May 23, 2017

    whether this would confuse users since they will simply get an ImportError instead of some other error and thus will they be able to realize why there's a problem?

    It's the same behaviour we have for any other module on the import path, that doesn't have the right tag. I suppose abi3 is a bit of a special case there, because it's expected to be widely supported...

    Also, there is a related problem: Because abi3 is in the supported extension list, setup.py build will build an abi3 extension (which isn't actually abi3), under a pydebug interpreter.

    @miss-islington
    Copy link
    Contributor

    New changeset 338d54f by Miss Islington (bot) (Stefano Rivera) in branch 'master':
    bpo-28401: prevent Py_DEBUG builds from trying to import limited ABI modules (GH-1766)
    338d54f

    @brettcannon
    Copy link
    Member

    Thanks for the PR!

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants