Bug 755872 - -fpie + -pie does not appear to work with __thread variables
Summary: -fpie + -pie does not appear to work with __thread variables
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: binutils
Version: 5.8
Hardware: Unspecified
OS: Unspecified
medium
medium
Target Milestone: rc
: ---
Assignee: Andreas Schwab
QA Contact: qe-baseos-tools-bugs
URL:
Whiteboard:
Depends On:
Blocks: 758797
TreeView+ depends on / blocked
 
Reported: 2011-11-22 10:00 UTC by Paolo Bonzini
Modified: 2013-01-09 11:56 UTC (History)
4 users (show)

Fixed In Version: binutils-2.17.50.0.6-20.el5
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2012-02-21 06:39:41 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2012:0271 0 normal SHIPPED_LIVE binutils bug fix update 2012-02-20 15:06:19 UTC

Description Paolo Bonzini 2011-11-22 10:00:49 UTC
Description of problem:
Compiling this little program as a PIE leads to problems on x86-64:

$ cat w.c
__thread int a;

int
main(void)
{
  return a;
}

Using

  gcc -o w -g -O2 -pie -fpie w.c

one sees

/usr/bin/ld: /tmp/ccU3JvLp.o: relocation R_X86_64_TPOFF32 against `a' can not
be used when making a shared object; recompile with -fPIC

It works with "-fpic -ftls-model=initial-exec", but not with "-fpic -ftls-model=local-exec".

Based on http://sourceware.org/bugzilla/show_bug.cgi?id=10434 and the two-line patch there (http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/bfd/elf64-x86-64.c.diff?cvsroot=src&r1=1.178&r2=1.179), it's a simple mistake where the linker allows local-exec only for non-PIC (!info->shared) instead of testing for executable vs shared (info->executable).

Version-Release number of selected component (if applicable):
binutils-2.17.50.0.6-14.el5

How reproducible:
100%

Steps to Reproduce:
1. See above.
  
Actual results:
Binaries that use TLS cannot be hardened with PIE.

Expected results:
Hardened binaries can use TLS.

Additional info:
Reproduced with QEMU 1.0-rc3.

Comment 5 errata-xmlrpc 2012-02-21 06:39:41 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

http://rhn.redhat.com/errata/RHBA-2012-0271.html


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