Bug 22052 - malloc failed to compile with GCC 7 and -O3
Summary: malloc failed to compile with GCC 7 and -O3
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: malloc (show other bugs)
Version: 2.27
: P2 normal
Target Milestone: 2.27
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-08-31 03:53 UTC by H.J. Lu
Modified: 2017-12-06 15:42 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2017-08-31 03:53:13 UTC
GCC 7 with -O3, I got

In file included from malloc.c:2266:0:
hooks.c: In function ‘realloc_check’:
hooks.c:356:14: error: ‘magic_p’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
     *magic_p ^= 0xFF;
     ~~~~~~~~~^~~~~~~
In file included from malloc.c:2266:0:
hooks.c: In function ‘realloc_check’:
hooks.c:356:14: error: ‘magic_p’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
     *magic_p ^= 0xFF;
     ~~~~~~~~~^~~~~~~
cc1: all warnings being treated as errors
make[5]: *** [../o-iterator.mk:9: /export/build/gnu/glibc-x32/build-x86_64-linux/malloc/malloc.o] Error 1
cc1: all warnings being treated as errors
make[5]: *** [../o-iterator.mk:9: /export/build/gnu/glibc-x32/build-x86_64-linux/malloc/malloc.os] Error 1
make[5]: Target 'subdir_lib' not remade because of errors.
Comment 1 cvs-commit@gcc.gnu.org 2017-10-15 15:01:09 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, hjl/pr22298/master has been created
        at  16be5568a0c24b9bd1ade7fa937c94b5d53b6ab1 (commit)

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=16be5568a0c24b9bd1ade7fa937c94b5d53b6ab1

commit 16be5568a0c24b9bd1ade7fa937c94b5d53b6ab1
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Sun Oct 15 07:48:58 2017 -0700

    Define __PTHREAD_MUTEX_HAVE_PREV only if undefined [BZ #22298]
    
    It is incorrect to define __PTHREAD_MUTEX_HAVE_PREV to 1 only when
    __WORDSIZE == 64.  For x32, __PTHREAD_MUTEX_HAVE_PREV should be 1, but
    it has __WORDSIZE == 32.  This patch defines __PTHREAD_MUTEX_HAVE_PREV
    based on __WORDSIZE only if it is undefined.  __PTHREAD_MUTEX_HAVE_PREV
    check is changed from "#ifdef" to "#if" to support values of 0 or 1.
    
    	[BZ #22298]
    	* nptl/allocatestack.c (allocate_stack): Check if
    	__PTHREAD_MUTEX_HAVE_PREV is non-zero, instead if
    	__PTHREAD_MUTEX_HAVE_PREV is defined.
    	* nptl/descr.h (pthread): Likewise.
    	* nptl/nptl-init.c (__pthread_initialize_minimal_internal):
    	Likewise.
    	* nptl/pthread_create.c (START_THREAD_DEFN): Likewise.
    	* sysdeps/nptl/fork.c (__libc_fork): Likewise.
    	* sysdeps/nptl/pthread.h (PTHREAD_MUTEX_INITIALIZER): Likewise.
    	* sysdeps/nptl/bits/thread-shared-types.h
    	(__PTHREAD_MUTEX_HAVE_PREV): Define only if it is undefined.
    	(__pthread_internal_list): Check __pthread_internal_list instead
    	of __WORDSIZE.
    	(__PTHREAD_SPINS_DATA): Likewise.
    	(__PTHREAD_SPINS): Likewise.
    	(__pthread_mutex_s): Likewise.
    	* sysdeps/x86/nptl/bits/pthreadtypes-arch.h
    	(__PTHREAD_MUTEX_HAVE_PREV): Defined.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=df44f9d02b68de45ba8c3984f47ecf1a523306ec

commit df44f9d02b68de45ba8c3984f47ecf1a523306ec
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Sun Oct 15 07:23:41 2017 -0700

    x32: Verify that NPTL structures are correct [BZ #22298]
    
    Add a build-time check to verify that NPTL structures are correct.
    
    	* sysdeps/x86_64/x32/nptl/Makefile: New file.
    	* sysdeps/x86_64/x32/nptl/nptl-check.sym: Likewise.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=aca3e9b42f9c172af368f2fc54d2c7299b231cc0

commit aca3e9b42f9c172af368f2fc54d2c7299b231cc0
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Sun Sep 3 08:39:55 2017 -0700

    Silence -O3 -Wall warning in malloc/hooks.c with GCC 7 [BZ #22052]
    
    realloc_check has
    
      unsigned char *magic_p;
    ...
      __libc_lock_lock (main_arena.mutex);
      const mchunkptr oldp = mem2chunk_check (oldmem, &magic_p);
      __libc_lock_unlock (main_arena.mutex);
      if (!oldp)
        malloc_printerr ("realloc(): invalid pointer");
    ...
      if (newmem == NULL)
        *magic_p ^= 0xFF;
    
    with
    
    static void malloc_printerr(const char *str) __attribute__ ((noreturn));
    
    GCC 7 -O3 warns
    
    hooks.c: In function ‘realloc_check’:
    hooks.c:352:14: error: ‘magic_p’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
         *magic_p ^= 0xFF;
    
    This patch silences GCC 7 by using DIAG_IGNORE_NEEDS_COMMENT.
    
    	[BZ #22052]
    	* malloc/hooks.c (realloc_check): Use DIAG_IGNORE_NEEDS_COMMENT
    	to silence -O3 -Wall warning GCC 7.

-----------------------------------------------------------------------
Comment 2 cvs-commit@gcc.gnu.org 2017-10-15 15:18:09 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, master has been updated
       via  8e57c9432a2b68c8a1e7f4df28f0e8c7acc04753 (commit)
      from  a4777c46af89649f2282c1703e8117ccd058d719 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=8e57c9432a2b68c8a1e7f4df28f0e8c7acc04753

commit 8e57c9432a2b68c8a1e7f4df28f0e8c7acc04753
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Sun Oct 15 08:16:26 2017 -0700

    Silence -O3 -Wall warning in malloc/hooks.c with GCC 7 [BZ #22052]
    
    realloc_check has
    
      unsigned char *magic_p;
    ...
      __libc_lock_lock (main_arena.mutex);
      const mchunkptr oldp = mem2chunk_check (oldmem, &magic_p);
      __libc_lock_unlock (main_arena.mutex);
      if (!oldp)
        malloc_printerr ("realloc(): invalid pointer");
    ...
      if (newmem == NULL)
        *magic_p ^= 0xFF;
    
    with
    
    static void malloc_printerr(const char *str) __attribute__ ((noreturn));
    
    GCC 7 -O3 warns
    
    hooks.c: In function ‘realloc_check’:
    hooks.c:352:14: error: ‘magic_p’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
         *magic_p ^= 0xFF;
    
    due to the GCC bug:
    
    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82090
    
    This patch silences GCC 7 by using DIAG_IGNORE_NEEDS_COMMENT.
    
    	[BZ #22052]
    	* malloc/hooks.c (realloc_check): Use DIAG_IGNORE_NEEDS_COMMENT
    	to silence -O3 -Wall warning with GCC 7.

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog      |    6 ++++++
 malloc/hooks.c |    7 +++++++
 2 files changed, 13 insertions(+), 0 deletions(-)
Comment 3 H.J. Lu 2017-10-15 15:19:17 UTC
Fixed.
Comment 4 cvs-commit@gcc.gnu.org 2017-12-06 15:42:10 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, release/2.26/master has been updated
       via  73a92363619e52c458146e903dfb9b1ba823aa40 (commit)
      from  df8c219cb987cfe85c550efa693a1383a11e38aa (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=73a92363619e52c458146e903dfb9b1ba823aa40

commit 73a92363619e52c458146e903dfb9b1ba823aa40
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Dec 6 16:15:47 2017 +0100

    Silence -O3 -Wall warning in malloc/hooks.c with GCC 7 [BZ #22052]
    
    realloc_check has
    
      unsigned char *magic_p;
    ...
      __libc_lock_lock (main_arena.mutex);
      const mchunkptr oldp = mem2chunk_check (oldmem, &magic_p);
      __libc_lock_unlock (main_arena.mutex);
      if (!oldp)
        malloc_printerr ("realloc(): invalid pointer");
    ...
      if (newmem == NULL)
        *magic_p ^= 0xFF;
    
    with
    
    static void malloc_printerr(const char *str) __attribute__ ((noreturn));
    
    GCC 7 -O3 warns
    
    hooks.c: In function ‘realloc_check’:
    hooks.c:352:14: error: ‘magic_p’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
         *magic_p ^= 0xFF;
    
    due to the GCC bug:
    
    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82090
    
    This patch silences GCC 7 by using DIAG_IGNORE_NEEDS_COMMENT.
    
    	[BZ #22052]
    	* malloc/hooks.c (realloc_check): Use DIAG_IGNORE_NEEDS_COMMENT
    	to silence -O3 -Wall warning with GCC 7.
    
    (cherry picked from commit 8e57c9432a2b68c8a1e7f4df28f0e8c7acc04753)

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog      |    6 ++++++
 NEWS           |    1 +
 malloc/hooks.c |    7 +++++++
 3 files changed, 14 insertions(+), 0 deletions(-)