Bug 157983 - gcc produces inadequate alignment for __thread vars
gcc produces inadequate alignment for __thread vars
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 3
Classification: Red Hat
Component: binutils (Show other bugs)
3.0
ia64 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
:
Depends On:
Blocks: 156320
  Show dependency treegraph
 
Reported: 2005-05-17 11:49 EDT by Yoav Zach
Modified: 2007-11-30 17:07 EST (History)
1 user (show)

See Also:
Fixed In Version: RHSA-2005-659
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2005-09-28 10:02:55 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
binutils-2.14.90.0.4-tls-align.patch (2.90 KB, patch)
2005-05-19 09:33 EDT, Jakub Jelinek
no flags Details | Diff

  None (edit)
Description Yoav Zach 2005-05-17 11:49:34 EDT
Description of problem:
In some code sequences, gcc creates __thread variables with inadequate offset, 
causing applications to crash when accessing these variables.

Version-Release number of selected component (if applicable):
[/tmp/gcc-bug-2]gcc -v
Reading specs from /usr/lib/gcc-lib/ia64-redhat-linux/3.2.3/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --
infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-
checking --with-system-zlib --enable-__cxa_atexit --host=ia64-redhat-linux
Thread model: posix
gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-42)


How reproducible:
consistent

Steps to Reproduce:
[/tmp/gcc-bug-2]cat main.c
struct foo_t {
        unsigned long ll[2] __attribute__ ((aligned (16)));
};
typedef struct foo_t foo_t;

__thread long t1  = 0l, t2 = 0l;
__thread foo_t fooo;

int g_dont_core = 0;
char * search_path[] = { "/usr/local/bin", "/usr/bin",
        "/bin", "/usr/lib/foo", ""
};
long bar (void *addr)
{
        return bar2 (addr);
}
[/tmp/gcc-bug-2]make
cc -fpic -ffixed-r13 -nostdinc   -c -o main.o main.c
gcc -shared -o libfoo.so main.o

  
Actual results:

The alignment of the thread variable 'fooo' has to be 16. Nevertheless, the 
value gcc assigns to it is 0x18, causing it to be non-aligned :

reading the output of readelf on the resulted shared object, one can see the 
alignment of TLS segment is 0x10:

  TLS            0x0000000000000ee8 0x0000000000010ee8 0x0000000000010ee8
                 0x0000000000000018 0x0000000000000028  R      10

but the value assigned to 'fooo' is 0x18:

   55: 0000000000000018    16 TLS     GLOBAL DEFAULT   18 fooo

which together sums up to 0x8 alignment, instead of 0x10.

ofcourse - this is a very simplified test case, the real case has a jmp_buf 
aligned incorrectly on 8 bytes, resulting with SIGBUS as soon as it is accessed.

Additional info:
I found the problem on RHEL3 U5 beta ( which is the latest one I have ), and 
checking with previous EL3 versions, i see the same behavior on EL3U3.
Comment 1 Yoav Zach 2005-05-18 16:39:53 EDT
I've just realized that I had to open an entry in the issue-tracker and not in 
bugzilla. I opened entry #73030 for that. Sorry for the confusion.
Thanks,
Yoav.
Comment 2 Jakub Jelinek 2005-05-19 08:53:18 EDT
That's actually a linker bug, not compiler bug.
Fixed by:
http://sources.redhat.com/ml/binutils/2003-11/msg00029.html
(so works properly in RHEL4), but I'll try to come up with some much smaller
patch for RHEL3.
Comment 3 Jakub Jelinek 2005-05-19 09:33:20 EDT
Created attachment 114565 [details]
binutils-2.14.90.0.4-tls-align.patch

Patch that ought to fix this.
Comment 11 Red Hat Bugzilla 2005-09-28 10:02:55 EDT
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on the solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHSA-2005-659.html

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