Skip to content

Commit 57bd452

Browse files
authored
Merge pull request #2469 from jorisv/topic/hidden_symbols
Hide all symbols by default
2 parents 902d676 + 561680e commit 57bd452

File tree

8 files changed

+120
-37
lines changed

8 files changed

+120
-37
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
99
### Added
1010
- Add `pinocchio_python_parser` target ([#2475](https://github.com/stack-of-tasks/pinocchio/pull/2475))
1111

12+
### Changed
13+
- On GNU/Linux and macOS, hide all symbols by default ([#2469](https://github.com/stack-of-tasks/pinocchio/pull/2469))
14+
1215
## [3.3.0] - 2024-11-06
1316

1417
### Added

bindings/python/CMakeLists.txt

+12-3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ function(PINOCCHIO_PYTHON_BINDINGS_SPECIFIC_TYPE scalar_name)
5353
${PYTHON_LIB_NAME}
5454
PROPERTIES PREFIX ""
5555
DEFINE_SYMBOL "${PYWRAP}_EXPORTS"
56+
CXX_VISIBILITY_PRESET hidden
5657
VISIBILITY_INLINES_HIDDEN ON)
5758

5859
# Do not report:
@@ -67,10 +68,10 @@ function(PINOCCHIO_PYTHON_BINDINGS_SPECIFIC_TYPE scalar_name)
6768
target_compile_options(${PYTHON_LIB_NAME} PRIVATE ${PRIVATE_OPTIONS})
6869

6970
set(PINOCCHIO_PYTHON_CONTEXT_FILE_VALUE "pinocchio/bindings/python/context/${scalar_name}.hpp")
70-
target_compile_options(
71+
target_compile_definitions(
7172
${PYTHON_LIB_NAME}
72-
PRIVATE -DPINOCCHIO_PYTHON_CONTEXT_FILE="${PINOCCHIO_PYTHON_CONTEXT_FILE_VALUE}"
73-
-DPINOCCHIO_PYTHON_MODULE_NAME=${PYTHON_LIB_NAME})
73+
PRIVATE PINOCCHIO_PYTHON_CONTEXT_FILE="${PINOCCHIO_PYTHON_CONTEXT_FILE_VALUE}"
74+
PINOCCHIO_PYTHON_MODULE_NAME=${PYTHON_LIB_NAME})
7475

7576
set_target_properties(${PYTHON_LIB_NAME} PROPERTIES VERSION ${PROJECT_VERSION})
7677
if(BUILD_WITH_COMMIT_VERSION)
@@ -183,6 +184,14 @@ if(BUILD_PYTHON_INTERFACE)
183184

184185
if(BUILD_WITH_CODEGEN_SUPPORT)
185186
pinocchio_python_bindings_specific_type(cppadcg cppadcg)
187+
188+
# On osx, use default visiblitiy because of an issue with thread_local storage defined in
189+
# cppad/cg/cg.hpp header (see
190+
# https://github.com/stack-of-tasks/pinocchio/pull/2469#issuecomment-2461845127)
191+
if(APPLE)
192+
set_target_properties(${PYWRAP}_cppadcg PROPERTIES CXX_VISIBILITY_PRESET default)
193+
endif()
194+
186195
# CPPAD_DEBUG_AND_RELEASE allow to mix debug and release versions of CppAD in the same program.
187196
target_compile_definitions(
188197
${PYWRAP}_cppadcg PRIVATE PYCPPAD_EXCLUDE_EIGEN_NUMTRAITS_SPECIALIZATION
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#! /usr/bin/env python3
2+
# Find common dynamics public symbols between shared libraries.
3+
4+
import argparse
5+
import itertools
6+
import pathlib
7+
import subprocess
8+
import typing
9+
10+
11+
def generate_symbols(shared_library: pathlib.Path) -> typing.Set[str]:
12+
# Show symbol
13+
# -D: Dynamic
14+
# -C: Demangled
15+
# -U: Defined
16+
# -W: Non weak
17+
result = subprocess.run(
18+
["nm", "-DCUW", "--format=sysv", str(shared_library)],
19+
capture_output=True,
20+
text=True,
21+
)
22+
output = result.stdout
23+
lines_split = (line.split("|") for line in output.splitlines() if "|" in line)
24+
# Only keep lines with exported (upper case) symbols.
25+
# `u` is also a global symbol, but if we always build with compatible libraries,
26+
# there is no issue to find it in many places.
27+
return set([line[0].strip() for line in lines_split if line[2].strip().isupper()])
28+
29+
30+
if __name__ == "__main__":
31+
parser = argparse.ArgumentParser(
32+
prog="common_symbol",
33+
description="Find common dynamics public symbols between shared libraries.",
34+
)
35+
parser.add_argument("shared_libraries", nargs="+", type=pathlib.Path)
36+
37+
args = parser.parse_args()
38+
symbols = [
39+
(shared_library, generate_symbols(shared_library))
40+
for shared_library in args.shared_libraries
41+
]
42+
43+
for lib1, lib2 in itertools.combinations(symbols, 2):
44+
print(f"Common symbols between {lib1[0]} and {lib2[0]}")
45+
common_symbols = lib1[1].intersection(lib2[1])
46+
for common in common_symbols:
47+
print(f"\t{common}")
48+
print()

include/pinocchio/algorithm/contact-cholesky.hpp

+12-32
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ namespace pinocchio
104104
///
105105
/// \brief Default constructor
106106
///
107-
ContactCholeskyDecompositionTpl()
108-
{
109-
}
107+
ContactCholeskyDecompositionTpl() = default;
110108

111109
///
112110
/// \brief Constructor from a model.
@@ -463,35 +461,10 @@ namespace pinocchio
463461
///@}
464462

465463
template<typename S1, int O1>
466-
bool operator==(const ContactCholeskyDecompositionTpl<S1, O1> & other) const
467-
{
468-
bool is_same = true;
469-
470-
if (nv != other.nv || num_contacts != other.num_contacts)
471-
return false;
472-
473-
if (
474-
D.size() != other.D.size() || Dinv.size() != other.Dinv.size() || U.rows() != other.U.rows()
475-
|| U.cols() != other.U.cols())
476-
return false;
477-
478-
is_same &= (D == other.D);
479-
is_same &= (Dinv == other.Dinv);
480-
is_same &= (U == other.U);
481-
482-
is_same &= (parents_fromRow == other.parents_fromRow);
483-
is_same &= (nv_subtree_fromRow == other.nv_subtree_fromRow);
484-
is_same &= (last_child == other.last_child);
485-
// is_same &= (rowise_sparsity_pattern == other.rowise_sparsity_pattern);
486-
487-
return is_same;
488-
}
464+
bool operator==(const ContactCholeskyDecompositionTpl<S1, O1> & other) const;
489465

490466
template<typename S1, int O1>
491-
bool operator!=(const ContactCholeskyDecompositionTpl<S1, O1> & other) const
492-
{
493-
return !(*this == other);
494-
}
467+
bool operator!=(const ContactCholeskyDecompositionTpl<S1, O1> & other) const;
495468
PINOCCHIO_COMPILER_DIAGNOSTIC_POP
496469

497470
protected:
@@ -702,10 +675,17 @@ namespace pinocchio
702675

703676
} // namespace pinocchio
704677

705-
#include "pinocchio/algorithm/contact-cholesky.hxx"
706-
678+
// Because of a GCC bug we should NEVER define a function that use ContactCholeskyDecompositionTpl
679+
// before doing the explicit template instantiation.
680+
// If we don't take care, GCC will not accept any visibility attribute when declaring the
681+
// explicit template instantiation of the ContactCholeskyDecompositionTpl class.
682+
// The warning message will look like this: type attributes ignored after type is already defined
683+
// [-Wattributes] A minimal code example is added on the PR
684+
// (https://github.com/stack-of-tasks/pinocchio/pull/2469)
707685
#if PINOCCHIO_ENABLE_TEMPLATE_INSTANTIATION
708686
#include "pinocchio/algorithm/contact-cholesky.txx"
709687
#endif // PINOCCHIO_ENABLE_TEMPLATE_INSTANTIATION
710688

689+
#include "pinocchio/algorithm/contact-cholesky.hxx"
690+
711691
#endif // ifndef __pinocchio_algorithm_contact_cholesky_hpp__

include/pinocchio/algorithm/contact-cholesky.hxx

+35
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,41 @@ namespace pinocchio
625625
return res;
626626
}
627627

628+
template<typename Scalar, int Options>
629+
template<typename S1, int O1>
630+
bool ContactCholeskyDecompositionTpl<Scalar, Options>::operator==(
631+
const ContactCholeskyDecompositionTpl<S1, O1> & other) const
632+
{
633+
bool is_same = true;
634+
635+
if (nv != other.nv || num_contacts != other.num_contacts)
636+
return false;
637+
638+
if (
639+
D.size() != other.D.size() || Dinv.size() != other.Dinv.size() || U.rows() != other.U.rows()
640+
|| U.cols() != other.U.cols())
641+
return false;
642+
643+
is_same &= (D == other.D);
644+
is_same &= (Dinv == other.Dinv);
645+
is_same &= (U == other.U);
646+
647+
is_same &= (parents_fromRow == other.parents_fromRow);
648+
is_same &= (nv_subtree_fromRow == other.nv_subtree_fromRow);
649+
is_same &= (last_child == other.last_child);
650+
// is_same &= (rowise_sparsity_pattern == other.rowise_sparsity_pattern);
651+
652+
return is_same;
653+
}
654+
655+
template<typename Scalar, int Options>
656+
template<typename S1, int O1>
657+
bool ContactCholeskyDecompositionTpl<Scalar, Options>::operator!=(
658+
const ContactCholeskyDecompositionTpl<S1, O1> & other) const
659+
{
660+
return !(*this == other);
661+
}
662+
628663
namespace details
629664
{
630665

pixi.lock

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pixi.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ casadi = { features = ["casadi", "py312"], solve-group = "py312" }
175175
autodiff = { features = ["autodiff", "py312"], solve-group = "py312" }
176176
extra = { features = ["extra", "py312"], solve-group = "py312" }
177177
openmp = { features = ["openmp", "py312"], solve-group = "py312" }
178-
codegen = { features = ["codegen", "py312"], solve-group = "py312" }
178+
# codegen need autodiff
179+
codegen = { features = ["autodiff", "codegen", "py312"], solve-group = "py312" }
179180
mpfr = { features = ["mpfr", "py312"], solve-group = "py312" }
180181
sdf = { features = ["sdf", "py312"], solve-group = "py312" }
181182
py39 = { features = ["py39"], solve-group = "py39" }

src/CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ function(PINOCCHIO_TARGET target_name)
9797
${LIB_NAME}
9898
PROPERTIES LINKER_LANGUAGE CXX
9999
INSTALL_RPATH "\$ORIGIN"
100-
VERSION ${PROJECT_VERSION})
100+
VERSION ${PROJECT_VERSION}
101+
CXX_VISIBILITY_PRESET hidden
102+
VISIBILITY_INLINES_HIDDEN ON)
101103
endif()
102104

103105
if(ENABLE_TEMPLATE_INSTANTIATION AND NOT ARGS_INTERFACE)

0 commit comments

Comments
 (0)