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 a cmake option to activate address sanitizers #146

Merged
merged 3 commits into from
Jul 13, 2023

Conversation

fmauch
Copy link
Collaborator

@fmauch fmauch commented Apr 27, 2023

In an effort to track down memory issues, I started activating address sanitizers on the urcl. I think, we should activate them by default inside CI in order to spot issues early on.

@fmauch fmauch self-assigned this Apr 27, 2023
@fmauch fmauch force-pushed the address_sanitizer branch 2 times, most recently from 1c7d3f4 to 5277534 Compare April 27, 2023 13:15
@codecov
Copy link

codecov bot commented Apr 27, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.42 ⚠️

Comparison is base (a1e514c) 70.62% compared to head (9f852b8) 70.21%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #146      +/-   ##
==========================================
- Coverage   70.62%   70.21%   -0.42%     
==========================================
  Files          69       69              
  Lines        2526     2521       -5     
  Branches      321      321              
==========================================
- Hits         1784     1770      -14     
- Misses        562      567       +5     
- Partials      180      184       +4     
Impacted Files Coverage Δ
include/ur_client_library/rtde/rtde_package.h 100.00% <ø> (ø)
include/ur_client_library/comm/bin_parser.h 89.55% <100.00%> (+0.32%) ⬆️

... and 11 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@fmauch fmauch marked this pull request as ready for review June 1, 2023 09:51
CMakeLists.txt Outdated
Comment on lines 12 to 15
if(WITH_ASAN)
add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)
endif()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not a big fan of setting these flags globally, especially for libraries. I think

target_compile_options(urcl PRIVATE -fsanitize=address)
target_link_options(urcl PRIVATE -fsanitize=address)

would be the better choice.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In principle I would agree. However, using this inside the main CMakeLists.txt

...
add_library(ur_client_library::urcl ALIAS urcl)
if(WITH_ASAN)
  target_compile_options(urcl PRIVATE -fsanitize=address)
  target_link_options(urcl PRIVATE -fsanitize=address)
endif()
target_compile_options(urcl PRIVATE -Wall -Wextra -Wno-unused-parameter)
target_compile_options(urcl PUBLIC ${CXX17_FLAG})
...

leads to this (without further modifications)

build/examples/dashboard_example 192.168.56.101
==416292==ASan runtime does not come first in initial library list; you should either link runtime to your application or manually preload it with LD_PRELOAD.

So, one has to add the targeted sanitizer to each target, as the targets depending on urcl won't work (won't run) otherwise. Since from a maintenance perspective it seems not right to copy those four lines to each of our many targets I would suggest sticking with the global flag. It should only be activated manually for testing purposes, so I guess, this would be valid price to pay.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you try using

  target_compile_options(urcl PUBLIC -fsanitize=address)
  target_link_options(urcl PUBLIC -fsanitize=address)

instead? From my understanding that should serve exactly this role, e.g. propagating to all targets linking to urcl.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds like a sane idea, will try that.

@fmauch fmauch force-pushed the address_sanitizer branch 2 times, most recently from 81a3157 to 277c323 Compare June 30, 2023 14:43
@fmauch fmauch added this to the Release 1.3.2 milestone Jul 8, 2023
We keep a pointer to the raw data buffer received from the comm interfaces
in our packages. This was held as a unique_ptr<uint8_t> while we were storing
a uint8_t type inside. This commit changes the pointer's type to the correct
one.
test_tcp_server had a memory leak by not deleting manually allocated clients.
@fmauch
Copy link
Collaborator Author

fmauch commented Jul 12, 2023

@RobertWilbrandt I've updated the PR using targeted compile options. This should now probably be fine for merging

@RobertWilbrandt RobertWilbrandt merged commit 9a59e81 into UniversalRobots:master Jul 13, 2023
15 of 17 checks passed
@fmauch fmauch deleted the address_sanitizer branch July 13, 2023 13:26
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.

None yet

2 participants