Bug 10434 - -fpie + -pie does not appear to work with __thread variables
Summary: -fpie + -pie does not appear to work with __thread variables
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.19
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-07-23 08:50 UTC by mathieu lacage
Modified: 2009-07-23 21:23 UTC (History)
2 users (show)

See Also:
Host: x86_64-redhat-linux
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description mathieu lacage 2009-07-23 08:50:22 UTC
[mathieu@mathieu-laptop elf-loader]$ ld --version
GNU ld version 2.19.51.0.2-17.fc11 20090204
[mathieu@mathieu-laptop test]$ gcc -dumpmachine
x86_64-redhat-linux
[mathieu@mathieu-laptop test]$ gcc --version
gcc (GCC) 4.4.0 20090506 (Red Hat 4.4.0-4)
[mathieu@mathieu-laptop test]$ uname -a
Linux mathieu-laptop 2.6.29.5-191.fc11.x86_64 #1 SMP Tue Jun 16
23:23:21 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux

testcase:

[mathieu@mathieu-laptop test]$ cat >test.c
__thread int g_a;

int main (int argc, char *argv[])
{
 g_a = 0;
 return 0;
}

[mathieu@mathieu-laptop test]$ gcc -fpie -pie ./test.c -o test
/usr/bin/ld: /tmp/ccsIE4YR.o: relocation R_X86_64_TPOFF32 against
`g_a' can not be used when making a shared object; recompile with
-fPIC
/tmp/ccsIE4YR.o: could not read symbols: Bad value
collect2: ld returned 1 exit status

The above works with "gcc -fpic -pie ./test.c -o test" (which, I know, is not
really supported).
Comment 1 mathieu lacage 2009-07-23 09:07:33 UTC
Note: this all appears to come from tls model local-exec. i.e., if I specify a
different tls model with __attribute__((tls_model("global-dynamic"))), the
linker does generate the above-mentionned error
Comment 2 mathieu lacage 2009-07-23 15:59:19 UTC
(In reply to comment #1)
> Note: this all appears to come from tls model local-exec. i.e., if I specify a
> different tls model with __attribute__((tls_model("global-dynamic"))), the
> linker does generate the above-mentionned error

s/does generate/does not generate/
Comment 3 Sourceware Commits 2009-07-23 21:22:43 UTC
Subject: Bug 10434

CVSROOT:	/cvs/src
Module name:	src
Changes by:	hjl@sourceware.org	2009-07-23 21:22:20

Modified files:
	bfd            : ChangeLog elf64-x86-64.c 
	ld/testsuite   : ChangeLog 
	ld/testsuite/ld-x86-64: x86-64.exp 
Added files:
	ld/testsuite/ld-x86-64: tlsle1.d tlsle1.s 

Log message:
	bfd/
	
	2009-07-23  H.J. Lu  <hongjiu.lu@intel.com>
	
	PR ld/10434
	* elf64-x86-64.c (elf64_x86_64_check_relocs): Check executable
	instead of shared for R_X86_64_TPOFF32.
	(elf64_x86_64_relocate_section): Likewise.
	
	ld/testsuite/
	
	2009-07-23  H.J. Lu  <hongjiu.lu@intel.com>
	
	PR ld/10434
	* ld-x86-64/tlsle1.d: New.
	* ld-x86-64/tlsle1.s: Likewise.
	
	* ld-x86-64/x86-64.exp: Run tlsle1.

Patches:
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&r1=1.4699&r2=1.4700
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/bfd/elf64-x86-64.c.diff?cvsroot=src&r1=1.178&r2=1.179
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/testsuite/ChangeLog.diff?cvsroot=src&r1=1.1132&r2=1.1133
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-x86-64/tlsle1.d.diff?cvsroot=src&r1=NONE&r2=1.1
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-x86-64/tlsle1.s.diff?cvsroot=src&r1=NONE&r2=1.1
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-x86-64/x86-64.exp.diff?cvsroot=src&r1=1.11&r2=1.12

Comment 4 H.J. Lu 2009-07-23 21:23:33 UTC
Fixed.