Skip to content

fix: export CallbackGroup destructor symbol with default visibility - #17

Merged
Koichi98 merged 2 commits into
t4-mainfrom
fix/export-callback-group-destructor
Mar 10, 2026
Merged

Koichi98 merged 2 commits into
t4-mainfrom
fix/export-callback-group-destructor

Conversation

@atsushi421

@atsushi421 atsushi421 commented Feb 20, 2026 •

Copy link
Copy Markdown

Summary

The t4-main branch is missing an explicit destructor for rclcpp::CallbackGroup that exists in the upstream rolling branch. This causes a runtime undefined symbol error at shutdown in executables linked against libagnocast.so:

symbol lookup error: libagnocast.so: undefined symbol: _ZN6rclcpp13CallbackGroupD1Ev

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

System rclcpp (/opt/ros/rolling) Workspace rclcpp (t4-main)
Header (callback_group.hpp) RCLCPP_PUBLIC ~CallbackGroup(); No declaration (implicit destructor)
Source (callback_group.cpp) CallbackGroup::~CallbackGroup() {} No definition
librclcpp.so symbol T _ZN6rclcpp13CallbackGroupD1Ev (exported) Not exported (hidden visibility)

rclcpp uses RCLCPP_PUBLIC (__attribute__((visibility("default")))) to control symbol visibility. Without an explicit RCLCPP_PUBLIC destructor, the compiler generates an implicit destructor that is hidden by the default -fvisibility=hidden flag, so librclcpp.so does not export it.

Why this causes a failure

Both librclcpp.so and libagnocast.so call std::make_shared<rclcpp::CallbackGroup>(), which instantiates the template class std::_Sp_counted_ptr_inplace<CallbackGroup> and its virtual method _M_dispose() (the deleter that calls CallbackGroup::~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.so libagnocast.so
_Sp_counted_ptr_inplace<CallbackGroup>::_M_dispose() WEAK DEFAULT (exported) WEAK DEFAULT (exported)
CallbackGroup::~CallbackGroup() LOCAL (hidden) — direct call, no PLT U (undefined) — PLT call, needs dynamic resolution
vtable for _Sp_counted_ptr_inplace<CallbackGroup> WEAK DEFAULT (exported) WEAK DEFAULT (exported)

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_inplace and its base class _Sp_counted_base under #pragma GCC visibility push(default), and CallbackGroup has individual members (constructor, public methods) marked RCLCPP_PUBLIC (visibility("default")) — giving the type effective default visibility. Note that RCLCPP_PUBLIC is on individual members, not on the class CallbackGroup declaration itself. Only the implicit destructor, which lacks an explicit RCLCPP_PUBLIC declaration, 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.so is loaded before librclcpp.so in the dynamic linker's search order, the linker picks libagnocast.so's definitions for the vtable and _M_dispose():

1. Process starts; libagnocast.so is loaded before librclcpp.so
2. Dynamic linker interposes _Sp_counted_ptr_inplace<CallbackGroup>'s vtable
   → ALL instances (including those created inside librclcpp.so) use libagnocast.so's vtable
3. rclcpp::Node calls create_callback_group() → make_shared<CallbackGroup>() inside librclcpp.so
4. The shared_ptr's control block vtable points to libagnocast.so's _M_dispose()
5. At shutdown, shared_ptr is destroyed → vtable dispatches to libagnocast.so's _M_dispose()
6. libagnocast.so's _M_dispose() tries to resolve ~CallbackGroup() via PLT
7. librclcpp.so does not export this symbol (hidden) → symbol lookup error

This means the error occurs even when agnocast::Node is never used — any shared_ptr<CallbackGroup> created by the standard rclcpp::Node API is affected, because the vtable interposition redirects all destructor calls through libagnocast.so.

Why other packages are not affected

Other packages create CallbackGroup instances through the standard rclcpp API:

auto group = node->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);

This calls rclcpp::node_interfaces::NodeBase::create_callback_group(), which internally calls std::make_shared<rclcpp::CallbackGroup>() inside librclcpp.so. Since these packages do not themselves call make_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.so that directly constructs CallbackGroup via std::make_shared (all other packages use node->create_callback_group()).

Fix

Add an explicit destructor with RCLCPP_PUBLIC visibility, matching the upstream humble branch:

  • Header: Declare RCLCPP_PUBLIC ~CallbackGroup();
  • Source: Define CallbackGroup::~CallbackGroup() {}

This ensures librclcpp.so exports the destructor symbol. Even when interposition causes libagnocast.so's _M_dispose() to be used, the PLT lookup succeeds because the symbol is now in librclcpp.so's dynamic symbol table.

Note: The upstream humble destructor calls trigger_notify_guard_condition(), but t4-main does not have that functionality, so the destructor body is intentionally empty.

Test plan

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_PUBLIC visibility to CallbackGroup class
  • Added empty destructor implementation to match the t4-main branch'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.

@Koichi98

Copy link
Copy Markdown

@atsushi421
Have you considered cherry-picking the whole file changes in the upstream ros2 PR, not just about Default destructor?

ros2#1640

@atsushi421

Copy link
Copy Markdown
Author

I considered cherry-picking the entire PR ros2#1640, but decided to keep this change minimal for the following reasons:

  1. PR Fix bug that a callback not reached ros2/rclcpp#1640 changes the executor's guard condition management from node-level (WeakNodesToGuardConditionsMap) to callback-group-level (WeakCallbackGroupsToGuardConditionsMap), which is a significant behavioral change affecting executor.hpp/cpp, node_services.cpp, node_timers.cpp, node_topics.cpp, and node_waitables.cpp.
  2. t4-main's static_executor_entities_collector also uses WeakNodesToGuardConditionsMap, but PR Fix bug that a callback not reached ros2/rclcpp#1640 does not modify this file (it was likely handled separately or removed in the upstream rolling branch). Cherry-picking just Fix bug that a callback not reached ros2/rclcpp#1640 would leave the static executor in an inconsistent state.
  3. The purpose of this PR is to fix the agnocast undefined symbol error. Adding RCLCPP_PUBLIC visibility to an empty destructor is sufficient for that.

If the notify_guard_condition functionality is needed in the future, I think it would be better to bring in the related upstream changes together in a separate PR.

@Koichi98
Koichi98 merged commit 0fdf9ca into t4-main Mar 10, 2026
@Koichi98
Koichi98 deleted the fix/export-callback-group-destructor branch March 10, 2026 09:06
iwatake2222 pushed a commit that referenced this pull request Mar 26, 2026
fix: export CallbackGroup destructor symbol with default visibility
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants