Improved control of symbol visibility
Description of Issue
Drake has begun incorporating portions of OpenUSD, via building from source code. One Drake-specific requirement (that other downstream library developers may have) is to minimize the symbols that are visible from its shared libraries.
Drake uses two techniques to control symbols:
- compiler symbol visibility attributes (https://gcc.gnu.org/wiki/Visibility)
- rewriting namespace names to contain the string 'drake_vendor'
Technique 1 has the limitation that it sometimes interferes with c++ in surprising ways (e.g https://github.com/PixarAnimationStudios/OpenUSD/issues/1475). It can work well for plain C code.
Happily, OpenUSD has a very nice system to let downstream builders rewrite its namespaces. However, the Drake integration experience so far has uncovered a few holes in the namespace scheme. I hope to help address this by offering a few small PRs, with reference back to this issue.
Steps to Reproduce
It's easiest to give an example from OpenUSD's own shared library output. These instructions are for Ubuntu Jammy.
-
$cd path-to/OpenUSD -
$ git checkout dev -
$ python3 ./build_scripts/build_usd.py --no-python ~/tmp/usd/dist -
$ cd ~/tmp/usd/dist -
$ readelf --wide --symbols --demangle ./lib/libusd_work.so | grep 'GLOBAL *DEFAULT' |egrep -v 'pxrInternal|GLIBC|GCC|CXXABI|tbb::' - In the output from above, the data section symbol
PXR_WORK_THREAD_LIMITis GLOBAL and not namespaced. - Repeat the above on libusd_gf.so, libusd_pegtl.so, etc., to see other cases.
System Information (OS, Hardware)
Ubuntu LTS versions for x84_64, macOS recent versions for arm64. See the Supported Configurations table at https://drake.mit.edu/installation.html .
Package Versions
The problems vary over time, but several were seen as of v24.08. Current dev has fewer problems already.
Build Flags
Filed as internal issue #USD-10094
The PRs associated with this issue have all been merged, so I'm going to close this out. Please file a new issue if this problem is still present even after these changes. Thank you!