-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Remove cmake PROPERTIES CXX_VISIBILITY_PRESET "hidden"
#4072
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
base: master
Are you sure you want to change the base?
Conversation
…11_NS_VISIBILITY`, use to resolve all "... declared with greater visibility than ..." warnings across all platforms.
This PR proves that we do not need What is your opinion regarding this question (currently a TODO in the PR description):
From my perspective, pushing "hidden" as strongly as it is done currently in the documentation and cmake files is more on the harmful than helpful side. Google-internally, after significant back & forth and confusion, we removed |
I'm down for this! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First pass done, PTAL!
@@ -25,8 +25,10 @@ | |||
// on the main `pybind11` namespace. | |||
#if !defined(PYBIND11_NAMESPACE) | |||
# ifdef __GNUG__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit VISIBILITY
sounds like what is being changed, but this doesn't provide an option to choose.
Consider using HIDDEN
to make intent more clear.
@@ -25,8 +25,10 @@ | |||
// on the main `pybind11` namespace. | |||
#if !defined(PYBIND11_NAMESPACE) | |||
# ifdef __GNUG__ | |||
# define PYBIND11_NAMESPACE pybind11 __attribute__((visibility("hidden"))) | |||
# define PYBIND11_NS_VISIBILITY(...) __VA_ARGS__ __attribute__((visibility("hidden"))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit While NS
is a good abbreviation, perhaps it is still good to full expand NAMESPACE
?
Or if this is agnostic to the type of symbol, consider just removing the NS
qualifier?
@@ -13,14 +13,19 @@ | |||
|
|||
namespace py = pybind11; | |||
|
|||
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NS_VISIBILITY(pybind11_tests)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if I understand need for applying hidden
when it only contains an anonymous namespace.
Is it possible to revert this (possibly redundant) change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Eric, I'll wait for Henry's opinion before investing more time, but to explain quickly, this is purely to appease some sad compilers that don't "realize" that the unnamed namespace is already hidden. I could add comments, or remove the unnamed namespace, I'll figure out something after we decided the big question.
@@ -15,6 +15,8 @@ | |||
#include <stdexcept> | |||
#include <utility> | |||
|
|||
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NS_VISIBILITY(pybind11_tests)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above - why not just use anonymous namespace {}
?
@@ -5,9 +5,13 @@ | |||
|
|||
// shared exceptions for cross_module_tests | |||
|
|||
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NS_VISIBILITY(pybind11_tests)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above - why not just use anonymous namespace {}
?
@@ -15,6 +15,8 @@ | |||
#include <cstdint> | |||
#include <utility> | |||
|
|||
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NS_VISIBILITY(pybind11_tests)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above - why not just use anonymous namespace {}
?
@@ -11,7 +11,7 @@ | |||
|
|||
#include <utility> | |||
|
|||
namespace external { | |||
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NS_VISIBILITY(external)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit Er, hiding a namespace external
smells odd.
Can we use a better name here? e.g. feaux_external
, with a comment of what is going on?
@@ -203,19 +203,6 @@ function(pybind11_add_module target_name) | |||
target_link_libraries(${target_name} PRIVATE pybind11::windows_extras) | |||
endif() | |||
|
|||
# -fvisibility=hidden is required to allow multiple modules compiled against |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW yay! deleting code makes me 10000% happier!
Let's wait till after 2.10.1 to decide on this. I know the original design was to do the right thing for most users, and most users are not using the ABI compat, and are not that familiar with symbol visibility. So suddenly asking everyone to start hiding their symbols or the binaries expand is not a very great thing to do. There's also a very easy workaround - a user can simply unset it, which is making the more advanced use case take more configuration, but that's nicer. I think the corrections on the visibility are good, and we can see how much this tends to affect user code. We could also update the docs recommending users set visibility for a release before we actually pull the plug on the default. |
Description
PROPERTIES CXX_VISIBILITY_PRESET "hidden"
PYBIND11_NS_VISIBILITY
in pybind11/detail/common.hTODO:
PROPERTIES CXX_VISIBILITY_PRESET "hidden"
from the cmake files.Background: Issue #2479
This PR was extracted from PR #4069 [smart_holder]. See commits there.
Suggested changelog entry: