From patchwork Tue Nov 24 21:44:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 9811 Received: (qmail 126913 invoked by alias); 24 Nov 2015 21:44:54 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 126897 invoked by uid 89); 24 Nov 2015 21:44:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.8 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com To: GNU C Library From: Florian Weimer Subject: [PATCH] __libc_lock_define_initialized: Always initialize the lock Message-ID: <5654DA50.5060002@redhat.com> Date: Tue, 24 Nov 2015 22:44:48 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 Since GCC 4.0, GCC will put zero-initialized variables into .bss. This makes the macro suitable for automatic variables, too. On x86_64-redhat-linux-gnu, all DSOs except libc.so.6 are unchanged. The differences for libc.so.6 are harmless, the symbols still end up in .bss: I think this change is still worthwhile because it removes a nasty source of errors, a macro with “initialized” in the name which does not actually initialize anything. Florian 2015-11-24 Florian Weimer * sysdeps/nptl/libc-lockP.h (__libc_lock_define_initialized): Always initialize the lock. diff --git a/sysdeps/nptl/libc-lockP.h b/sysdeps/nptl/libc-lockP.h index 3881b45..2a4809f 100644 --- a/sysdeps/nptl/libc-lockP.h +++ b/sysdeps/nptl/libc-lockP.h @@ -66,27 +66,15 @@ typedef pthread_key_t __libc_key_t; #define __rtld_lock_define_recursive(CLASS,NAME) \ CLASS __rtld_lock_recursive_t NAME; -/* Define an initialized lock variable NAME with storage class CLASS. - - For the C library we take a deeper look at the initializer. For - this implementation all fields are initialized to zero. Therefore - we don't initialize the variable which allows putting it into the - BSS section. (Except on PA-RISC and other odd architectures, where - initialized locks must be set to one due to the lack of normal - atomic operations.) */ +/* Define an initialized lock variable NAME with storage class CLASS. */ #define _LIBC_LOCK_INITIALIZER LLL_LOCK_INITIALIZER #if IS_IN (libc) || IS_IN (libpthread) -# if LLL_LOCK_INITIALIZER == 0 -# define __libc_lock_define_initialized(CLASS,NAME) \ - CLASS __libc_lock_t NAME; -# else -# define __libc_lock_define_initialized(CLASS,NAME) \ +# define __libc_lock_define_initialized(CLASS,NAME) \ CLASS __libc_lock_t NAME = LLL_LOCK_INITIALIZER; -# endif #else # define __libc_lock_define_initialized(CLASS,NAME) \ - CLASS __libc_lock_t NAME; + CLASS __libc_lock_t NAME = PTHREAD_MUTEX_INITIALIZER; #endif #define __libc_rwlock_define_initialized(CLASS,NAME) \