Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -Wl,--no-undefined to make compilation of components fail if a symbol is not defined? #10

Open
3 tasks done
VRichardJP opened this issue Jul 29, 2024 · 0 comments
Open
3 tasks done

Comments

@VRichardJP
Copy link

VRichardJP commented Jul 29, 2024

Checklist

  • I've read the contribution guidelines.
  • I've searched other issues and no duplicate issues were found.
  • I've agreed with the maintainers that I can plan this task.

Description

Autoware relies a lot on ROS2 components, which are nothing but shared library.
Because it is totally fine for a shared library to contain undefined symbols, the linker won't complain if it is the case at compilation time.
However, if you try to load into a ROS2 container a component with undefined symbols at runtime, then your application will crash.

Not catching undefined symbols when compiling components is thus quite annoying.
One solution is to add tests or to link it to a binary, but this means extra compilation time.
Another simple solution is to pass -Wl,--no-undefined to the target libraries.

For example, I have commented a function definition in gnss_poser_node.cpp, then I have added the following line to autoware_cmake:

# DIRTY? add -Wl,--no-undefined to *ALL* shared libraries
add_link_options(
      "$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,SHARED_LIBRARY>:LINKER:--no-undefined>")

With this extra flag, I get the following compilation error:

/home/sig/autoware/src/universe/autoware.universe/sensing/gnss_poser/src/gnss_poser_core.cpp:46: undefined reference to `gnss_poser::GNSSPoser::callbackMapProjectorInfo(std::shared_ptr<tier4_map_msgs::msg::MapProjectorInfo_<std::allocator<void> > const>)'
collect2: error: ld returned 1 exit status

Whereas without the flag no error is reported (but the application would crash at runtime).

Purpose

Detect broken components at compilation time

Possible approaches

Add the flag to all shared libraries:
add_link_options("$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,SHARED_LIBRARY>:LINKER:--no-undefined>")

Or add target_link_options(tgt PRIVATE LINKER:--no-undefined) to individual components.

Definition of done

Depend on chosen solution

@VRichardJP VRichardJP changed the title Add -Wl,--no-undefined to make compilation of shared library fail if a symbol is not defined? Add -Wl,--no-undefined to make compilation of components fail if a symbol is not defined? Jul 29, 2024
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

No branches or pull requests

1 participant