From patchwork Tue Oct 1 12:21:44 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vineet Gupta X-Patchwork-Id: 279433 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from whitealder.osuosl.org (whitealder.osuosl.org [140.211.166.138]) by ozlabs.org (Postfix) with ESMTP id 4A40B2C00C3 for ; Tue, 1 Oct 2013 22:22:09 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 7B8438CACB; Tue, 1 Oct 2013 12:22:06 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sZV4cgpz6ybY; Tue, 1 Oct 2013 12:22:04 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by whitealder.osuosl.org (Postfix) with ESMTP id 6D7428CA62; Tue, 1 Oct 2013 12:22:04 +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 571C51BFA70 for ; Tue, 1 Oct 2013 12:22:03 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 54B9D330DA for ; Tue, 1 Oct 2013 12:22:03 +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 rBVHIkw-+NON for ; Tue, 1 Oct 2013 12:22:02 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from vaxjo.synopsys.com (us02smtp1.synopsys.com [198.182.60.75]) by silver.osuosl.org (Postfix) with ESMTP id 6BF7D3314B for ; Tue, 1 Oct 2013 12:22:02 +0000 (UTC) Received: from WBSNus01mta2 (us01secmta2.synopsys.com [10.9.203.102]) by vaxjo.synopsys.com (Postfix) with ESMTP id BF1A0DA5A for ; Tue, 1 Oct 2013 05:22:01 -0700 (PDT) Received: from us01secmta2.internal.synopsys.com (us01secmta2.internal.synopsys.com [127.0.0.1]) by us01secmta2.internal.synopsys.com (Service) with ESMTP id ACB1EA4112 for ; Tue, 1 Oct 2013 05:22:01 -0700 (PDT) Received: from mailhost.synopsys.com (mailhost2.synopsys.com [10.9.202.240]) by us01secmta2.internal.synopsys.com (Service) with ESMTP id 799C3A4102 for ; Tue, 1 Oct 2013 05:22:01 -0700 (PDT) Received: from mailhost.synopsys.com (localhost [127.0.0.1]) by mailhost.synopsys.com (Postfix) with ESMTP id 66F44FD for ; Tue, 1 Oct 2013 05:22:01 -0700 (PDT) Received: from us01wehtc1.internal.synopsys.com (us01wehtc1.internal.synopsys.com [10.12.239.235]) by mailhost.synopsys.com (Postfix) with ESMTP id 626C2FC for ; Tue, 1 Oct 2013 05:22:01 -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.2.298.4; Tue, 1 Oct 2013 05:22:01 -0700 Received: from vineetg-E6520.internal.synopsys.com (10.12.197.243) by IN01WEHTCA.internal.synopsys.com (10.144.199.243) with Microsoft SMTP Server (TLS) id 14.2.298.4; Tue, 1 Oct 2013 17:51:56 +0530 From: Vineet Gupta To: Subject: [PATCH] Fix weak/strong attribute of __errno_location and it's __GI alias Date: Tue, 1 Oct 2013 17:51:44 +0530 Message-ID: <1380630104-8230-1-git-send-email-vgupta@synopsys.com> X-Mailer: git-send-email 1.8.1.2 MIME-Version: 1.0 X-Originating-IP: [10.12.197.243] Cc: Vineet Gupta 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 A simple statically linked hello world program was segfaulting for ARC in linuxthreads.old configuration (although the root casue applies cross-arch for NPTL as well as linuxthreads.old as described) The crash was due to branch to NULL in _stdio_init 0001026c <_stdio_init>: 1026c: push_s blink 1026e: st.a r13,[sp,-8] 10272: bl.d 0 --> supposed call to __errno_location The call was NOT getting patched to libc internal only alias __GI___errno_location, because it was weak while it's exported cousin, __errno_location was strong/normal. arc-linux-uclibc-nm libc/misc/internals/__errno_location.os 00000000 W __GI___errno_location 00000000 T __errno_location This is exactly opposite to what is expected. Quoting Peter S. Mazinger, commit 87936cd013041 "errno and *_init cleanup" | The rule adopted: | for enabled threads we make in libc the __GI_x() variants strong, x() weak | and (should) provide another strong x() in libpthread. | If threads are disabled, even the __GI_x() variants are weak. With the fix, we see the right settings as below 00000000 T __GI___errno_location 00000000 W __errno_location Note that problem won't show up in a static busybox build as it references errno and that seems to elide the issue. I can confirm the same/more issues with latest ARM buildroot builds w/o my fix. (1). linuxthreads.old (broken just like ARC) arm-linux-nm uclibc-snapshot/libc/misc/internals/__errno_location.os 00000000 W __GI___errno_location 00000000 T __errno_location But presumably the issue there is NOT catestrophic because ARM linker is likely smarter and patches a NOP instead of NULL branch. 00008388 <_stdio_init>: 8388: e92d4038 push {r3, r4, r5, lr} 838c: e320f000 nop {0} (2) NPTL build (exported version is not weak) 00000000 T __GI___errno_location 00000000 T __errno_location This causes a static link with libpthread and test program referencing errno to fail to link. #include int main(void) { printf("%d\n", errno); } arm-linux-gcc -static -pthread -o tst tst.o arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib/libc.a(__errno_location.os): In function `__errno_location': __errno_location.c:(.text+0x0): multiple definition of `__errno_location' arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib/libpthread.a (errno_location.os):errno_location.c:(.text+0x0): first defined here Signed-off-by: Vineet Gupta --- libc/misc/internals/__errno_location.c | 2 +- libc/sysdeps/linux/common/bits/errno.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libc/misc/internals/__errno_location.c b/libc/misc/internals/__errno_location.c index dec913f..be7a909 100644 --- a/libc/misc/internals/__errno_location.c +++ b/libc/misc/internals/__errno_location.c @@ -16,4 +16,4 @@ int *__errno_location(void) { return &errno; } -libc_hidden_def(__errno_location) +libc_hidden_weak(__errno_location) diff --git a/libc/sysdeps/linux/common/bits/errno.h b/libc/sysdeps/linux/common/bits/errno.h index 7ef1b94..777338f 100644 --- a/libc/sysdeps/linux/common/bits/errno.h +++ b/libc/sysdeps/linux/common/bits/errno.h @@ -43,7 +43,7 @@ /* Function to get address of global `errno' variable. */ extern int *__errno_location (void) __THROW __attribute__ ((__const__)); # ifdef _LIBC -# ifndef __UCLIBC_HAS_TLS__ +# if !defined(__UCLIBC_HAS_TLS__) && !defined(__UCLIBC_HAS_THREADS__) extern int weak_const_function *__errno_location(void); # endif # endif