On 07.09.2019 01:07, Kamil Rytarowski wrote: > On 07.09.2019 00:41, Thomas Klausner wrote: >> On Sat, Sep 07, 2019 at 12:36:49AM +0200, Kamil Rytarowski wrote: >>> Sanitizing compiler is available without MKSANITIZER. >> >> I tried (on 9.99.10 from Aug 26): >> >> wiz@yt:~> clang -fsanitize=address -g memory-leak.c >> wiz@yt:~> ASAN_OPTIONS=detect_leaks=1 ./a.out >> ==16509==AddressSanitizer: detect_leaks is not supported on this platform. >> > > The version of Clang/LLVM in base as of today (clang 7.x, compiler-rt > 8.x) does not support LSan/NetBSD. > > LSan/NetBSD is supported in Clang/LLVM 9.0.0. > > Michal Gorny works on porting LLVM 9.0.0 to the base in this moment. > > As an intermediate step we have updated to LLVM 8.x and NetBSD-current > from HEAD. > > https://github.com/mgorny/netbsd-src/tree/llvm8 > > Next step is to update to Clang/LLVM 9.0.0 prerelease snapshot, the > final release of 9.0.0 is still not formally out. > > NB. LSan in LLVM 9.0.0 will have one flaw on NetBSD. It will report > false positives in strict detection of leaks on process termination. > This functionality is called from an atexit(3) callback, and the > callback is fired from libc and before freeing memory of it. > > There is need to invent a solution to this false-positive. > >>> libutil is built with a sanitizer. >>> >>> This means that the code in libutil is instrumented and contains calls >>> to sanitizer runtime. >>> >>> The runtime is linked into programs, not libraries. >>> >>> This means that there is need to build each program in this setup with a >>> sanitizer. >> >> Ok, thanks for the explanation. >> > > There are some alternative approaches, but I don't want to make things more complex here. > >>> Every application that dynamically links with an instrumented library >>> has to be prebuilt with a sanitizer. >>> >>>> Do I have to recompile all of pkgsrc, and if yes, why? >>> >>> Basically yes, there is need to recompile all of pkgsrc. >> >> Do I need to use any particular settings or will this automatically >> work in such a userland? >> > > If we want to combine pkgsrc with a MKSANITIZER host, we want to reuse > the same CPPFLAGS, CFLAGS, CXXFLAGS and LDFLAGS as in basesystem. > > This is by default: > > CPPFLAGS=-D_REENTRANT > CFLAGS=-fsanitize=address > CXXFLAGS=-fsanitize=address > LDFLAGS=-fsanitize=address > >>> However ASan and UBSan can be often used on the top of non-sanitized >>> libraries and this will work decently finding problems in an >>> application, but skipping issues called in libraries. >>> >>> MSan and TSan are more sensitive here and need full sanitization. >> >> I'm currently mostly interested in the leak sanitizer. >> But perhaps that's not available yet, or at least not in 9.99.10? >> Thomas >> > > I could backport LSan/LLVM for NetBSD-9 if there would be a request. > However before that I would prefer to address the mentioned > false-positive from the atexit(3) callback. I have originally > rescheduled it for NetBSD-10. > > For LSan there is no need for MKSANITIZER as all free/malloc/similar > calls are intercepted always regardless of instrumenting the code. > > It's also possible to use -fsanitize=leak, without -fsanitize=address. > It's actually a better idea here if we want to catch only leaks as > ASan/NetBSD is still not perfect. >
Attachment:
signature.asc
Description: OpenPGP digital signature