Bug 13301 - Wrong linker relaxation for TLS_LDM_CALL and TLS_GD_CALL on SPARC
Summary: Wrong linker relaxation for TLS_LDM_CALL and TLS_GD_CALL on SPARC
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.22
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-16 14:41 UTC by Eric Botcazou
Modified: 2011-10-19 06:58 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Botcazou 2011-10-16 14:41:00 UTC
This is the miscompilation of MPFR 3.1.0 on SPARC/Linux, initially filed as
  http://gcc.gnu.org/PR50683

The compiler generates at -O2 -fPIC:

	add	%l7, %l3, %l3, %tgd_add(__gmpfr_flags)
[...]
	call	__tls_get_addr, %tgd_call(__gmpfr_flags)
	 mov	%l3, %o0
	ld	[%o0], %g1

and the linker turns this into:

   0x00014d14 <+504>:   add  %g7, %o0, %o0
   0x00014d18 <+508>:   mov  %l3, %o0
   0x00014d1c <+512>:   ld  [ %o0 ], %g1

so segfault on the load.  Both TLS_LDM_CALL and TLS_GD_CALL are affected.
Comment 1 cvs-commit@gcc.gnu.org 2011-10-19 00:32:28 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	davem@sourceware.org	2011-10-19 00:32:25

Modified files:
	bfd            : ChangeLog elfxx-sparc.c 
	gold           : ChangeLog sparc.cc 
	ld/testsuite   : ChangeLog 
	ld/testsuite/ld-sparc: tlssunbin32.dd tlssunbin64.dd 
	                       tlssunpic32.dd tlssunpic64.dd 

Log message:
	Fix sparc TLS call relaxation when the delay slot sets up %o0.
	
	bfd/
	
	PR binutils/13301
	* elfxx-sparc.c (sparc_elf_find_reloc_at_ofs): New function.
	(_bfd_sparc_elf_relocate_section): Always move the __tls_get_addr
	call delay slot instruction forward 4 bytes when performing
	relaxation.
	
	gold/
	
	PR binutils/13301
	* sparc.cc (Target_sparc::Relocate::reloc_adjust_addr_): New
	member to track relocation locations that have moved during TLS
	reloc optimizations.
	(Target_sparc::Relocate::Relocate): Initialize to NULL.
	(Target_sparc::Relocate::relocate): Adjust view down by 4
	bytes if it matches reloc_adjust_addr_.
	(Target_sparc::Relocate::relocate_tls): Always move the
	__tls_get_addr call delay slot instruction forward 4 bytes when
	performing relaxation.
	
	ld/testsuite/
	
	* ld-sparc/tlssunbin32.dd: Update for TLS call relaxation fix
	for PR 13301.
	* ld-sparc/tlssunbin64.dd: Likewise.
	* ld-sparc/tlssunpic32.dd: Likewise.
	* ld-sparc/tlssunpic64.dd: Likewise.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&r1=1.5491&r2=1.5492
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elfxx-sparc.c.diff?cvsroot=src&r1=1.60&r2=1.61
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/ChangeLog.diff?cvsroot=src&r1=1.841&r2=1.842
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/sparc.cc.diff?cvsroot=src&r1=1.49&r2=1.50
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ChangeLog.diff?cvsroot=src&r1=1.1469&r2=1.1470
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-sparc/tlssunbin32.dd.diff?cvsroot=src&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-sparc/tlssunbin64.dd.diff?cvsroot=src&r1=1.2&r2=1.3
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-sparc/tlssunpic32.dd.diff?cvsroot=src&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-sparc/tlssunpic64.dd.diff?cvsroot=src&r1=1.2&r2=1.3
Comment 2 cvs-commit@gcc.gnu.org 2011-10-19 00:38:56 UTC
CVSROOT:	/cvs/src
Module name:	src
Branch: 	binutils-2_22-branch
Changes by:	davem@sourceware.org	2011-10-19 00:38:54

Modified files:
	bfd            : ChangeLog elfxx-sparc.c 
	gold           : ChangeLog sparc.cc 
	ld/testsuite   : ChangeLog 
	ld/testsuite/ld-sparc: tlssunbin32.dd tlssunbin64.dd 
	                       tlssunpic32.dd tlssunpic64.dd 

Log message:
	Fix sparc TLS call relaxation when the delay slot sets up %o0.
	
	bfd/
	
	PR binutils/13301
	* elfxx-sparc.c (sparc_elf_find_reloc_at_ofs): New function.
	(_bfd_sparc_elf_relocate_section): Always move the __tls_get_addr
	call delay slot instruction forward 4 bytes when performing
	relaxation.
	
	gold/
	
	PR binutils/13301
	* sparc.cc (Target_sparc::Relocate::reloc_adjust_addr_): New
	member to track relocation locations that have moved during TLS
	reloc optimizations.
	(Target_sparc::Relocate::Relocate): Initialize to NULL.
	(Target_sparc::Relocate::relocate): Adjust view down by 4
	bytes if it matches reloc_adjust_addr_.
	(Target_sparc::Relocate::relocate_tls): Always move the
	__tls_get_addr call delay slot instruction forward 4 bytes when
	performing relaxation.
	
	ld/testsuite/
	
	* ld-sparc/tlssunbin32.dd: Update for TLS call relaxation fix
	for PR 13301.
	* ld-sparc/tlssunbin64.dd: Likewise.
	* ld-sparc/tlssunpic32.dd: Likewise.
	* ld-sparc/tlssunpic64.dd: Likewise.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.5473.2.6&r2=1.5473.2.7
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elfxx-sparc.c.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.60&r2=1.60.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/ChangeLog.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.824.2.1&r2=1.824.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/sparc.cc.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.48&r2=1.48.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ChangeLog.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.1460.2.3&r2=1.1460.2.4
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-sparc/tlssunbin32.dd.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.3&r2=1.3.20.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-sparc/tlssunbin64.dd.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.2&r2=1.2.20.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-sparc/tlssunpic32.dd.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.3&r2=1.3.20.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-sparc/tlssunpic64.dd.diff?cvsroot=src&only_with_tag=binutils-2_22-branch&r1=1.2&r2=1.2.20.1
Comment 3 Eric Botcazou 2011-10-19 06:58:46 UTC
Fixed in 2.22 and later.