Skip to content

[BUG] pybind11_add_module forcing -fvisiblity=hidden is a bit too aggressive? #2479

Closed
@EricCousineau-TRI

Description

@EricCousineau-TRI

Issue description

In 97aa54fefa, -fvisibility=hidden was introduced to pybind11_add_module as a means to effectively avoid warnings (by means of setting CXX_VISIBILITY_PRESET to "hidden").

I ran into this on our downstream project (which uses a pybind11 fork) here:
RobotLocomotion/drake#14047
In the fork, I had previously stripped out that CMake code, then restored it when merging in the changes from more active development. (In this issue, I've provided the workaround, which is to re-set the visibility to "default".)

The long and short is, we (unfortunately) have very template-heavy public API and bindings, and setting -fvisibility=hidden in downstream units mean that some of the bound symbols may get new RTTI information, which we don't want in our project.

From reading the comments in the commit (and the surround commit on current master), it looks like this preset isn't really necessary; it's really only to suppress errors in user's code who aren't sufficiently careful to curate their symbol visibility.

That's fine, but I would still love to not have to reverse that in code and try to track changes.

Reproducible example code

See downstream issue.

Possible solutions

From most conservative (keep non-expert users happy) to least conservative (require users be cognizant):

  1. No change. Maybe add a docstring to pybind11_add_module talking about templates, RTTI, and visibility with bindings, and mention the workaround (which is now coupled to internal implementation details, albeit publicly documented).
  2. Add a flag to pybind11_add_module to not foist hidden visibility on downstream code (instantiations).
  3. Remove the flag. Update the docs to tell users to add it themselves (not super suggested) or add more explicit visibility annotations (heavily suggested).

@rwgk @YannickJadoul @bstaletic @wjakob Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions