Bug 237577

Summary: librtld: unable to compile it with MALLOC_DEBUG
Product: Base System Reporter: Alexandre martins <alexandre.martins>
Component: binAssignee: freebsd-bugs mailing list <bugs>
Status: Closed FIXED    
Severity: Affects Only Me CC: alexandre.martins, emaste, kib
Priority: ---    
Version: 12.0-STABLE   
Hardware: Any   
OS: Any   

Description Alexandre martins 2019-04-26 08:48:38 UTC
Hi,

I'm currently trying to compile the libthr with more debug (-DMALLOC_DEBUG)

Unfortunately, something has activated more compiler check and now, that lib doesn't compile.
Here is the error:

/home/jenkins/sources/libexec/rtld-elf/rtld_malloc.c:271:2: error: passing 'const char [2]' to parameter of type 'char *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
        ASSERT(sz > 0);
        ^~~~~~~~~~~~~~
/home/jenkins/sources/libexec/rtld-elf/rtld_malloc.c:130:37: note: expanded from macro 'ASSERT'
#define ASSERT(p)   if (!(p)) botch("p")
                                    ^~~
/home/jenkins/sources/libexec/rtld-elf/rtld_malloc.c:310:4: error: passing 'const char [2]' to parameter of type 'char *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
        ASSERT(op->ov_magic == MAGIC);          /* make sure it was in use */
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/jenkins/sources/libexec/rtld-elf/rtld_malloc.c:130:37: note: expanded from macro 'ASSERT'
#define ASSERT(p)   if (!(p)) botch("p")
                                    ^~~
/home/jenkins/sources/libexec/rtld-elf/rtld_malloc.c:320:4: error: passing 'const char [2]' to parameter of type 'char *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
        ASSERT(size < NBUCKETS);
        ^~~~~~~~~~~~~~~~~~~~~~~
/home/jenkins/sources/libexec/rtld-elf/rtld_malloc.c:130:37: note: expanded from macro 'ASSERT'
#define ASSERT(p)   if (!(p)) botch("p")
                                    ^~~
3 errors generated.

Can it be possible to fix that ?

Thank you
Comment 1 Konstantin Belousov freebsd_committer 2019-05-02 13:40:43 UTC
What are you trying to do ?  Why do you think that compiling libthr with MALLOC_DEBUG is useful ?
Comment 2 Alexandre martins 2019-05-02 13:53:43 UTC
In fact, it's a side effect. We are using MALLOC_DEBUG for the jemalloc allocator in the libc. Unfortunately, that flags (put in DEBUG_FLAGS) apply to the librtld too.

We use the flag to trap double free or heap corruption more easily in our very old code base.
Comment 3 Konstantin Belousov freebsd_committer 2019-05-02 14:13:08 UTC
(In reply to Alexandre martins from comment #2)
Ok, I am going to remove this code from rtld_malloc.c.  It is de-facto rotten, and there is one curious instance of UB nearby which should be harmless.
Comment 4 commit-hook freebsd_committer 2019-05-02 15:03:22 UTC
A commit references this bug:

Author: kib
Date: Thu May  2 15:03:16 UTC 2019
New revision: 347019
URL: https://svnweb.freebsd.org/changeset/base/347019

Log:
  Cleanup for rtld_malloc.c.

  - Remove dead and most likely rotten MALLOC_DEBUG, MSTAT, and RCHECK options.
  - Remove unused headers.
  - Remove one case of undefined behavior where left shift could overflow.
    It is impossible on practice for rtld and libthr consumer.

  PR:	237577
  Sponsored by:	The FreeBSD Foundation
  MFC after:	1 week

Changes:
  head/libexec/rtld-elf/rtld_malloc.c
Comment 5 Alexandre martins 2019-05-04 18:50:57 UTC
The fix works for me.

Thank you !
Comment 6 commit-hook freebsd_committer 2019-05-09 09:49:49 UTC
A commit references this bug:

Author: kib
Date: Thu May  9 09:49:08 UTC 2019
New revision: 347386
URL: https://svnweb.freebsd.org/changeset/base/347386

Log:
  MFC r347019:
  Cleanup for rtld_malloc.c.

  PR:	237577

Changes:
_U  stable/12/
  stable/12/libexec/rtld-elf/rtld_malloc.c