ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

How does the ROS2 DDS Shared Library get loaded in rclpy?

asked 2020-05-17 13:23:14 -0500

dawonn_haval gravatar image

updated 2020-05-17 17:35:28 -0500

I'm trying to understand how the DDS shared library is loaded by rclpy->rcl->rmw, and have hit a stumbling point:

It appears that rclpy_init() calls rcl_init() which calles rmw_init() and that function will load the shared library.

My confusion is that two lines above the call to rcl_init(); It appears that rcl_init_options_init() calls rmw_init_options_init() which is located in the shared library, that shouldn't be loaded yet...

What am I missing here?

I think I confirmed that the shared library is loaded before reaching rmw_init by placing some log_info() statements in rmw_fastrtps_shared_cpp / rmw_init_options_init().

$ ros2 topic info -v /str1 --no-daemon
[INFO] [1589753151.364450457] []: >>> rcl_init_options_init
[INFO] [1589753151.364512790] []: >>> rmw_init_options_init
[INFO] [1589753151.364525402] []: >>> rcl_init_options_init
[INFO] [1589753151.364531202] []: >>> rmw_init_options_init
[INFO] [1589753151.364552913] []: >>> rclpy_init pre rmw_init
[INFO] [1589753151.364607009] []: >>> rmw_init

How is rmw_init_options_init() loaded from the rmw implementation shared library before the shared library is loaded in rmw_init()???

I added a trace to rmw_implementation/ function.cpp, and was pleasantly surprised to see that something is loading the function just before it is called: pastebin output

So, what's causing get_symbol() to be called?

The CALL_SYMBOL macro seems to indicate that it's responsible, but I'm not yet sure how...

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-05-17 20:46:42 -0500

dawonn_haval gravatar image

I finally get it...

The RMW_INTERFACE_FN macro creates a function that implements each of the rmw functions and a pointer to the shared library function symbol_{function_name}, based on the list of functions directly below it. Each function expands the CALL_SYMBOL macro inside of it.

The the CALL_SYMBOL macro will get the pointer to the function in the shared library with get_symbol() and assign the address to the pointer. If no matching symbol is found, an error is returned. If the symbol is found, it will call the shared library function.

get_symbol() will get a reference to the shared library, via get_library() which loads the .so file based on the RMW_IMPLEMENTATION environment variable.

rmw_init() was hijacked to 'prefetch' all of the other functions in the library before calling the real rmw_init() function. There's a comment that this was done to avoid a race condition due to allocating an std::string. This is what made me mistakenly think that rmw_init() was responsible for loading all the symbols.

Case Closed. :)

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2020-05-17 13:23:14 -0500

Seen: 203 times

Last updated: May 17 '20