Bug 731228 - __thread variable is not initialised if there is only one byte of TLS data.
Summary: __thread variable is not initialised if there is only one byte of TLS data.
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: glibc
Version: 15
Hardware: x86_64
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Andreas Schwab
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2011-08-17 04:29 UTC by John Steele Scott
Modified: 2016-11-24 15:47 UTC (History)
3 users (show)

Fixed In Version: glibc-2.14.90-8
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2011-09-13 06:11:44 UTC


Attachments (Terms of Use)

Description John Steele Scott 2011-08-17 04:29:10 UTC
Description of problem:

When building a program with only 1 byte of thread local variables, the variable appears to not be initialised.

Version-Release number of selected component (if applicable):

[root@dxi0-02 ~]# gcc --version
gcc (GCC) 4.6.0 20110603 (Red Hat 4.6.0-10)
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[root@dxi0-02 ~]# /lib/libc.so.6 
GNU C Library stable release version 2.14, by Roland McGrath et al.
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 4.6.0 20110530 (Red Hat 4.6.0-9).
Compiled on a Linux 2.6.38 system on 2011-06-28.
Available extensions:
	Support for some architectures added on, not maintained in glibc core.
	The C stubs add-on version 2.1.2.
	crypt add-on version 2.1 by Michael Glad and others
	GNU Libidn by Simon Josefsson
	Native POSIX Threads Library by Ulrich Drepper et al
	BIND-8.2.3-T5B
	RT using linux kernel aio
libc ABIs: UNIQUE IFUNC
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.


How reproducible:

Every time.


Steps to Reproduce:
1. Write this simple example to tls-byte.c:

[root@dxi0-02 ~]# cat > tls-byte.c
#include <stdio.h>
#include <stdint.h>

__thread uint8_t foo = 1;

int main (void)
{
 printf("foo is %hhu.\n", foo);
 return 0;
}

2. Compile it to produce tls-byte.

[root@dxi0-02 ~]# gcc -lpthread tls-byte.c -o tls-byte

3. Run it.

[root@dxi0-02 ~]# ./tls-byte 
  
Actual results:
The program prints "foo is 0."

Expected results:
The program should print "foo is 1."

Interestingly, if foo is changed to a uint16_t, or a second '__thread uint8_t bar' variable is declared (even if it is not initialised), I get the expected result.

I have filed this bug on glibc rather than gcc because the TLS header appears to show 1 byte of data, which seems to me to be set correctly:

[root@dxi0-02 ~]# readelf -l ./tls-byte | grep TLS -A1
  TLS            0x0000000000000714 0x0000000000600714 0x0000000000600714
                 0x0000000000000001 0x0000000000000001  R      1

[root@dxi0-02 ~]# od --address-radix=x --format=x1 --skip-bytes=0x714 --read-bytes=1 ./tls-byte 
000714 01
000715

Apologies if I have misinterpreted this readelf output.

Comment 1 Fedora Update System 2011-09-02 07:18:51 UTC
glibc-2.14.90-7 has been submitted as an update for Fedora 16.
https://admin.fedoraproject.org/updates/glibc-2.14.90-7

Comment 2 Fedora Update System 2011-09-06 18:09:21 UTC
Package glibc-2.14.90-7:
* should fix your issue,
* was pushed to the Fedora 16 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing glibc-2.14.90-7'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/glibc-2.14.90-7
then log in and leave karma (feedback).

Comment 3 Fedora Update System 2011-09-08 20:48:24 UTC
Package glibc-2.14.90-8:
* should fix your issue,
* was pushed to the Fedora 16 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing glibc-2.14.90-8'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/glibc-2.14.90-8
then log in and leave karma (feedback).

Comment 4 Fedora Update System 2011-09-13 06:11:03 UTC
glibc-2.14.90-8 has been pushed to the Fedora 16 stable repository.  If problems still persist, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.