From owner-freebsd-bugs@FreeBSD.ORG Wed Sep 14 02:10:11 2011 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AA3B8106566C for ; Wed, 14 Sep 2011 02:10:11 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 7A1018FC16 for ; Wed, 14 Sep 2011 02:10:11 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id p8E2ABEc003816 for ; Wed, 14 Sep 2011 02:10:11 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id p8E2AB9g003815; Wed, 14 Sep 2011 02:10:11 GMT (envelope-from gnats) Resent-Date: Wed, 14 Sep 2011 02:10:11 GMT Resent-Message-Id: <201109140210.p8E2AB9g003815@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, "Thinker K.F. Li" Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7D1AD106564A for ; Wed, 14 Sep 2011 02:01:34 +0000 (UTC) (envelope-from thinker.li@gmail.com) Received: from mail-gw0-f45.google.com (mail-gw0-f45.google.com [74.125.83.45]) by mx1.freebsd.org (Postfix) with ESMTP id 38A3C8FC0C for ; Wed, 14 Sep 2011 02:01:34 +0000 (UTC) Received: by gwb19 with SMTP id 19so1344151gwb.18 for ; Tue, 13 Sep 2011 19:01:33 -0700 (PDT) Received: by 10.150.157.21 with SMTP id f21mr1290747ybe.126.1315963888217; Tue, 13 Sep 2011 18:31:28 -0700 (PDT) Received: from eeebox.branda.to (123-194-52-90.dynamic.kbronet.com.tw [123.194.52.90]) by mx.google.com with ESMTPS id v5sm5240676anc.6.2011.09.13.18.31.24 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 13 Sep 2011 18:31:25 -0700 (PDT) Received: from eeebox.branda.to (localhost [127.0.0.1]) by eeebox.branda.to (8.14.4/8.14.4) with ESMTP id p8E1ZAv5078901 for ; Wed, 14 Sep 2011 09:35:11 +0800 (CST) (envelope-from thinker@branda.to) Received: (from root@localhost) by eeebox.branda.to (8.14.4/8.14.4/Submit) id p8E1ZA4o078900; Wed, 14 Sep 2011 09:35:10 +0800 (CST) (envelope-from thinker) Message-Id: <201109140135.p8E1ZA4o078900@eeebox.branda.to> Date: Wed, 14 Sep 2011 09:35:10 +0800 (CST) From: "Thinker K.F. Li" Sender: Thinker Li To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: misc/160721: TLS is inconsistent X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: "Thinker K.F. Li" List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Sep 2011 02:10:11 -0000 >Number: 160721 >Category: misc >Synopsis: TLS is inconsistent >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Sep 14 02:10:10 UTC 2011 >Closed-Date: >Last-Modified: >Originator: Thinker K.F. Li >Release: FreeBSD 9.0-CURRENT i386 >Organization: Allwitz Tech. >Environment: System: FreeBSD eeebox.branda.to 9.0-CURRENT FreeBSD 9.0-CURRENT #1: Sun Jun 5 17:08:32 CST 2011 thinker@eeebox.branda.to:/usr/src/sys/i386/compile/eeebox i386 >Description: Compiler generated code will call ___tls_get_addr() of ld-elf.so for TLS variable. It is supposed to return the same address, every time, for the same passed address and thread, but it does not. >How-To-Repeat: Compile following code with commands 1. cc -shared -o test-tls-1.so -pthread -fpic test-tls-1.c 2. cc -o test-tls -pthread test-tls.c test-tls is supposed to print "100" on stdout, but it print out "50", instead. If you dig into opcodes, you will find that ___tls_get_addr() return two different base addresses for modify() and for show() respective. This issue is only making troubles for programs accessing TLS after dlopen(). --- test-tls-1.c begins here --- #include __thread int var = 50; void modify(void) { var = 100; } void show(void) { printf("%d\n", var); } --- test-tls-1.c ends here --- --- test-tls.c begins here --- #include #include int main(int argc, char * const *argv) { void (*modify)(void); void (*modify)(void); void *sohdl; sohdl = dlopen("./test-tls-1.so", RTLD_NOW); modify = (void (*)(void))dlsym(sohdl, "modify"); show = (void (*)(void))dlsym(sohdl, "show"); modify(); show(); return 0; } --- test-tls.c ends here --- >Fix: Apply following patch on the root of source tree can fix this issue. --- libexec-rtld_elf-rtld.c.diff begins here --- --- libexec/rtld-elf/rtld.c.orig 2011-09-13 14:25:17.000000000 +0800 +++ libexec/rtld-elf/rtld.c 2011-09-13 14:25:43.000000000 +0800 @@ -3371,6 +3371,7 @@ free(dtv); lock_release(rtld_bind_lock, &lockstate); *dtvp = newdtv; + dtv = newdtv; } /* Dynamically allocate module TLS if necessary */ --- libexec-rtld_elf-rtld.c.diff ends here --- >Release-Note: >Audit-Trail: >Unformatted: