Skip to content

add NO_UNDEFINED_SYMBOLS to rclcpp_components_register_node cmake macro#2746

Merged
ahcorde merged 4 commits intoros2:jazzyfrom
ottojo:feat/components/no_undefined_symbols_flag
Mar 7, 2025
Merged

add NO_UNDEFINED_SYMBOLS to rclcpp_components_register_node cmake macro#2746
ahcorde merged 4 commits intoros2:jazzyfrom
ottojo:feat/components/no_undefined_symbols_flag

Conversation

@ottojo
Copy link
Copy Markdown
Contributor

@ottojo ottojo commented Feb 14, 2025

this adds an option NO_UNDEFINED_SYMBOLS to the rclcpp_components_register_node cmake macro, which adds the required linker option to the (component library) target to deny undefined symbols.

Undefined symbols usually produce an error if an executable is built, but due to the way the autogenerated executable generated by rclcpp_components_register_node is constructed, that doesn't happen here, and the error occurs only when executing it.
This change makes this a link-time error again.

This is especially intended for the workflow of migrating a ros node which was built directly as an executable before to using rclcpp_components_register_node.

By default, the option is disabled. If no adverse impact is detected, i suggest enabling it by default in a future release.

fixes #2744

Signed-off-by: Jonas Otto <jonas.otto@ipa.fraunhofer.de>
@ottojo ottojo force-pushed the feat/components/no_undefined_symbols_flag branch from f4688b4 to d44b54d Compare February 14, 2025 17:02
@mjcarroll
Copy link
Copy Markdown
Member

I wonder if we should also use --no-allow-shlib-undefined?

@ottojo
Copy link
Copy Markdown
Contributor Author

ottojo commented Feb 18, 2025

I wonder if we should also use --no-allow-shlib-undefined?

Reading an article on this in the gentoo wiki, it seems this would be useful here, as long as there are no symbols that would only be provided by the container which loads the component. I did a quick test, and it seems that this is not the case, but i'm not very familiar with the plugin mechanism under the hood.

Signed-off-by: Jonas Otto <jonas.otto@ipa.fraunhofer.de>
@ottojo ottojo force-pushed the feat/components/no_undefined_symbols_flag branch from 4ff2c58 to 38656ac Compare February 18, 2025 17:02
Signed-off-by: Jonas Otto <jonas@jonasotto.com>
@ottojo ottojo requested a review from sloretz February 20, 2025 21:53
Copy link
Copy Markdown
Contributor

@sloretz sloretz left a comment

Choose a reason for hiding this comment

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

I'm not sure whether --no-allow-shlib-undefined should be included because I can't find docs for it, but approving because the code LGTM!

@ottojo
Copy link
Copy Markdown
Contributor Author

ottojo commented Feb 24, 2025

I'm not sure whether --no-allow-shlib-undefined should be included because I can't find docs for it, but approving because the code LGTM!

the ld(1) man page has docs:

       --no-allow-shlib-undefined
           Allows or disallows undefined symbols in shared libraries.
           This switch is similar to --no-undefined except that it
           determines the behaviour when the undefined symbols are in a
           shared library rather than a regular object file.  It does not
           affect how undefined symbols in regular object files are
           handled.

           The default behaviour is to report errors for any undefined
           symbols referenced in shared libraries if the linker is being
           used to create an executable, but to allow them if the linker
           is being used to create a shared library.

           The reasons for allowing undefined symbol references in shared
           libraries specified at link time are that:

           •   A shared library specified at link time may not be the
               same as the one that is available at load time, so the
               symbol might actually be resolvable at load time.

           •   There are some operating systems, eg BeOS and HPPA, where
               undefined symbols in shared libraries are normal.

               The BeOS kernel for example patches shared libraries at
               load time to select whichever function is most appropriate
               for the current architecture.  This is used, for example,
               to dynamically select an appropriate memset function.

@mjcarroll
Copy link
Copy Markdown
Member

Pulls: #2746
Gist: https://gist.githubusercontent.com/mjcarroll/a775e3c08b1a3c3ba2cec2f57da3734b/raw/69fb337a12405174b2594fe2a6f53629d137c83d/ros2.repos
BUILD args:
TEST args:
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/15300

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

Copy link
Copy Markdown
Member

@mjcarroll mjcarroll left a comment

Choose a reason for hiding this comment

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

LGTM with green CI

@ahcorde
Copy link
Copy Markdown
Contributor

ahcorde commented Mar 7, 2025

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

@ahcorde
Copy link
Copy Markdown
Contributor

ahcorde commented Mar 7, 2025

Pulls: #2746
Gist: https://gist.githubusercontent.com/ahcorde/9fb08b36a3b4cb4c6b84cd333e4908ba/raw/a8bb491b6cb1447ab79120b2b88ccd0136c0d290/ros2.repos
BUILD args: --packages-above-and-dependencies rclcpp
TEST args: --packages-above rclcpp
ROS Distro: jazzy
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/15305

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

@ahcorde
Copy link
Copy Markdown
Contributor

ahcorde commented Mar 7, 2025

Windows warnings are unrelated

@ahcorde ahcorde merged commit c31daa6 into ros2:jazzy Mar 7, 2025
3 checks passed
@ottojo ottojo deleted the feat/components/no_undefined_symbols_flag branch March 9, 2025 17:38
@christophebedard
Copy link
Copy Markdown
Member

Should this be backforwardported to Rolling?

@fujitatomoya
Copy link
Copy Markdown
Collaborator

@Mergifyio backport rolling

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Mar 11, 2025

backport rolling

✅ Backports have been created

Details

mergify bot pushed a commit that referenced this pull request Mar 11, 2025
…ro (#2746)

Signed-off-by: Jonas Otto <jonas.otto@ipa.fraunhofer.de>
Signed-off-by: Jonas Otto <jonas@jonasotto.com>
(cherry picked from commit c31daa6)
ahcorde pushed a commit that referenced this pull request Mar 11, 2025
…ro (#2746) (#2764)

Signed-off-by: Jonas Otto <jonas.otto@ipa.fraunhofer.de>
Signed-off-by: Jonas Otto <jonas@jonasotto.com>
(cherry picked from commit c31daa6)

Co-authored-by: Jonas Otto <jonas@jonasotto.com>
jplapp pushed a commit to pixel-robotics/rclcpp that referenced this pull request Apr 9, 2025
…ro (ros2#2746)

Signed-off-by: Jonas Otto <jonas.otto@ipa.fraunhofer.de>
Signed-off-by: Jonas Otto <jonas@jonasotto.com>
mojomex pushed a commit to mojomex/rclcpp that referenced this pull request Feb 16, 2026
…ro (ros2#2746)

Signed-off-by: Jonas Otto <jonas.otto@ipa.fraunhofer.de>
Signed-off-by: Jonas Otto <jonas@jonasotto.com>
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.

6 participants