Re: MALLOC_STATS [was: Clang sanitizer support]

2021-07-23 Thread Joe Nelson
Otto Moerbeek wrote:
> yeah, MALLOC_STATS is not well maintained... 

What's the relation between the MALLOC_STATS code currently in -stable,
and the code in your mdump [0] project? Are you experimenting with
different approaches?

BTW, thanks for your work on this.

0: https://github.com/omoerbeek/mdump



Re: MALLOC_STATS [was: Clang sanitizer support]

2021-07-23 Thread Joe Nelson
Omar Polo wrote:
> not tried, but compiles :)

Your patch made it compile for me too. With that change I was able to
run through the steps in https://www.drijf.net/malloc/ and detect memory
leaks! Thank you.

What's the process to get your change applied to -current? Should it be
submitted to the tech@ list?



Re: MALLOC_STATS [was: Clang sanitizer support]

2021-07-23 Thread Joe Nelson
Omar Polo wrote:
> There's a built-in mechanisms to check for memory leaks:
> 
>   https://www.drijf.net/malloc/
> 
> don't know if it still applies, I tried only once and was like a couple
> of years ago (if not more).

Thanks for the tip, Omar. I just tried compiling malloc.c with MALLOC_STATS
defined, but I got a compiler error:

clang -O2 -pipe -g -Wimplicit -I/usr/src/lib/libc/include 
-I/usr/src/lib/libc/hidden \
-D__LIBC__  -Werror-implicit-function-declaration -include 
namespace.h   \
-Werror=deprecated-declarations -DAPIWARN -DYP 
-I/usr/src/lib/libc/yp\
-I/usr/src/lib/libc -I/usr/src/lib/libc/gdtoa   
 \
-I/usr/src/lib/libc/arch/amd64/gdtoa -DINFNAN_CHECK 
-DMULTIPLE_THREADS   \
-DNO_FENV_H -DUSE_LOCALE -I/usr/src/lib/libc 
-I/usr/src/lib/libc/citrus  \
-DRESOLVSORT -DFLOATING_POINT -DPRINTF_WIDE_CHAR -DSCANF_WIDE_CHAR 
-DFUTEX  -MD  \
-MP  -c /usr/src/lib/libc/stdlib/malloc.c -o malloc.o

/usr/src/lib/libc/stdlib/malloc.c:1613:14: error: use of undeclared 
identifier 'd'

STATS_SUB(d->malloc_used, roldsz - rnewsz);
  ^
1 error generated.

Malloc source version:
$OpenBSD: malloc.c,v 1.270 2021/04/09 06:05:21 otto Exp $
System:
6.9 stable



Re: MALLOC_STATS [was: Clang sanitizer support]

2021-07-23 Thread Otto Moerbeek
On Fri, Jul 23, 2021 at 11:54:38AM -0500, Joe Nelson wrote:

> Otto Moerbeek wrote:
> > yeah, MALLOC_STATS is not well maintained... 
> 
> What's the relation between the MALLOC_STATS code currently in -stable,
> and the code in your mdump [0] project? Are you experimenting with
> different approaches?
> 
> BTW, thanks for your work on this.
> 
> 0: https://github.com/omoerbeek/mdump

This was an experiment, it's not in a state that is suitable for
inclusion into OpenBSD base due to various isues and depedencies on
external stuff.

-Otto



Re: MALLOC_STATS [was: Clang sanitizer support]

2021-07-23 Thread Otto Moerbeek
I'll take care.

Joe Nelson  schreef op 23 juli 2021 18:36:04 CEST:
>Omar Polo wrote:
>> not tried, but compiles :)
>
>Your patch made it compile for me too. With that change I was able to
>run through the steps in https://www.drijf.net/malloc/ and detect
>memory
>leaks! Thank you.
>
>What's the process to get your change applied to -current? Should it be
>submitted to the tech@ list?

-- 
Verstuurd vanaf mijn Android apparaat met K-9 Mail. Excuseer mijn beknoptheid.


Re: MALLOC_STATS [was: Clang sanitizer support]

2021-07-23 Thread Otto Moerbeek
On Fri, Jul 23, 2021 at 06:02:08PM +0200, Omar Polo wrote:

> 
> Joe Nelson  writes:
> 
> > Omar Polo wrote:
> >> There's a built-in mechanisms to check for memory leaks:
> >> 
> >>https://www.drijf.net/malloc/
> >> 
> >> don't know if it still applies, I tried only once and was like a couple
> >> of years ago (if not more).
> >
> > Thanks for the tip, Omar. I just tried compiling malloc.c with MALLOC_STATS
> > defined, but I got a compiler error:
> >
> > clang -O2 -pipe -g -Wimplicit -I/usr/src/lib/libc/include 
> > -I/usr/src/lib/libc/hidden \
> > -D__LIBC__  -Werror-implicit-function-declaration -include 
> > namespace.h   \
> > -Werror=deprecated-declarations -DAPIWARN -DYP 
> > -I/usr/src/lib/libc/yp\
> > -I/usr/src/lib/libc -I/usr/src/lib/libc/gdtoa   
> >  \
> > -I/usr/src/lib/libc/arch/amd64/gdtoa -DINFNAN_CHECK 
> > -DMULTIPLE_THREADS   \
> > -DNO_FENV_H -DUSE_LOCALE -I/usr/src/lib/libc 
> > -I/usr/src/lib/libc/citrus  \
> > -DRESOLVSORT -DFLOATING_POINT -DPRINTF_WIDE_CHAR -DSCANF_WIDE_CHAR 
> > -DFUTEX  -MD  \
> > -MP  -c /usr/src/lib/libc/stdlib/malloc.c -o malloc.o
> >
> > /usr/src/lib/libc/stdlib/malloc.c:1613:14: error: use of undeclared 
> > identifier 'd'
> > 
> > STATS_SUB(d->malloc_used, roldsz - rnewsz);
> >   ^
> > 1 error generated.
> >
> > Malloc source version:
> > $OpenBSD: malloc.c,v 1.270 2021/04/09 06:05:21 otto Exp $
> > System:
> > 6.9 stable
> 
> that seems to be a typo?
> 
> not tried, but compiles :)

yeah, MALLOC_STATS is not well maintained... 

-Otto

> 
> Index: malloc.c
> ===
> RCS file: /home/cvs/src/lib/libc/stdlib/malloc.c,v
> retrieving revision 1.270
> diff -u -p -r1.270 malloc.c
> --- malloc.c  9 Apr 2021 06:05:21 -   1.270
> +++ malloc.c  23 Jul 2021 16:01:26 -
> @@ -1610,7 +1610,7 @@ orealloc(struct dir_info **argpool, void
>   }
>   if (munmap((char *)r->p + rnewsz, roldsz - rnewsz))
>   wrterror(pool, "munmap %p", (char *)r->p + 
> rnewsz);
> - STATS_SUB(d->malloc_used, roldsz - rnewsz);
> + STATS_SUB(pool->malloc_used, roldsz - rnewsz);
>   r->size = gnewsz;
>   if (MALLOC_MOVE_COND(gnewsz)) {
>   void *pp = MALLOC_MOVE(r->p, gnewsz);



Re: MALLOC_STATS [was: Clang sanitizer support]

2021-07-23 Thread Omar Polo


Joe Nelson  writes:

> Omar Polo wrote:
>> There's a built-in mechanisms to check for memory leaks:
>> 
>>  https://www.drijf.net/malloc/
>> 
>> don't know if it still applies, I tried only once and was like a couple
>> of years ago (if not more).
>
> Thanks for the tip, Omar. I just tried compiling malloc.c with MALLOC_STATS
> defined, but I got a compiler error:
>
>   clang -O2 -pipe -g -Wimplicit -I/usr/src/lib/libc/include 
> -I/usr/src/lib/libc/hidden \
>   -D__LIBC__  -Werror-implicit-function-declaration -include 
> namespace.h   \
>   -Werror=deprecated-declarations -DAPIWARN -DYP 
> -I/usr/src/lib/libc/yp\
>   -I/usr/src/lib/libc -I/usr/src/lib/libc/gdtoa   
>  \
>   -I/usr/src/lib/libc/arch/amd64/gdtoa -DINFNAN_CHECK 
> -DMULTIPLE_THREADS   \
>   -DNO_FENV_H -DUSE_LOCALE -I/usr/src/lib/libc 
> -I/usr/src/lib/libc/citrus  \
>   -DRESOLVSORT -DFLOATING_POINT -DPRINTF_WIDE_CHAR -DSCANF_WIDE_CHAR 
> -DFUTEX  -MD  \
>   -MP  -c /usr/src/lib/libc/stdlib/malloc.c -o malloc.o
>
>   /usr/src/lib/libc/stdlib/malloc.c:1613:14: error: use of undeclared 
> identifier 'd'
>   
> STATS_SUB(d->malloc_used, roldsz - rnewsz);
> ^
>   1 error generated.
>
> Malloc source version:
>   $OpenBSD: malloc.c,v 1.270 2021/04/09 06:05:21 otto Exp $
> System:
>   6.9 stable

that seems to be a typo?

not tried, but compiles :)

Index: malloc.c
===
RCS file: /home/cvs/src/lib/libc/stdlib/malloc.c,v
retrieving revision 1.270
diff -u -p -r1.270 malloc.c
--- malloc.c9 Apr 2021 06:05:21 -   1.270
+++ malloc.c23 Jul 2021 16:01:26 -
@@ -1610,7 +1610,7 @@ orealloc(struct dir_info **argpool, void
}
if (munmap((char *)r->p + rnewsz, roldsz - rnewsz))
wrterror(pool, "munmap %p", (char *)r->p + 
rnewsz);
-   STATS_SUB(d->malloc_used, roldsz - rnewsz);
+   STATS_SUB(pool->malloc_used, roldsz - rnewsz);
r->size = gnewsz;
if (MALLOC_MOVE_COND(gnewsz)) {
void *pp = MALLOC_MOVE(r->p, gnewsz);