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

Add ldscript code for Python extensions in CMake #6665

Merged
merged 3 commits into from
Mar 29, 2022

Conversation

steven-johnson
Copy link
Contributor

We added ldscripts to the Makefile for Python extensions (to restrict exported symbols to just the PyInit_foo symbol), but neglected to do so for CMake. This corrects that.

We added ldscripts to the Makefile for Python extensions (to restrict exported symbols to just the PyInit_foo symbol), but neglected to do so for CMake. This corrects that.
Comment on lines 27 to 33
if (APPLE)
configure_file(ext.ldscript.apple.in "${CMAKE_CURRENT_BINARY_DIR}/${GEN}.ldscript")
target_link_options(py_${GEN} PRIVATE "-Wl,-exported_symbols_list,${CMAKE_CURRENT_BINARY_DIR}/${GEN}.ldscript")
elseif (UNIX)
configure_file(ext.ldscript.linux.in "${CMAKE_CURRENT_BINARY_DIR}/${GEN}.ldscript")
target_link_options(py_${GEN} PRIVATE "-Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/${GEN}.ldscript")
endif()
Copy link
Member

Choose a reason for hiding this comment

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

We have a helper for this... why not use it?

Suggested change
if (APPLE)
configure_file(ext.ldscript.apple.in "${CMAKE_CURRENT_BINARY_DIR}/${GEN}.ldscript")
target_link_options(py_${GEN} PRIVATE "-Wl,-exported_symbols_list,${CMAKE_CURRENT_BINARY_DIR}/${GEN}.ldscript")
elseif (UNIX)
configure_file(ext.ldscript.linux.in "${CMAKE_CURRENT_BINARY_DIR}/${GEN}.ldscript")
target_link_options(py_${GEN} PRIVATE "-Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/${GEN}.ldscript")
endif()
include(TargetExportScript)
configure_file(ext.ldscript.apple.in "${CMAKE_CURRENT_BINARY_DIR}/${GEN}.ldscript.apple")
configure_file(ext.ldscript.linux.in "${CMAKE_CURRENT_BINARY_DIR}/${GEN}.ldscript")
target_export_script(
py_${GEN}
APPLE_LD "${CMAKE_CURRENT_BINARY_DIR}/${GEN}.ldscript.apple"
GNU_LD "${CMAKE_CURRENT_BINARY_DIR}/${GEN}.ldscript"
)

Copy link
Contributor Author

@steven-johnson steven-johnson Mar 29, 2022

Choose a reason for hiding this comment

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

...because I didn't know apparently completely forgot about it? :-)

Currently, there is no way to set 'synthetic' GeneratorParams via a GeneratorStub. ('synthetic' == things like "fieldname.type" for an input Buffer with an undefined static type.)

C++ GeneratorStubs are rarely used, but the Python stubs are useful, and (more importantly) revising this behavior to be possible will make some future work on Python generators more consistent.

Note that this should (in theory) have no effect on any existing C++ stub users; the new fields added to the stubs all have unique names, and aren't added to the default signatures.
@steven-johnson
Copy link
Contributor Author

Urgh, looks like I made a commit with the wrong message as the fix -- I'll squash it away :-)

@steven-johnson steven-johnson merged commit 5d2abd3 into main Mar 29, 2022
@steven-johnson steven-johnson deleted the srj/pyext-cmake-linker-script branch March 29, 2022 23:33
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.

2 participants