From patchwork Tue Apr 1 13:57:13 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vineet Gupta X-Patchwork-Id: 335926 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from hemlock.osuosl.org (hemlock.osuosl.org [140.211.166.133]) by ozlabs.org (Postfix) with ESMTP id F3B3C140089 for ; Wed, 2 Apr 2014 00:57:50 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 87A248A4DF; Tue, 1 Apr 2014 13:57:47 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Bm+R8ABvGlz8; Tue, 1 Apr 2014 13:57:44 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by hemlock.osuosl.org (Postfix) with ESMTP id 3036E88C6E; Tue, 1 Apr 2014 13:57:44 +0000 (UTC) X-Original-To: uclibc@lists.busybox.net Delivered-To: uclibc@osuosl.org Received: from silver.osuosl.org (silver.osuosl.org [140.211.166.136]) by ash.osuosl.org (Postfix) with ESMTP id 216081C225C for ; Tue, 1 Apr 2014 13:57:43 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 191FB3043C for ; Tue, 1 Apr 2014 13:57:43 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id OXoJVxkRUVvK for ; Tue, 1 Apr 2014 13:57:40 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from smtprelay.synopsys.com (smtprelay.synopsys.com [198.182.60.111]) by silver.osuosl.org (Postfix) with ESMTPS id BF8CF200E5 for ; Tue, 1 Apr 2014 13:57:40 +0000 (UTC) Received: from us02secmta1.synopsys.com (us02secmta1.synopsys.com [10.12.235.96]) by smtprelay.synopsys.com (Postfix) with ESMTP id 299FF10C0A38; Tue, 1 Apr 2014 06:57:37 -0700 (PDT) Received: from us02secmta1.internal.synopsys.com (us02secmta1.internal.synopsys.com [127.0.0.1]) by us02secmta1.internal.synopsys.com (Service) with ESMTP id E0B514E214; Tue, 1 Apr 2014 06:57:37 -0700 (PDT) Received: from mailhost.synopsys.com (mailhost3.synopsys.com [10.12.238.238]) by us02secmta1.internal.synopsys.com (Service) with ESMTP id 1F5E44E202; Tue, 1 Apr 2014 06:57:37 -0700 (PDT) Received: from mailhost.synopsys.com (localhost [127.0.0.1]) by mailhost.synopsys.com (Postfix) with ESMTP id 06E4B8F0; Tue, 1 Apr 2014 06:57:37 -0700 (PDT) Received: from us01wehtc1.internal.synopsys.com (us01wehtc1-vip.internal.synopsys.com [10.12.239.236]) by mailhost.synopsys.com (Postfix) with ESMTP id 65E0B8DC; Tue, 1 Apr 2014 06:57:36 -0700 (PDT) Received: from IN01WEHTCA.internal.synopsys.com (10.144.199.104) by us01wehtc1.internal.synopsys.com (10.12.239.235) with Microsoft SMTP Server (TLS) id 14.3.158.1; Tue, 1 Apr 2014 06:57:36 -0700 Received: from vg-E6520.internal.synopsys.com (10.12.197.226) by IN01WEHTCA.internal.synopsys.com (10.144.199.243) with Microsoft SMTP Server (TLS) id 14.3.158.1; Tue, 1 Apr 2014 19:27:31 +0530 From: Vineet Gupta To: Subject: [PATCH v2] LT.old: Make __errno_location/__h_errno_location thread safe Date: Tue, 1 Apr 2014 19:27:13 +0530 Message-ID: <1396360633-32619-1-git-send-email-vgupta@synopsys.com> X-Mailer: git-send-email 1.8.3.2 MIME-Version: 1.0 X-Originating-IP: [10.12.197.226] Cc: Jeremy Bennett , Christian Ruppert , Francois Bedard , Vineet Gupta , Joern Rennecke , buildroot@busybox.net X-BeenThere: uclibc@uclibc.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Discussion and development of uClibc \(the embedded C library\)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: uclibc-bounces@uclibc.org Sender: uclibc-bounces@uclibc.org WHY: errno in uClibc is not thread safe HOW: __errno_location and it's sibling __h_errno_location need to be called via PLT - even from within libc. That way when linked with pthread, intra-uClibc callers will also use the thread safe version. Verified with ARC LT.old and ARM cubieboard2 buildroot (LT.old) NPTL is unaffected by this bug. ------------ History behind this patch --------------------- This is a long standing bug (https://bugs.busybox.net/show_bug.cgi?id=2089) Others have tried to fix it in past (alteast Peter Korsgaard's patch in 2010), but somehow failed to be merged (or were backed out afterwards). http://lists.uclibc.org/pipermail/uclibc/2010-July/044176.html One of the causes could be side effect of atleast one more bug related to pthreads and static link which has now been fixed. http://lists.uclibc.org/pipermail/uclibc/2013-October/047958.html I have solved this w/o looking at other pacthes but would like to give credit to Peter and others for confirming that it makes sense. Cc: Christian Ruppert CC: Francois Bedard Cc: Joern Rennecke Cc: Jeremy Bennett Cc: Thomas Petazzoni Cc: Peter Korsgaard Cc: Khem Raj Cc: buildroot@busybox.net Signed-off-by: Vineet Gupta --- Changes since v1 (http://lists.uclibc.org/pipermail/uclibc/2014-March/048273.html - Rebased to trunk - Added handling for h_errno_location Signed-off-by: Vineet Gupta --- include/netdb.h | 3 --- libc/misc/internals/__errno_location.c | 1 - libc/misc/internals/__h_errno_location.c | 1 - libc/sysdeps/linux/common/bits/errno.h | 3 --- 4 files changed, 8 deletions(-) diff --git a/include/netdb.h b/include/netdb.h index 8fdfa0fccc7d..0f361bb6f662 100644 --- a/include/netdb.h +++ b/include/netdb.h @@ -59,11 +59,8 @@ __BEGIN_DECLS /* Function to get address of global `h_errno' variable. */ extern int *__h_errno_location (void) __THROW __attribute__ ((__const__)); #ifdef _LIBC -# if !defined(__UCLIBC_HAS_TLS__) && !defined(__UCLIBC_HAS_THREADS__) extern int weak_const_function *__h_errno_location(void); -# endif #endif -libc_hidden_proto(__h_errno_location) /* Macros for accessing h_errno from inside libc. */ #ifdef _LIBC diff --git a/libc/misc/internals/__errno_location.c b/libc/misc/internals/__errno_location.c index be7a9093efa3..9bbc2d779653 100644 --- a/libc/misc/internals/__errno_location.c +++ b/libc/misc/internals/__errno_location.c @@ -16,4 +16,3 @@ int *__errno_location(void) { return &errno; } -libc_hidden_weak(__errno_location) diff --git a/libc/misc/internals/__h_errno_location.c b/libc/misc/internals/__h_errno_location.c index 6653681cbf09..b30859e81f19 100644 --- a/libc/misc/internals/__h_errno_location.c +++ b/libc/misc/internals/__h_errno_location.c @@ -16,4 +16,3 @@ int *__h_errno_location(void) { return &h_errno; } -libc_hidden_weak(__h_errno_location) diff --git a/libc/sysdeps/linux/common/bits/errno.h b/libc/sysdeps/linux/common/bits/errno.h index 777338fb1e0a..611b8359001a 100644 --- a/libc/sysdeps/linux/common/bits/errno.h +++ b/libc/sysdeps/linux/common/bits/errno.h @@ -43,11 +43,8 @@ /* Function to get address of global `errno' variable. */ extern int *__errno_location (void) __THROW __attribute__ ((__const__)); # ifdef _LIBC -# if !defined(__UCLIBC_HAS_TLS__) && !defined(__UCLIBC_HAS_THREADS__) extern int weak_const_function *__errno_location(void); -# endif # endif -libc_hidden_proto(__errno_location) # ifdef __UCLIBC_HAS_THREADS__ /* When using threads, errno is a per-thread value. */