Repository navigation
fix: export CallbackGroup destructor symbol with default visibility - #17
Conversation
The t4-main branch does not have an explicit destructor declaration for
rclcpp::CallbackGroup, unlike the upstream humble branch. This causes
the compiler to generate an implicit destructor with hidden visibility
(due to -fvisibility=hidden), which means librclcpp.so does not export
the _ZN6rclcpp13CallbackGroupD1Ev symbol.
This is not a problem for most packages because they create
CallbackGroup instances through Node::create_callback_group(), which
internally calls std::make_shared<CallbackGroup> inside librclcpp.so.
The destructor reference stays within librclcpp.so and resolves fine
even when the symbol is hidden.
However, agnocast (libagnocast.so) directly constructs CallbackGroup
via std::make_shared<rclcpp::CallbackGroup>() in its own NodeBase
implementation. This generates an external symbol reference to the
destructor in libagnocast.so, which cannot be resolved at runtime
because librclcpp.so does not export it, resulting in:
symbol lookup error: libagnocast.so: undefined symbol:
_ZN6rclcpp13CallbackGroupD1Ev
This commit adds an explicit destructor with RCLCPP_PUBLIC
(visibility("default")) to match the upstream humble branch, ensuring
the symbol is exported from librclcpp.so.
There was a problem hiding this comment.
Pull request overview
This pull request fixes a runtime undefined symbol error by adding an explicit destructor with default visibility to the rclcpp::CallbackGroup class. The t4-main branch was missing this destructor that exists in the upstream humble branch, causing executables linked against libraries that directly construct CallbackGroup objects to fail at startup with symbol lookup errors.
Changes:
- Added explicit destructor declaration with
RCLCPP_PUBLICvisibility toCallbackGroupclass - Added empty destructor implementation to match the
t4-mainbranch's functionality
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| rclcpp/include/rclcpp/callback_group.hpp | Declares public destructor with RCLCPP_PUBLIC macro for symbol export |
| rclcpp/src/rclcpp/callback_group.cpp | Implements empty destructor body (appropriate for t4-main branch) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@atsushi421 |
|
I considered cherry-picking the entire PR ros2#1640, but decided to keep this change minimal for the following reasons:
If the |
fix: export CallbackGroup destructor symbol with default visibility
Summary
The
t4-mainbranch is missing an explicit destructor forrclcpp::CallbackGroupthat exists in the upstreamrollingbranch. This causes a runtimeundefined symbolerror at shutdown in executables linked againstlibagnocast.so:Demangled:
rclcpp::CallbackGroup::~CallbackGroup()Erros in Evaluator: https://evaluation.tier4.jp/evaluation/reports/cad22fd6-60d2-59f0-9c46-61e9be2f6342/tests/146a5fc6-8aa2-528a-8dcb-932941615908/f8013b02-ccd3-5a5c-ba33-67887994c083/348f1e62-6277-5aa5-8332-4f7b4b0f550d?project_id=autoware_dev
Root Cause
Missing explicit destructor in
t4-main/opt/ros/rolling)t4-main)callback_group.hpp)RCLCPP_PUBLIC ~CallbackGroup();callback_group.cpp)CallbackGroup::~CallbackGroup() {}librclcpp.sosymbolT _ZN6rclcpp13CallbackGroupD1Ev(exported)rclcpp uses
RCLCPP_PUBLIC(__attribute__((visibility("default")))) to control symbol visibility. Without an explicitRCLCPP_PUBLICdestructor, the compiler generates an implicit destructor that is hidden by the default-fvisibility=hiddenflag, solibrclcpp.sodoes not export it.Why this causes a failure
Both
librclcpp.soandlibagnocast.socallstd::make_shared<rclcpp::CallbackGroup>(), which instantiates the template classstd::_Sp_counted_ptr_inplace<CallbackGroup>and its virtual method_M_dispose()(the deleter that callsCallbackGroup::~CallbackGroup()). These template instantiations are emitted as weak symbols (vague linkage) in each library.The two libraries'
_M_dispose()implementations differ in how they reference the destructor:librclcpp.solibagnocast.so_Sp_counted_ptr_inplace<CallbackGroup>::_M_dispose()CallbackGroup::~CallbackGroup()_Sp_counted_ptr_inplace<CallbackGroup>Normally, GCC propagates
visibility("hidden")from a type to its template instantiations, which would prevent interposition. However,_Sp_counted_ptr_inplace<CallbackGroup>is emitted with default visibility in both libraries. This is because libstdc++ defines_Sp_counted_ptr_inplaceand its base class_Sp_counted_baseunder#pragma GCC visibility push(default), andCallbackGrouphas individual members (constructor, public methods) markedRCLCPP_PUBLIC(visibility("default")) — giving the type effective default visibility. Note thatRCLCPP_PUBLICis on individual members, not on theclass CallbackGroupdeclaration itself. Only the implicit destructor, which lacks an explicitRCLCPP_PUBLICdeclaration, falls back to hidden visibility under-fvisibility=hidden. This mismatch makes the control block subject to dynamic linker interposition while the destructor it calls remains unexportable.When
libagnocast.sois loaded beforelibrclcpp.soin the dynamic linker's search order, the linker pickslibagnocast.so's definitions for the vtable and_M_dispose():This means the error occurs even when
agnocast::Nodeis never used — anyshared_ptr<CallbackGroup>created by the standardrclcpp::NodeAPI is affected, because the vtable interposition redirects all destructor calls throughlibagnocast.so.Why other packages are not affected
Other packages create
CallbackGroupinstances through the standard rclcpp API:This calls
rclcpp::node_interfaces::NodeBase::create_callback_group(), which internally callsstd::make_shared<rclcpp::CallbackGroup>()insidelibrclcpp.so. Since these packages do not themselves callmake_shared<CallbackGroup>(), they do not instantiate_Sp_counted_ptr_inplace<CallbackGroup>and therefore do not introduce competing weak symbols.A search across the entire workspace confirms that agnocast is the only package outside of
librclcpp.sothat directly constructsCallbackGroupviastd::make_shared(all other packages usenode->create_callback_group()).Fix
Add an explicit destructor with
RCLCPP_PUBLICvisibility, matching the upstreamhumblebranch:RCLCPP_PUBLIC ~CallbackGroup();CallbackGroup::~CallbackGroup() {}This ensures
librclcpp.soexports the destructor symbol. Even when interposition causeslibagnocast.so's_M_dispose()to be used, the PLT lookup succeeds because the symbol is now inlibrclcpp.so's dynamic symbol table.Note: The upstream
humbledestructor callstrigger_notify_guard_condition(), butt4-maindoes not have that functionality, so the destructor body is intentionally empty.Test plan
librclcpp.soexports the destructor symbol:nm -D librclcpp.so | grep CallbackGroupDlibagnocast.solaunch without theundefined symbolerror: https://evaluation.tier4.jp/evaluation/reports/e1c0985a-1a42-5e70-902a-526bf46ebf3c?project_id=autoware_dev