This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Properly align static TLS segments on Solaris 2/SPARC
- From: Rainer Orth <ro at CeBiTec dot Uni-Bielefeld dot DE>
- To: binutils at sourceware dot org
- Date: Thu, 21 Oct 2010 17:48:18 +0200
- Subject: Properly align static TLS segments on Solaris 2/SPARC
The following patch implements the SPARC side corresponding to
Properly align static TLS segments on Solaris 2
http://sourceware.org/ml/binutils/2010-09/msg00485.html
http://sourceware.org/ml/binutils/2010-10/msg00291.html
While trivial in principle, there are a couple of issues worth
mentioning:
* Since there is no Solaris 2-specific bfd vector for SPARC yet, this
patch needs to introduce it for both 32 and 64-bit so
elf_backend_static_tls_alignment can be set only for that target.
Although TLS support was only introduced in Solaris 9 (and backported
to 8), I'm using the same vector for all Solaris 2 releases so they
are all treated the same.
* As a consequence, both gas and gld need to be adapted to use the new
vector.
A sparc-sun-solaris2.10 GCC bootstrap with this gas and gld is in
progress at the moment, but well into stage 2, so both are able to
assemble and link.
Ok if the bootstrap passes and the TLS LE related failures are gone?
Thanks.
Rainer
2010-10-17 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
ld:
* emulparams/elf32_sparc_sol2.sh (OUTPUT_FORMAT): Set to
elf32-sparc-sol2.
* emulparams/elf64_sparc_sol2.sh (OUTPUT_FORMAT): Set to
elf64-sparc-sol2.
gas:
* config/tc-sparc.h [TE_SOLARIS] (ELF_TARGET_FORMAT): Define as
elf32-sparc-sol2.
(ELF64_TARGET_FORMAT): Define as elf64-sparc-sol2.
bfd:
* elfxx-sparc.c (tpoff): Define bed, static_tls_size.
Consider static_tls_alignment.
* elf32-sparc.c (TARGET_BIG_SYM): Redefine to
bfd_elf32_sparc_sol2_vec.
(TARGET_BIG_NAME): Redefine to elf32-sparc-sol2.
(elf32_bed): Redefine to elf32_sparc_sol2_bed.
(elf_backend_static_tls_alignment): Redefine to 8.
Include elf32-target.h.
(elf_backend_static_tls_alignment): Undef again for VxWorks.
* elf64-sparc.c (TARGET_BIG_SYM): Redefine to
bfd_elf64_sparc_sol2_vec.
(TARGET_BIG_NAME): Redefine to elf64-sparc-sol2.
(ELF_OSABI): Undef.
(elf64_bed): Redefine to elf64_sparc_sol2_bed.
(elf_backend_static_tls_alignment): Redefine to 16.
Include elf64-target.h.
* config.bfd (sparc-*-solaris2.[0-6]): Split from sparc-*-elf*.
Set targ_defvec to bfd_elf32_sparc_sol2_vec.
[BFD64] (sparc-*-solaris2*): Set targ_defvec to
bfd_elf32_sparc_sol2_vec.
Replace bfd_elf64_sparc_vec by bfd_elf64_sparc_sol2_vec in
targ_selvecs.
* configure.in: Handle bfd_elf32_sparc_sol2_vec,
bfd_elf64_sparc_sol2_vec.
* configure: Regenerate.
* targets.c (bfd_elf32_sparc_sol2_vec): Declare.
(bfd_elf64_sparc_sol2_vec): Declare.
(_bfd_target_vector): Add bfd_elf32_sparc_sol2_vec,
bfd_elf64_sparc_sol2_vec.
Index: bfd/config.bfd
===================================================================
RCS file: /cvs/src/src/bfd/config.bfd,v
retrieving revision 1.269
diff -u -p -r1.269 config.bfd
--- bfd/config.bfd 2 Sep 2010 22:54:43 -0000 1.269
+++ bfd/config.bfd 21 Oct 2010 15:14:24 -0000
@@ -1395,14 +1395,18 @@ case "${targ}" in
targ_defvec=bfd_elf32_sparc_vec
targ_selvecs=sparcnetbsd_vec
;;
- sparc-*-elf* | sparc-*-solaris2.[0-6] | sparc-*-solaris2.[0-6].*)
+ sparc-*-elf*)
targ_defvec=bfd_elf32_sparc_vec
targ_selvecs=sunos_big_vec
;;
+ sparc-*-solaris2.[0-6] | sparc-*-solaris2.[0-6].*)
+ targ_defvec=bfd_elf32_sparc_sol2_vec
+ targ_selvecs=sunos_big_vec
+ ;;
#ifdef BFD64
sparc-*-solaris2* | sparcv9-*-solaris2* | sparc64-*-solaris2*)
- targ_defvec=bfd_elf32_sparc_vec
- targ_selvecs="bfd_elf64_sparc_vec sunos_big_vec"
+ targ_defvec=bfd_elf32_sparc_sol2_vec
+ targ_selvecs="bfd_elf64_sparc_sol2_vec sunos_big_vec"
want64=true
;;
#endif
Index: bfd/configure.in
===================================================================
RCS file: /cvs/src/src/bfd/configure.in,v
retrieving revision 1.286
diff -u -p -r1.286 configure.in
--- bfd/configure.in 29 Jun 2010 04:17:22 -0000 1.286
+++ bfd/configure.in 21 Oct 2010 15:14:24 -0000
@@ -783,6 +783,7 @@ do
bfd_elf32_shnbsd_vec) tb="$tb elf32-sh.lo elf-vxworks.lo elf32.lo $elf coff-sh.lo cofflink.lo" ;;
bfd_elf32_shvxworks_vec) tb="$tb elf32-sh.lo elf-vxworks.lo elf32.lo $elf coff-sh.lo" ;;
bfd_elf32_sparc_vec) tb="$tb elf32-sparc.lo elfxx-sparc.lo elf-vxworks.lo elf32.lo $elf" ;;
+ bfd_elf32_sparc_sol2_vec) tb="$tb elf32-sparc.lo elfxx-sparc.lo elf-vxworks.lo elf32.lo $elf" ;;
bfd_elf32_sparc_vxworks_vec) tb="$tb elf32-sparc.lo elfxx-sparc.lo elf-vxworks.lo elf32.lo $elf" ;;
bfd_elf32_spu_vec) tb="$tb elf32-spu.lo elf32.lo $elf" ;;
bfd_elf32_tic6x_be_vec) tb="$tb elf32-tic6x.lo elf32.lo $elf" ;;
@@ -820,6 +821,7 @@ do
bfd_elf64_sh64nbsd_vec) tb="$tb elf64-sh64.lo elf64.lo $elf" target_size=64 ;;
bfd_elf64_sparc_vec) tb="$tb elf64-sparc.lo elfxx-sparc.lo elf-vxworks.lo elf64.lo $elf"; target_size=64 ;;
bfd_elf64_sparc_freebsd_vec) tb="$tb elf64-sparc.lo elfxx-sparc.lo elf-vxworks.lo elf64.lo $elf"; target_size=64 ;;
+ bfd_elf64_sparc_sol2_vec) tb="$tb elf64-sparc.lo elfxx-sparc.lo elf-vxworks.lo elf64.lo $elf"; target_size=64 ;;
bfd_elf64_tradbigmips_vec) tb="$tb elf64-mips.lo elf64.lo elfxx-mips.lo elf-vxworks.lo elf32.lo $elf ecofflink.lo"; target_size=64 ;;
bfd_elf64_tradlittlemips_vec) tb="$tb elf64-mips.lo elf64.lo elfxx-mips.lo elf-vxworks.lo elf32.lo $elf ecofflink.lo"; target_size=64 ;;
bfd_elf64_x86_64_freebsd_vec) tb="$tb elf64-x86-64.lo elf-ifunc.lo elf64.lo $elf"; target_size=64 ;;
Index: bfd/elf32-sparc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-sparc.c,v
retrieving revision 1.93
diff -u -p -r1.93 elf32-sparc.c
--- bfd/elf32-sparc.c 25 Aug 2010 14:53:44 -0000 1.93
+++ bfd/elf32-sparc.c 21 Oct 2010 15:14:24 -0000
@@ -1,6 +1,6 @@
/* SPARC-specific support for 32-bit ELF
Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
- 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+ 2003, 2004, 2005, 2006, 2007, 2010 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
@@ -246,6 +246,23 @@ elf32_sparc_add_symbol_hook (bfd * abfd,
#include "elf32-target.h"
+/* Solaris 2. */
+
+#undef TARGET_BIG_SYM
+#define TARGET_BIG_SYM bfd_elf32_sparc_sol2_vec
+#undef TARGET_BIG_NAME
+#define TARGET_BIG_NAME "elf32-sparc-sol2"
+
+#undef elf32_bed
+#define elf32_bed elf32_sparc_sol2_bed
+
+/* The 32-bit static TLS arena size is rounded to the nearest 8-byte
+ boundary. */
+#undef elf_backend_static_tls_alignment
+#define elf_backend_static_tls_alignment 8
+
+#include "elf32-target.h"
+
/* A wrapper around _bfd_sparc_elf_link_hash_table_create that identifies
the target system as VxWorks. */
@@ -305,6 +322,7 @@ elf32_sparc_vxworks_final_write_processi
#undef elf_backend_final_write_processing
#define elf_backend_final_write_processing \
elf32_sparc_vxworks_final_write_processing
+#undef elf_backend_static_tls_alignment
#undef elf32_bed
#define elf32_bed sparc_elf_vxworks_bed
Index: bfd/elf64-sparc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-sparc.c,v
retrieving revision 1.123
diff -u -p -r1.123 elf64-sparc.c
--- bfd/elf64-sparc.c 4 Oct 2010 14:13:09 -0000 1.123
+++ bfd/elf64-sparc.c 21 Oct 2010 15:14:24 -0000
@@ -1,6 +1,6 @@
/* SPARC-specific support for 64-bit ELF
Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
- 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+ 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
@@ -934,3 +934,23 @@ const struct elf_size_info elf64_sparc_s
#include "elf64-target.h"
+/* Solaris 2. */
+
+#undef TARGET_BIG_SYM
+#define TARGET_BIG_SYM bfd_elf64_sparc_sol2_vec
+#undef TARGET_BIG_NAME
+#define TARGET_BIG_NAME "elf64-sparc-sol2"
+
+/* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE
+ objects won't be recognized. */
+#undef ELF_OSABI
+
+#undef elf64_bed
+#define elf64_bed elf64_sparc_sol2_bed
+
+/* The 64-bit static TLS arena size is rounded to the nearest 16-byte
+ boundary. */
+#undef elf_backend_static_tls_alignment
+#define elf_backend_static_tls_alignment 16
+
+#include "elf64-target.h"
Index: bfd/elfxx-sparc.c
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-sparc.c,v
retrieving revision 1.55
diff -u -p -r1.55 elfxx-sparc.c
--- bfd/elfxx-sparc.c 4 Oct 2010 14:13:10 -0000 1.55
+++ bfd/elfxx-sparc.c 21 Oct 2010 15:14:24 -0000
@@ -2819,11 +2819,16 @@ static bfd_vma
tpoff (struct bfd_link_info *info, bfd_vma address)
{
struct elf_link_hash_table *htab = elf_hash_table (info);
+ const struct elf_backend_data *bed = get_elf_backend_data (info->output_bfd);
+ bfd_vma static_tls_size;
/* If tls_sec is NULL, we should have signalled an error already. */
if (htab->tls_sec == NULL)
return 0;
- return address - htab->tls_size - htab->tls_sec->vma;
+
+ /* Consider special static TLS alignment requirements. */
+ static_tls_size = BFD_ALIGN (htab->tls_size, bed->static_tls_alignment);
+ return address - static_tls_size - htab->tls_sec->vma;
}
/* Return the relocation value for a %gdop relocation. */
Index: bfd/targets.c
===================================================================
RCS file: /cvs/src/src/bfd/targets.c,v
retrieving revision 1.195
diff -u -p -r1.195 targets.c
--- bfd/targets.c 18 Aug 2010 12:24:07 -0000 1.195
+++ bfd/targets.c 21 Oct 2010 15:14:24 -0000
@@ -676,6 +676,7 @@ extern const bfd_target bfd_elf32_shlvxw
extern const bfd_target bfd_elf32_shnbsd_vec;
extern const bfd_target bfd_elf32_shvxworks_vec;
extern const bfd_target bfd_elf32_sparc_vec;
+extern const bfd_target bfd_elf32_sparc_sol2_vec;
extern const bfd_target bfd_elf32_sparc_vxworks_vec;
extern const bfd_target bfd_elf32_spu_vec;
extern const bfd_target bfd_elf32_tic6x_be_vec;
@@ -713,6 +714,7 @@ extern const bfd_target bfd_elf64_sh64ln
extern const bfd_target bfd_elf64_sh64nbsd_vec;
extern const bfd_target bfd_elf64_sparc_vec;
extern const bfd_target bfd_elf64_sparc_freebsd_vec;
+extern const bfd_target bfd_elf64_sparc_sol2_vec;
extern const bfd_target bfd_elf64_tradbigmips_vec;
extern const bfd_target bfd_elf64_tradlittlemips_vec;
extern const bfd_target bfd_elf64_x86_64_freebsd_vec;
@@ -1025,6 +1027,7 @@ static const bfd_target * const _bfd_tar
&bfd_elf32_sh64blin_vec,
#endif
&bfd_elf32_sparc_vec,
+ &bfd_elf32_sparc_sol2_vec,
&bfd_elf32_sparc_vxworks_vec,
&bfd_elf32_spu_vec,
&bfd_elf32_tic6x_be_vec,
@@ -1063,6 +1066,7 @@ static const bfd_target * const _bfd_tar
&bfd_elf64_sh64blin_vec,
&bfd_elf64_sparc_vec,
&bfd_elf64_sparc_freebsd_vec,
+ &bfd_elf64_sparc_sol2_vec,
&bfd_elf64_tradbigmips_vec,
&bfd_elf64_tradlittlemips_vec,
&bfd_elf64_x86_64_freebsd_vec,
Index: gas/config/tc-sparc.h
===================================================================
RCS file: /cvs/src/src/gas/config/tc-sparc.h,v
retrieving revision 1.30
diff -u -p -r1.30 tc-sparc.h
--- gas/config/tc-sparc.h 2 Sep 2009 07:24:20 -0000 1.30
+++ gas/config/tc-sparc.h 21 Oct 2010 15:14:25 -0000
@@ -1,6 +1,6 @@
/* tc-sparc.h - Macros and type defines for the sparc.
Copyright 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
- 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2008
+ 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2008, 2010
Free Software Foundation, Inc.
This file is part of GAS, the GNU Assembler.
@@ -37,6 +37,11 @@ struct frag;
#define ELF64_TARGET_FORMAT "elf64-sparc-freebsd"
#endif
+#ifdef TE_SOLARIS
+#define ELF_TARGET_FORMAT "elf32-sparc-sol2"
+#define ELF64_TARGET_FORMAT "elf64-sparc-sol2"
+#endif
+
#ifndef ELF_TARGET_FORMAT
#define ELF_TARGET_FORMAT "elf32-sparc"
#endif
Index: ld/emulparams/elf32_sparc_sol2.sh
===================================================================
RCS file: /cvs/src/src/ld/emulparams/elf32_sparc_sol2.sh,v
retrieving revision 1.2
diff -u -p -r1.2 elf32_sparc_sol2.sh
--- ld/emulparams/elf32_sparc_sol2.sh 12 Oct 2010 18:39:36 -0000 1.2
+++ ld/emulparams/elf32_sparc_sol2.sh 21 Oct 2010 15:14:32 -0000
@@ -1,3 +1,4 @@
. ${srcdir}/emulparams/elf32_sparc.sh
. ${srcdir}/emulparams/solaris2.sh
EXTRA_EM_FILE=solaris2
+OUTPUT_FORMAT="elf32-sparc-sol2"
Index: ld/emulparams/elf64_sparc_sol2.sh
===================================================================
RCS file: /cvs/src/src/ld/emulparams/elf64_sparc_sol2.sh,v
retrieving revision 1.2
diff -u -p -r1.2 elf64_sparc_sol2.sh
--- ld/emulparams/elf64_sparc_sol2.sh 12 Oct 2010 18:39:36 -0000 1.2
+++ ld/emulparams/elf64_sparc_sol2.sh 21 Oct 2010 15:14:32 -0000
@@ -1,3 +1,4 @@
. ${srcdir}/emulparams/elf64_sparc.sh
. ${srcdir}/emulparams/solaris2.sh
EXTRA_EM_FILE=solaris2
+OUTPUT_FORMAT="elf64-sparc-sol2"
--
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University