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

MAINT: hide symbols on Linux when using GNU linker #8463

Merged
merged 3 commits into from Feb 25, 2018

Conversation

pv
Copy link
Member

@pv pv commented Feb 23, 2018

Hide unnecessary symbols in .so libraries, using a GNU linker version script on linux.

This is a general solution to the discussion in #8451

Overriding the distutils logic by a custom build_ext seemed the cleanest option. The logic of detecting when a GNU linker is similar to what distutils does internally, didn't find a nicer way and this information doesn't seem to be available otherwise.

There was a testing module scipy.integrate._test_multivariate that tried to look up some test symbols with ctypes --- rewrote that to use a different approach.

This may also work on OSX, but I'll leave that to someone else.
(Windows already does something like this in standard Python distutils with MSVC, so no changes necessary for that platform.)

Copy link
Contributor

@tylerjereddy tylerjereddy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solution seems more sustainable than a case-by-case enforcement of symbol hiding as in #8451. Perhaps @stuartarchibald can briefly confirm given comments on the previously proposed solution.

I'm guessing we won't have tests to enforce "stable" symbol exposure on different platforms anytime soon--I wonder if that is a good practice or just overkill, in terms of guaranteeing what other libraries have low-level access to, etc.

setup.py Outdated Show resolved Hide resolved
Use -Wl,--version-script linker flag to restrict symbols exported in the
built .so files, if we are using a GNU linker on Linux.  Do this by
overriding the built_ext command, so that the fix is applied to all
extensions.
@pv
Copy link
Member Author

pv commented Feb 24, 2018

Added a test on Travis that checks the number of exported symbols.

@person142
Copy link
Member

This may also work on OSX, but I'll leave that to someone else.

I'll note that it doesn't work out-of-the box since the default linker on OSX doesn't support version scripts.

Copy link
Contributor

@tylerjereddy tylerjereddy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM & there's a test now in CI for linux symbol exposure

@stuartarchibald
Copy link

@tylerjereddy I think this will achieve what is desired on Linux with GNU ld.

adbugger pushed a commit to adbugger/scipy that referenced this pull request Mar 11, 2018
* MAINT: integrate: export symbols with pycapsules in _test_multivariate

* BLD: control exported symbols, on Linux with GNU linker

Use -Wl,--version-script linker flag to restrict symbols exported in the
built .so files, if we are using a GNU linker on Linux.  Do this by
overriding the built_ext command, so that the fix is applied to all
extensions.

* CI: check symbol hiding on linux
@rgommers rgommers added Build issues Issues with building from source, including different choices of architecture, compilers and OS maintenance Items related to regular maintenance tasks labels Nov 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Build issues Issues with building from source, including different choices of architecture, compilers and OS maintenance Items related to regular maintenance tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants