-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hide visibility of non-public symbols (#1644)
Fixes #1645 Contributes to rapidsai/build-planning#33 Similar to rapidsai/cudf#15982 Proposes more tightly controlling the visibility of symbols in the shared libraries produces for the `rmm` Python library, via the following: * compiling with `-fvisibility=hidden` by default * marking intended-to-be-public parts of `rmm` *(everything in the `rmm::` namespace)* with `__attribute__((visibility("default")))` ## Benefits of this change Reduces the risk of symbol conflicts when `rmm` is used alongside other libraries. For example, see this case in `cudf` where the `spdlog::` symbols in `rmm` are conflicting with the `spdlog::` symbols in `nvcomp`: rapidsai/cudf#15483 (comment) Reduces library size by a bit (around 0.3 MB uncompressed), by reducing the size of symbol tables in DSOs. ## Notes for Reviewers This is at the very edge of my C++ knowledge, apologies in advance if I've missed something obvious 😬 # Authors: - James Lamb (https://github.com/jameslamb) Approvers: - Bradley Dice (https://github.com/bdice) - Kyle Edwards (https://github.com/KyleFromNVIDIA) - Mark Harris (https://github.com/harrism) - Vyas Ramasubramani (https://github.com/vyasr) URL: #1644
- Loading branch information
Showing
4 changed files
with
103 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#!/bin/bash | ||
# Copyright (c) 2024, NVIDIA CORPORATION. | ||
|
||
set -eEuo pipefail | ||
|
||
echo "checking for symbol visibility issues" | ||
|
||
WHEEL_FILE=${1} | ||
|
||
raise-symbols-found-error() { | ||
local pattern="${1}" | ||
|
||
err_msg="ERROR: Found some exported symbols matching the pattern '${pattern}'. | ||
These should be marked with 'hidden' visibility. | ||
See https://cmake.org/cmake/help/latest/prop_tgt/LANG_VISIBILITY_PRESET.html and https://gcc.gnu.org/wiki/Visibility for details. | ||
" | ||
|
||
echo "" | ||
echo "${err_msg}" | ||
exit 1 | ||
} | ||
|
||
WHEEL_EXPORT_DIR="$(mktemp -d)" | ||
|
||
unzip \ | ||
-d "${WHEEL_EXPORT_DIR}" \ | ||
"${WHEEL_FILE}" | ||
|
||
dso_files=$( | ||
find \ | ||
"${WHEEL_EXPORT_DIR}" \ | ||
-type f \ | ||
\( -name '*.so' -o -name '*.so.*' \) | ||
) | ||
|
||
for dso_file in ${dso_files}; do | ||
echo "" | ||
echo "checking exported symbols in '${dso_file}'" | ||
symbol_file="./syms.txt" | ||
readelf --symbols --wide "${dso_file}" \ | ||
| c++filt \ | ||
> "${symbol_file}" | ||
|
||
echo "symbol counts by type" | ||
echo " * GLOBAL: $(grep --count -E ' GLOBAL ' < ${symbol_file})" | ||
echo " * WEAK: $(grep --count -E ' WEAK ' < ${symbol_file})" | ||
echo " * LOCAL: $(grep --count -E ' LOCAL ' < ${symbol_file})" | ||
|
||
# Explanation for '-v' uses here: | ||
# | ||
# * 'format_error' symbols are intentionally exported, that type of error | ||
# can be thrown across library boundaries. See "Problems with C++ exceptions" | ||
# at https://gcc.gnu.org/wiki/Visibility. | ||
echo "checking for 'fmt::' symbols..." | ||
if grep -E 'fmt\:\:' < "${symbol_file}" \ | ||
| grep -v 'format_error' | ||
then | ||
raise-symbols-found-error 'fmt::' | ||
fi | ||
|
||
# Explanation for '-v' uses here: | ||
# | ||
# * trivially-destructible objects sometimes get an entry in the symbol table | ||
# for a specialization of `std::_Destroy_aux()` called to destroy them. | ||
# There is one for `spdlog::details::log_msg_buffer like that: | ||
# | ||
# 'std::_Destroy_aux<false>::__destroy<spdlog::details::log_msg_buffer*>' | ||
# | ||
# That should be safe to export. | ||
# | ||
echo "checking for 'spdlog::' symbols..." | ||
if grep -E 'spdlog\:\:' < "${symbol_file}" \ | ||
| grep -v 'std\:\:_Destroy_aux' | ||
then | ||
raise-symbols-found-error 'spdlog::' | ||
fi | ||
echo "No symbol visibility issues found" | ||
done | ||
|
||
echo "" | ||
echo "No symbol visibility issues found in any DSOs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters