[v2] malloc: Fix malloc debug for 2.35 onwards

Message ID 20211116213225.3032782-1-shorne@gmail.com
State Committed
Commit f1bcfde3a7b1b2606ff9f267e1e4a9cd7c65497a
Headers
Series [v2] malloc: Fix malloc debug for 2.35 onwards |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent
dj/TryBot-32bit success Build for i686

Commit Message

Stafford Horne Nov. 16, 2021, 9:32 p.m. UTC
  The change 1e5a5866cb ("Remove malloc hooks [BZ #23328]") has broken
ports that are using GLIBC_2_35, like the new OpenRISC port I am working
on.

The libc_malloc_debug.so library used to bring in the debug
infrastructure is currently essentially empty for GLIBC_2_35 ports like
mine causing mtrace tests to fail:

    cat sysdeps/unix/sysv/linux/or1k/shlib-versions
    DEFAULT                 GLIBC_2.35
    ld=ld-linux-or1k.so.1

    FAIL: posix/bug-glob2-mem
    FAIL: posix/bug-regex14-mem
    FAIL: posix/bug-regex2-mem
    FAIL: posix/bug-regex21-mem
    FAIL: posix/bug-regex31-mem
    FAIL: posix/bug-regex36-mem
    FAIL: malloc/tst-mtrace.

The issue seems to be with the ifdefs in malloc/malloc-debug.c. The
ifdefs are currently essentially exluding all symbols for ports > 2.35.

Removing the top level SHLIB_COMPAT ifdef allows things to just work.

Fixes: 1e5a5866cb ("Remove malloc hooks [BZ #23328]")
Cc: Siddhesh Poyarekar <siddhesh@gotplt.org>
---

Changes since v2:
 - Just remove SHLIB_COMPAT, using compat_symbol seems to do what
   Siddhesh was explaining he wanted to do.

 malloc/malloc-debug.c | 2 --
 1 file changed, 2 deletions(-)
  

Comments

Stafford Horne Nov. 16, 2021, 9:38 p.m. UTC | #1
On Wed, Nov 17, 2021 at 6:32 AM Stafford Horne <shorne@gmail.com> wrote:
>
> The change 1e5a5866cb ("Remove malloc hooks [BZ #23328]") has broken
> ports that are using GLIBC_2_35, like the new OpenRISC port I am working
> on.
>
> The libc_malloc_debug.so library used to bring in the debug
> infrastructure is currently essentially empty for GLIBC_2_35 ports like
> mine causing mtrace tests to fail:
>
>     cat sysdeps/unix/sysv/linux/or1k/shlib-versions
>     DEFAULT                 GLIBC_2.35
>     ld=ld-linux-or1k.so.1
>
>     FAIL: posix/bug-glob2-mem
>     FAIL: posix/bug-regex14-mem
>     FAIL: posix/bug-regex2-mem
>     FAIL: posix/bug-regex21-mem
>     FAIL: posix/bug-regex31-mem
>     FAIL: posix/bug-regex36-mem
>     FAIL: malloc/tst-mtrace.
>
> The issue seems to be with the ifdefs in malloc/malloc-debug.c. The
> ifdefs are currently essentially exluding all symbols for ports > 2.35.
>
> Removing the top level SHLIB_COMPAT ifdef allows things to just work.
>
> Fixes: 1e5a5866cb ("Remove malloc hooks [BZ #23328]")
> Cc: Siddhesh Poyarekar <siddhesh@gotplt.org>
> ---
>
> Changes since v2:
>  - Just remove SHLIB_COMPAT, using compat_symbol seems to do what
>    Siddhesh was explaining he wanted to do.
>
>  malloc/malloc-debug.c | 2 --
>  1 file changed, 2 deletions(-)
>
> diff --git a/malloc/malloc-debug.c b/malloc/malloc-debug.c
> index 3d7e6d44fd..99aa95b145 100644
> --- a/malloc/malloc-debug.c
> +++ b/malloc/malloc-debug.c
> @@ -24,7 +24,6 @@
>  #include <unistd.h>
>  #include <sys/param.h>
>
> -#if SHLIB_COMPAT (libc_malloc_debug, GLIBC_2_0, GLIBC_2_34)
>  /* Support only the glibc allocators.  */
>  extern void *__libc_malloc (size_t);
>  extern void __libc_free (void *);
> @@ -669,4 +668,3 @@ compat_symbol (libc_malloc_debug, __free_hook, __free_hook, GLIBC_2_0);
>  compat_symbol (libc_malloc_debug, __malloc_hook, __malloc_hook, GLIBC_2_0);
>  compat_symbol (libc_malloc_debug, __realloc_hook, __realloc_hook, GLIBC_2_0);
>  compat_symbol (libc_malloc_debug, __memalign_hook, __memalign_hook, GLIBC_2_0);
> -#endif
> --
> 2.31.1
>

Note, after this patch objdump -T looks like following below.   Note,
this just works because
when we use GLIBC_2_0 in compat_symbol it automatically forwards to the ports
default/first version.

Also, tests pass for me.

../build-glibc/malloc/libc_malloc_debug.so:     file format elf32-big

DYNAMIC SYMBOL TABLE:
00001114 l    d  .text  00000000              .text
0000a7d0 l    d  .rodata        00000000              .rodata
0000b7c8 l    d  .eh_frame      00000000              .eh_frame
0000df00 l    d  .tbss  00000000              .tbss
0000e000 l    d  .data  00000000              .data
0000e574 l    d  .bss   00000000              .bss
00000000      DF *UND*  00000000  GLIBC_2.35  fclose
00000000      DF *UND*  00000000  GLIBC_2.35  __libc_free
00000000      DF *UND*  00000000  GLIBC_PRIVATE __lll_lock_wake_private
00000000  w   D  *UND*  00000000  Base        _ITM_deregisterTMCloneTable
00000000      D  *UND*  00000000  GLIBC_PRIVATE errno
00000000      DF *UND*  00000000  GLIBC_2.35  __libc_memalign
00000000      DF *UND*  00000000  GLIBC_PRIVATE __libc_fatal
00000000      DO *UND*  00000000  GLIBC_2.35  _libc_intl_domainname
00000000      DF *UND*  00000000  GLIBC_PRIVATE __mmap
00000000      DF *UND*  00000000  GLIBC_2.35  __libc_malloc
00000000      DF *UND*  00000000  GLIBC_PRIVATE __munmap
00000000      DF *UND*  00000000  GLIBC_2.35  __assert_fail
00000000      DO *UND*  00000000  GLIBC_PRIVATE __libc_enable_secure
00000000      DF *UND*  00000000  GLIBC_2.35  dlsym
00000000      DF *UND*  00000000  GLIBC_2.35  mremap
00000000      DF *UND*  00000000  GLIBC_PRIVATE __open_nocancel
00000000      DF *UND*  00000000  GLIBC_2.35  setvbuf
00000000      DF *UND*  00000000  GLIBC_2.35  sprintf
00000000      DF *UND*  00000000  GLIBC_2.35  __sbrk
00000000  w   DF *UND*  00000000  GLIBC_2.35  __cxa_finalize
00000000      DF *UND*  00000000  GLIBC_2.35  __dcgettext
00000000      DF *UND*  00000000  GLIBC_PRIVATE __mprotect
00000000      DO *UND*  00000000  GLIBC_PRIVATE _rtld_global_ro
00000000      DF *UND*  00000000  GLIBC_2.35  fopen
00000000      DF *UND*  00000000  GLIBC_2.35  funlockfile
00000000      DF *UND*  00000000  GLIBC_2.35  sysconf
00000000      DF *UND*  00000000  GLIBC_2.35  flockfile
00000000      DF *UND*  00000000  GLIBC_PRIVATE __read_nocancel
00000000      DO *UND*  00000000  GLIBC_2.35  stderr
00000000      DF *UND*  00000000  GLIBC_2.35  memset
00000000      DF *UND*  00000000  GLIBC_2.35  __libc_realloc
00000000      DF *UND*  00000000  GLIBC_2.35  fprintf
00000000      DF *UND*  00000000  GLIBC_2.35  secure_getenv
00000000      DF *UND*  00000000  GLIBC_2.35  __libc_freeres
00000000      DF *UND*  00000000  GLIBC_PRIVATE __madvise
00000000      DF *UND*  00000000  GLIBC_2.35  strlen
00000000      DF *UND*  00000000  GLIBC_2.35  memcpy
00000000      DF *UND*  00000000  GLIBC_2.35  dladdr
00000000      DF *UND*  00000000  GLIBC_PRIVATE __tunable_get_val
00000000      DF *UND*  00000000  GLIBC_2.35  __cxa_atexit
00000000  w   D  *UND*  00000000  Base        _ITM_registerTMCloneTable
00000000      DF *UND*  00000000  GLIBC_PRIVATE __lll_lock_wait_private
00000000      DF *UND*  00000000  GLIBC_PRIVATE __close_nocancel
00000000      DF *UND*  00000000  GLIBC_2.35  fwrite
0000e498 g    DO .data  00000004 (GLIBC_2.35) __realloc_hook
0000e7c8 g    DO .bss   00000004 (GLIBC_2.35) __free_hook
00000000 g    DO *ABS*  00000000  GLIBC_2.35  GLIBC_2.35
00009804 g    DF .text  00000024 (GLIBC_2.35) mcheck_pedantic
00009c1c g    DF .text  00000104 (GLIBC_2.35) pvalloc
000095ec g    DF .text  0000011c (GLIBC_2.35) free
0000a478 g    DF .text  00000138 (GLIBC_2.35) mallinfo2
000099b8 g    DF .text  000001a4 (GLIBC_2.35) realloc
00009d20 g    DF .text  000000a8 (GLIBC_2.35) valloc
00004440 g    DF .text  00000024 (GLIBC_2.35) mcheck_check_all
00004464 g    DF .text  00000020 (GLIBC_2.35) mprobe
0000e494 g    DO .data  00000004 (GLIBC_2.35) __memalign_hook
00009ba4 g    DF .text  00000030 (GLIBC_2.35) aligned_alloc
0000e49c g    DO .data  00000004 (GLIBC_2.35) __malloc_hook
0000a1bc g    DF .text  000000f8 (GLIBC_2.35) malloc_info
000044a4 g    DF .text  00000020 (GLIBC_2.35) muntrace
0000a128 g    DF .text  00000094 (GLIBC_2.35) malloc_usable_size
00009dc8 g    DF .text  000000bc (GLIBC_2.35) posix_memalign
000097e0 g    DF .text  00000024 (GLIBC_2.35) mcheck
00004484 g    DF .text  00000020 (GLIBC_2.35) mtrace
0000a3ac g    DF .text  000000cc (GLIBC_2.35) malloc_stats
00009e84 g    DF .text  000002a4 (GLIBC_2.35) calloc
0000a6e8 g    DF .text  000000e8 (GLIBC_2.35) malloc_trim
00009ba4 g    DF .text  00000030 (GLIBC_2.35) memalign
00009190 g    DF .text  00000180 (GLIBC_2.35) malloc
0000a5b0 g    DF .text  00000138 (GLIBC_2.35) mallinfo
0000a2b4 g    DF .text  000000f8 (GLIBC_2.35) mallopt
  
Siddhesh Poyarekar Nov. 17, 2021, 3:44 a.m. UTC | #2
On 11/17/21 03:02, Stafford Horne wrote:
> The change 1e5a5866cb ("Remove malloc hooks [BZ #23328]") has broken
> ports that are using GLIBC_2_35, like the new OpenRISC port I am working
> on.
> 
> The libc_malloc_debug.so library used to bring in the debug
> infrastructure is currently essentially empty for GLIBC_2_35 ports like
> mine causing mtrace tests to fail:
> 
>      cat sysdeps/unix/sysv/linux/or1k/shlib-versions
>      DEFAULT                 GLIBC_2.35
>      ld=ld-linux-or1k.so.1
> 
>      FAIL: posix/bug-glob2-mem
>      FAIL: posix/bug-regex14-mem
>      FAIL: posix/bug-regex2-mem
>      FAIL: posix/bug-regex21-mem
>      FAIL: posix/bug-regex31-mem
>      FAIL: posix/bug-regex36-mem
>      FAIL: malloc/tst-mtrace.
> 
> The issue seems to be with the ifdefs in malloc/malloc-debug.c. The
> ifdefs are currently essentially exluding all symbols for ports > 2.35.
> 
> Removing the top level SHLIB_COMPAT ifdef allows things to just work.

LGTM.  I verified that the only change to the build in x86_64 is in the 
debug sections to account for change in line numbers.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>

> 
> Fixes: 1e5a5866cb ("Remove malloc hooks [BZ #23328]")
> Cc: Siddhesh Poyarekar <siddhesh@gotplt.org>
> ---
> 
> Changes since v2:
>   - Just remove SHLIB_COMPAT, using compat_symbol seems to do what
>     Siddhesh was explaining he wanted to do.
> 
>   malloc/malloc-debug.c | 2 --
>   1 file changed, 2 deletions(-)
> 
> diff --git a/malloc/malloc-debug.c b/malloc/malloc-debug.c
> index 3d7e6d44fd..99aa95b145 100644
> --- a/malloc/malloc-debug.c
> +++ b/malloc/malloc-debug.c
> @@ -24,7 +24,6 @@
>   #include <unistd.h>
>   #include <sys/param.h>
>   
> -#if SHLIB_COMPAT (libc_malloc_debug, GLIBC_2_0, GLIBC_2_34)
>   /* Support only the glibc allocators.  */
>   extern void *__libc_malloc (size_t);
>   extern void __libc_free (void *);
> @@ -669,4 +668,3 @@ compat_symbol (libc_malloc_debug, __free_hook, __free_hook, GLIBC_2_0);
>   compat_symbol (libc_malloc_debug, __malloc_hook, __malloc_hook, GLIBC_2_0);
>   compat_symbol (libc_malloc_debug, __realloc_hook, __realloc_hook, GLIBC_2_0);
>   compat_symbol (libc_malloc_debug, __memalign_hook, __memalign_hook, GLIBC_2_0);
> -#endif
>
  

Patch

diff --git a/malloc/malloc-debug.c b/malloc/malloc-debug.c
index 3d7e6d44fd..99aa95b145 100644
--- a/malloc/malloc-debug.c
+++ b/malloc/malloc-debug.c
@@ -24,7 +24,6 @@ 
 #include <unistd.h>
 #include <sys/param.h>
 
-#if SHLIB_COMPAT (libc_malloc_debug, GLIBC_2_0, GLIBC_2_34)
 /* Support only the glibc allocators.  */
 extern void *__libc_malloc (size_t);
 extern void __libc_free (void *);
@@ -669,4 +668,3 @@  compat_symbol (libc_malloc_debug, __free_hook, __free_hook, GLIBC_2_0);
 compat_symbol (libc_malloc_debug, __malloc_hook, __malloc_hook, GLIBC_2_0);
 compat_symbol (libc_malloc_debug, __realloc_hook, __realloc_hook, GLIBC_2_0);
 compat_symbol (libc_malloc_debug, __memalign_hook, __memalign_hook, GLIBC_2_0);
-#endif