After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 761429 - Add support for building NM with GCC and Clang sanitizers
Add support for building NM with GCC and Clang sanitizers
Status: RESOLVED FIXED
Product: NetworkManager
Classification: Platform
Component: general
git master
Other Linux
: Normal enhancement
: ---
Assigned To: NetworkManager maintainer(s)
NetworkManager maintainer(s)
Depends on:
Blocks: nm-patch
 
 
Reported: 2016-02-01 21:05 UTC by Beniamino Galvani
Modified: 2016-06-03 20:49 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Beniamino Galvani 2016-02-01 21:05:19 UTC
Recent GCC and Clang versions can compile applications with runtime
checks for some programming errors as bad memory accesses, undefined
behaviors, memory leaks, etc.

Maybe it would be useful to provide configure options to enable such
features (--enable-address-sanitizer, --enable-undefined-sanitizer, ?).

The address sanitizer could replace the usage of valgrind when running
the test suite since it's faster and can detect a broader range of
errors.

https://github.com/google/sanitizers
http://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html
Comment 1 Beniamino Galvani 2016-04-09 12:16:41 UTC
Pushed bg/asan-bgo761429, please review.
Comment 2 Thomas Haller 2016-04-11 23:04:24 UTC
pushed one fixup.

There seems to be memory leaks in ifupdown tests.
Comment 3 Beniamino Galvani 2016-04-14 13:45:27 UTC
(In reply to Thomas Haller from comment #2)
> pushed one fixup.

Looks good.

> There seems to be memory leaks in ifupdown tests.

I've added some commits to fix the leaks in 'make check'.
Comment 4 Thomas Haller 2016-04-14 14:12:22 UTC
Could you reorder the commits, to first fix the tests and then enable the sanitizer?

The libnm-util/tests/test-libnm-linking test never terminates and breaks tests.
Comment 5 Thomas Haller 2016-04-14 14:15:37 UTC
(In reply to Thomas Haller from comment #4)

> The libnm-util/tests/test-libnm-linking test never terminates and breaks
> tests.

It's because g_error is no longer working as expected to abort the program... that is also bad for other tests, because we use that commonly to denote a fatal failure (in tests).

Unless easily fixable, we could re-define g_error in nm-glib.h.
Comment 6 Beniamino Galvani 2016-04-14 14:29:40 UTC
(In reply to Thomas Haller from comment #5)
> (In reply to Thomas Haller from comment #4)
> 
> > The libnm-util/tests/test-libnm-linking test never terminates and breaks
> > tests.
> 
> It's because g_error is no longer working as expected to abort the
> program... that is also bad for other tests, because we use that commonly to
> denote a fatal failure (in tests).
> 
> Unless easily fixable, we could re-define g_error in nm-glib.h.

Mmh, it's working here. Can you check if you have something trying to write a core file for the failed program (like systemd-coredump or abrt)? Since the program is built with address sanitizer, its address space should be very big and the dump can take a long time.
Comment 7 Thomas Haller 2016-04-14 16:26:11 UTC
I had abrt running, so the coredump didn't take so long it never finished.

After uninstalling abrt, systemd-coredump takes over. That one is faster, but still taking 12 seconds.


Can we do something to avoid writing these core dumps?
Comment 8 Beniamino Galvani 2016-04-19 12:28:02 UTC
(In reply to Thomas Haller from comment #7)
> Can we do something to avoid writing these core dumps?

Apart from setting RLIMIT_CORE to 0 (which we already do, see
_test_libnm_linking_setup_child_process in test-general.c), I suspect
there is nothing that can be done.

systemd (but only from v229) honors such setting and won't generate a
core dump when the limit is set to 0. abrt instead uses RLIMIT_CORE
only to decide whether a core dump should be generated in the working
directory (but will process the dump anyway).

So the only solution for now is to disable core dumps globally.
Comment 9 Thomas Haller 2016-04-19 20:34:23 UTC
(In reply to Beniamino Galvani from comment #8)
> (In reply to Thomas Haller from comment #7)

> So the only solution for now is to disable core dumps globally.

That is a bit unsatisfying, but well.

Could you somewhere add a comment about this? Maybe in configure.ac around the --enable-*-sanitizer configure flag?


Another question I had, is why did you add two separate flags and not just one --enable-sanitizer?


Anyway, branch looks good to me as is.
Comment 10 Beniamino Galvani 2016-05-19 12:32:05 UTC
(In reply to Thomas Haller from comment #9)
> Could you somewhere add a comment about this? Maybe in configure.ac around
> the --enable-*-sanitizer configure flag?

Done.

> Another question I had, is why did you add two separate flags and not just
> one --enable-sanitizer?

The two were added in different GCC versions and thus it's possible
that someone wants to use only the address sanitizer but not the
undefined one.

> Anyway, branch looks good to me as is.

I admit that it's a bit hacky but the cause is that we compile libnm
with -fsanitize and this has the disadvantage that every application
linking against it must be either compiled with -fsanitize or
preload the asan shared object through LD_PRELOAD; otherwise it will
refuse to load.

So, an alternative is to remove the -fsanitize flags when compiling
libnm/ (and thus also libnm-core/ and introspection/) and enable it
only in the core (and maybe clients). This will simpler, as clients
don't need to preload the library (and Makefiles don't need all the
hacks), but the libnm library code will not be checked. What do you
think?
Comment 11 Beniamino Galvani 2016-05-20 08:03:19 UTC
Dropped the import of attributes.m4 and extended the existing m4/compiler_options.m4. Also, disabled the linking test when using asan.

Repushed bg/asan-bgo761429.
Comment 12 Beniamino Galvani 2016-05-20 13:50:53 UTC
After discussion on IRC, re-imported attributes.m4. The plan is to replace our custom compiler macros with ones from the new file, but that can be done later as a separate work.
Comment 13 Lubomir Rintel 2016-06-01 11:40:32 UTC
+1

I'm fine with this as it is.