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

cmd: add support for building with address and undefined behavior sanitizers #15059

Merged
merged 6 commits into from
Feb 18, 2025

Conversation

bboozzoo
Copy link
Contributor

@bboozzoo bboozzoo commented Feb 11, 2025

The branch builds on #15045 and adds support for building with asan and ubsan. This is only useful for testing local installation or running unit tests, as otherwise we'd have to ship libasan/libubsan in the snapd snap to make it universally useful in all scenarios.

Note, some binaries which are linked statically, snap-gdb*-shim specifically, had to be skipped, since libasan relies on dlopen().

@bboozzoo bboozzoo added the Skip spread Indicate that spread job should not run label Feb 11, 2025
@bboozzoo bboozzoo closed this Feb 11, 2025
@bboozzoo bboozzoo reopened this Feb 11, 2025
Copy link

github-actions bot commented Feb 11, 2025

Tue Feb 18 12:09:09 UTC 2025

Spread tests skipped

Copy link

codecov bot commented Feb 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.13%. Comparing base (a272aac) to head (76dfa04).
Report is 18 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #15059      +/-   ##
==========================================
+ Coverage   78.07%   78.13%   +0.06%     
==========================================
  Files        1182     1172      -10     
  Lines      157743   157622     -121     
==========================================
+ Hits       123154   123156       +2     
+ Misses      26943    26823     -120     
+ Partials     7646     7643       -3     
Flag Coverage Δ
unittests 78.13% <ø> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bboozzoo bboozzoo marked this pull request as ready for review February 11, 2025 18:21
@bboozzoo bboozzoo removed the Skip spread Indicate that spread job should not run label Feb 11, 2025
@bboozzoo bboozzoo closed this Feb 11, 2025
@bboozzoo bboozzoo reopened this Feb 11, 2025
@@ -319,6 +319,20 @@ AS_IF([test "x$with_unit_tests" = "xyes"], [
AX_APPEND_COMPILE_FLAGS([-Werror], [CHECK_CFLAGS])
])

AC_ARG_ENABLE([sanitize],
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is only using asan at the moment, would it be better to just call it asan rather than sanitize?

Copy link
Contributor

@alexmurray alexmurray left a comment

Choose a reason for hiding this comment

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

LGTM but I think perhaps a better option name should be chosen that is more self-explanatory than just sanitize (plus I expect woke etc will complain about the use of the term sanitize as well)

@bboozzoo
Copy link
Contributor Author

LGTM but I think perhaps a better option name should be chosen that is more self-explanatory than just sanitize (plus I expect woke etc will complain about the use of the term sanitize as well)

Do you think it makes sense to add ubsan too, even if for unit tests only?

@alexmurray
Copy link
Contributor

Do you think it makes sense to add ubsan too, even if for unit tests only?

Sure, the more the merrier particularly if its just the unit tests.

@bboozzoo bboozzoo changed the title cmd: add support for building with address sanitizer cmd: add support for building with address and undefined behavior sanitizers Feb 14, 2025
@bboozzoo bboozzoo added the Skip spread Indicate that spread job should not run label Feb 14, 2025
@bboozzoo bboozzoo closed this Feb 14, 2025
@bboozzoo bboozzoo reopened this Feb 14, 2025
Copy link
Contributor

@zyga zyga left a comment

Choose a reason for hiding this comment

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

This all looks good so far. I don't have any high-level comments.

endif

##
## snap-gdb-shim
##

if !ENABLE_SANITIZE
Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose you do not add SANITIZE_* to snap_gdb_shim_snap_gdb_shim_*. So that would still build, right? Is it just to disable what we are not testing here?

Copy link
Contributor

Choose a reason for hiding this comment

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

If it is so, we should maybe document in the AS_HELP_STRING of --enable-sanitize that it gives a partial build.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bit of both. We don't test it and it won't build. Even with -static-libasan dlopen() is retained for some reason. I guess it just makes libasan parts to be linked statically, but still relies on hijacking libc's malloc dynamically.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've tweaked the help message.

Add support for building C code with address
sanitizer (-fsanitize=address).

Signed-off-by: Maciej Borzecki <[email protected]>
@bboozzoo bboozzoo merged commit b37e8f6 into canonical:master Feb 18, 2025
80 checks passed
@bboozzoo bboozzoo deleted the bboozzoo/asan branch February 18, 2025 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Skip spread Indicate that spread job should not run
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants