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

Make static internals ptr pybind version specific #862

Merged
merged 1 commit into from
May 18, 2017

Conversation

jagerman
Copy link
Member

@jagerman jagerman commented May 17, 2017

Under gcc, the static internals *internals_ptr is shared across .so's, which breaks for obvious reasons.

This commit fixes it by moving the static pointer declaration into a pybind-version-templated function.

Fixes #796.

@jagerman
Copy link
Member Author

(This doesn't affect test suite .so size at all.)

@dean0x7d
Copy link
Member

It's strange that gcc does that. The fix looks good to me. Might be nice to add a comment above the new function template since its purpose is a bit mysterious out of context.

(As a side-note, placing get_internals inside an inline namespace with a version-macro-derived name could also be a solution, but more code than the template parameter version.)

Under gcc, the `static internals *internals_ptr` is shared across .so's,
which breaks for obvious reasons.

This commit fixes it by moving the static pointer declaration into a
pybind-version-templated function.
@jagerman
Copy link
Member Author

Added a comment, and removed the unneeded "inline".

@jagerman jagerman merged commit a4d0d95 into pybind:master May 18, 2017
@jagerman
Copy link
Member Author

A bit of further investigation: gcc only seems to behave this way when not compiling with -flto. Static locals then get exported as STB_GNU_UNIQUE, which makes them unique, even across the RTLD_LOCAL boundary.

With -flto this doesn't appear to happen.

@jagerman
Copy link
Member Author

Another way to fix this is to compile with -fno-gnu-unique.

jagerman added a commit to jagerman/pybind11 that referenced this pull request Jul 24, 2017
…cals

This commit adds an attribute macro PYBIND11_UNSHARED_STATIC_LOCALS
that forces a function to have hidden visibility under gcc.  This is
needed to force gcc to avoid sharing static local instances across
modules (which happens even under a RTLD_LOCAL dlopen()!)

This replaces the fix from pybind#862 to use this instead of the
version-specific-template internals pointer.
jagerman added a commit to jagerman/pybind11 that referenced this pull request Jul 24, 2017
…cals

This commit adds an attribute macro PYBIND11_UNSHARED_STATIC_LOCALS
that forces a function to have hidden visibility under gcc.  This is
needed to force gcc to avoid sharing static local instances across
modules (which happens even under a RTLD_LOCAL dlopen()!)

This updates the workaround from pybind#862 to use this rather than the
version-specific-template.
jagerman added a commit to jagerman/pybind11 that referenced this pull request Jul 25, 2017
…cals

This commit adds an attribute macro PYBIND11_UNSHARED_STATIC_LOCALS
that forces a function to have hidden visibility under gcc.  This is
needed to force gcc to avoid sharing static local instances across
modules (which happens even under a RTLD_LOCAL dlopen()!)

This updates the workaround from pybind#862 to use this rather than the
version-specific-template.
jagerman added a commit to jagerman/pybind11 that referenced this pull request Jul 29, 2017
This commit adds a PYBIND11_UNSHARED_STATIC_LOCALS macro that forces a
function to have hidden visibility under gcc and gcc-compatible
compilers.  gcc, in particular, needs this to to avoid sharing static
local variables across modules (which happens even under a RTLD_LOCAL
dlopen()!).  clang doesn't appear to have this issue, but the forced
visibility on internal pybind functions certainly won't hurt it and icc.

This updates the workaround from pybind#862 to use this rather than the
version-specific template.
jagerman added a commit to jagerman/pybind11 that referenced this pull request Aug 4, 2017
This commit adds a PYBIND11_UNSHARED_STATIC_LOCALS macro that forces a
function to have hidden visibility under gcc and gcc-compatible
compilers.  gcc, in particular, needs this to to avoid sharing static
local variables across modules (which happens even under a RTLD_LOCAL
dlopen()!).  clang doesn't appear to have this issue, but the forced
visibility on internal pybind functions certainly won't hurt it and icc.

This updates the workaround from pybind#862 to use this rather than the
version-specific template.
jagerman added a commit that referenced this pull request Aug 4, 2017
This commit adds a PYBIND11_UNSHARED_STATIC_LOCALS macro that forces a
function to have hidden visibility under gcc and gcc-compatible
compilers.  gcc, in particular, needs this to to avoid sharing static
local variables across modules (which happens even under a RTLD_LOCAL
dlopen()!).  clang doesn't appear to have this issue, but the forced
visibility on internal pybind functions certainly won't hurt it and icc.

This updates the workaround from #862 to use this rather than the
version-specific template.
@dean0x7d dean0x7d modified the milestone: v2.2 Aug 13, 2017
@rwgk rwgk mentioned this pull request Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve mixed-version handling
2 participants