Re: leak sanitizer support

From: rickygee <ricky_at_rickysquid.org>
Date: Sun, 02 Jan 2022 00:28:51 UTC
Hey Luoqi & Shawn,

This is really cool - I have been testing on -CURRENT, and just needed to change
one or two teeny little things and lsan is working in my hokey trivial examples
anyway. Only changes so far were matching the method signatures in the derived
SuspendedThreadsListFreeBSD class, to match its parent (actually the only sig so
far needed amending was GetRegistersAndSP, where second param is now more
complex type than before).

Anyway here is a remote with the patch applied and my tiny little amendments:
https://github.com/emgullufsen/freebsd.git

example from testing follows - create leaky code, compile, and run)

//CREATE LEAKY CODE - HOKEY EXAMPLE FROM clang ASAN webpage
root@dougBSD14-vm:~/mem-leaky # cat leaky.c
#include<stdlib.h>

void *p;

int main() {
        p = malloc(7);
        p = 0;
        return 0;
}

//COMPILE
root@dougBSD14-vm:~/mem-leaky # clang -fsanitize=address -o leaky leaky.c

//RUN
root@dougBSD14-vm:~/mem-leaky # ASAN_OPTIONS=detect_leaks=1:verbosity=3 ./leaky

[cut output]
=================================================================
==3753==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 7 byte(s) in 1 object(s) allocated from:
    #0 0x28fcdd in malloc
/usr/src/contrib/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:129:3
    #1 0x2be638 in main (/root/mem-leaky/leaky+0x2be638)
    #2 0x2373df in _start /usr/src/lib/csu/amd64/crt1_c.c:73:7
    #3 0x8002e4007  (<unknown module>)

SUMMARY: AddressSanitizer: 7 byte(s) leaked in 1 allocation(s).

//END OF TESTING EXAMPLE

So I have only barely tested this and will continue with more involved tests,
but anyway wanted to shoot this out - thanks!

-Eric (or ricky, whichevs)