This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

vxworks tls part 2


here's the next bit of vxworks TLS support. Shared objects need to insert some additional dynamic tags to tell the loader about the .tls_data and .tls_vars sections. This patch accomplishes that by two helpers in elf-vxworks.c to allocated and then initialize the dynamic tags. We then call these two helpers from the appropriate two places in all the backends supported.

tested on arm, sh, mips, i686, sparc and powerpc vxworks targets. I also build elf targets for the same architectures and observed no regressions.

ok?

nathan
--
Nathan Sidwell    ::   http://www.codesourcery.com   ::         CodeSourcery

2007-11-07  Nathan Sidwell  <nathan@codesourcery.com>

	include/elf/
	* vxworks.h: New.

	bfd/
	* elf-vxworks.h (elf_vxworks_add_dynamic_entries): Declare.
	(elf_vxworks_finish_dynamic_entry): Declare.
	* elf-vxworks.c: Include elf/vxworks.h.
	(elf_vxworks_add_dynamic_entries): New.
	(elf_vxworks_finish_dynamic_entry): New.
	* Makefile.am (elf-vxworks.lo): Add dependency.
	* Makefile.in (elf-vxworks.lo): Add dependency.
	* elf32-i386.c (elf_i386_size_dynamic_sections,
	elf_i386_finish_dynamic_sections): Call
	elf_vxworks_add_dynamic_entries and
	elf_vxworks_finish_dynamic_entry.
	* elf32-ppc.c (ppc_elf_size_dynamic_sections,
	ppc_elf_finish_dynamic_sections): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_size_dynamic_sections,
	sparc_finish_dyn): Likewise.
	* elf32-sh.c (sh_elf_size_dynamic_sections,
	sh_elf_finish_dynamic_sections): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_size_dynamic_sections,
	_bfd_mips_elf_finish_dynamic_sections): Likewise.
	* elf32-arm.c (elf32_arm_size_dynamic_sections,
	elf32_arm_finish_dynamic_sections): Likewise.

	ld/
	* ld-vxworks/tls-1.d: New.
	* ld-vxworks/tls-1.s: New.

Index: bfd/Makefile.am
===================================================================
RCS file: /cvs/src/src/bfd/Makefile.am,v
retrieving revision 1.207
diff -c -3 -p -r1.207 Makefile.am
*** bfd/Makefile.am	24 Oct 2007 04:54:37 -0000	1.207
--- bfd/Makefile.am	7 Nov 2007 12:31:39 -0000
*************** elf-eh-frame.lo: elf-eh-frame.c $(INCDIR
*** 1580,1586 ****
  elf-vxworks.lo: elf-vxworks.c $(INCDIR)/filenames.h \
    $(INCDIR)/hashtab.h elf-bfd.h $(INCDIR)/elf/common.h \
    $(INCDIR)/elf/internal.h $(INCDIR)/elf/external.h $(INCDIR)/bfdlink.h \
!   elf-vxworks.h
  epoc-pe-arm.lo: epoc-pe-arm.c pe-arm.c $(INCDIR)/filenames.h \
    coff-arm.c $(INCDIR)/hashtab.h $(INCDIR)/coff/arm.h \
    $(INCDIR)/coff/external.h $(INCDIR)/coff/internal.h \
--- 1580,1586 ----
  elf-vxworks.lo: elf-vxworks.c $(INCDIR)/filenames.h \
    $(INCDIR)/hashtab.h elf-bfd.h $(INCDIR)/elf/common.h \
    $(INCDIR)/elf/internal.h $(INCDIR)/elf/external.h $(INCDIR)/bfdlink.h \
!   $(INCDIR)/elf/vxworks.h elf-vxworks.h
  epoc-pe-arm.lo: epoc-pe-arm.c pe-arm.c $(INCDIR)/filenames.h \
    coff-arm.c $(INCDIR)/hashtab.h $(INCDIR)/coff/arm.h \
    $(INCDIR)/coff/external.h $(INCDIR)/coff/internal.h \
Index: bfd/Makefile.in
===================================================================
RCS file: /cvs/src/src/bfd/Makefile.in,v
retrieving revision 1.228
diff -c -3 -p -r1.228 Makefile.in
*** bfd/Makefile.in	24 Oct 2007 04:54:38 -0000	1.228
--- bfd/Makefile.in	7 Nov 2007 12:31:42 -0000
*************** elf-eh-frame.lo: elf-eh-frame.c $(INCDIR
*** 2160,2166 ****
  elf-vxworks.lo: elf-vxworks.c $(INCDIR)/filenames.h \
    $(INCDIR)/hashtab.h elf-bfd.h $(INCDIR)/elf/common.h \
    $(INCDIR)/elf/internal.h $(INCDIR)/elf/external.h $(INCDIR)/bfdlink.h \
!   elf-vxworks.h
  epoc-pe-arm.lo: epoc-pe-arm.c pe-arm.c $(INCDIR)/filenames.h \
    coff-arm.c $(INCDIR)/hashtab.h $(INCDIR)/coff/arm.h \
    $(INCDIR)/coff/external.h $(INCDIR)/coff/internal.h \
--- 2160,2166 ----
  elf-vxworks.lo: elf-vxworks.c $(INCDIR)/filenames.h \
    $(INCDIR)/hashtab.h elf-bfd.h $(INCDIR)/elf/common.h \
    $(INCDIR)/elf/internal.h $(INCDIR)/elf/external.h $(INCDIR)/bfdlink.h \
!   $(INCDIR)/elf/vxworks.h elf-vxworks.h
  epoc-pe-arm.lo: epoc-pe-arm.c pe-arm.c $(INCDIR)/filenames.h \
    coff-arm.c $(INCDIR)/hashtab.h $(INCDIR)/coff/arm.h \
    $(INCDIR)/coff/external.h $(INCDIR)/coff/internal.h \
Index: bfd/elf-vxworks.c
===================================================================
RCS file: /cvs/src/src/bfd/elf-vxworks.c,v
retrieving revision 1.9
diff -c -3 -p -r1.9 elf-vxworks.c
*** bfd/elf-vxworks.c	3 Jul 2007 14:26:40 -0000	1.9
--- bfd/elf-vxworks.c	7 Nov 2007 12:31:42 -0000
***************
*** 25,30 ****
--- 25,31 ----
  #include "libbfd.h"
  #include "elf-bfd.h"
  #include "elf-vxworks.h"
+ #include "elf/vxworks.h"
  
  /* Return true if symbol NAME, as defined by ABFD, is one of the special
     __GOTT_BASE__ or __GOTT_INDEX__ symbols.  */
*************** elf_vxworks_final_write_processing (bfd 
*** 225,227 ****
--- 226,294 ----
    if (sec)
      d->this_hdr.sh_info = elf_section_data (sec)->this_idx;
  }
+ 
+ /* Add the dynamic entries required by VxWorks.  These point to the
+    tls sections.  */
+ 
+ bfd_boolean
+ elf_vxworks_add_dynamic_entries (bfd *output_bfd, struct bfd_link_info *info)
+ {
+   if (bfd_get_section_by_name (output_bfd, ".tls_data"))
+     {
+       if (!_bfd_elf_add_dynamic_entry (info, DT_VX_WRS_TLS_DATA_START, 0)
+ 	  || !_bfd_elf_add_dynamic_entry (info, DT_VX_WRS_TLS_DATA_SIZE, 0)
+ 	  || !_bfd_elf_add_dynamic_entry (info, DT_VX_WRS_TLS_DATA_ALIGN, 0))
+ 	return FALSE;
+     }
+   if (bfd_get_section_by_name (output_bfd, ".tls_vars"))
+     {
+       if (!_bfd_elf_add_dynamic_entry (info, DT_VX_WRS_TLS_VARS_START, 0)
+ 	  || !_bfd_elf_add_dynamic_entry (info, DT_VX_WRS_TLS_VARS_SIZE, 0))
+ 	return FALSE;
+     }
+   return TRUE;
+ }
+ 
+ /* If *DYN is one of the VxWorks-specific dynamic entries, then fill
+    in the value now  and return TRUE.  Otherwise return FALSE.  */
+ 
+ bfd_boolean
+ elf_vxworks_finish_dynamic_entry (bfd *output_bfd, Elf_Internal_Dyn *dyn)
+ {
+   asection *sec;
+   
+   switch (dyn->d_tag)
+     {
+     default:
+       return FALSE;
+       
+     case DT_VX_WRS_TLS_DATA_START:
+       sec = bfd_get_section_by_name (output_bfd, ".tls_data");
+       dyn->d_un.d_ptr = sec->vma;
+       break;
+       
+     case DT_VX_WRS_TLS_DATA_SIZE:
+       sec = bfd_get_section_by_name (output_bfd, ".tls_data");
+       dyn->d_un.d_val = sec->size;
+       break;
+       
+     case DT_VX_WRS_TLS_DATA_ALIGN:
+       sec = bfd_get_section_by_name (output_bfd, ".tls_data");
+       dyn->d_un.d_val
+ 	= (bfd_size_type)1 << bfd_get_section_alignment (abfd, sec);
+       break;
+       
+     case DT_VX_WRS_TLS_VARS_START:
+       sec = bfd_get_section_by_name (output_bfd, ".tls_vars");
+       dyn->d_un.d_ptr = sec->vma;
+       break;
+       
+     case DT_VX_WRS_TLS_VARS_SIZE:
+       sec = bfd_get_section_by_name (output_bfd, ".tls_vars");
+       dyn->d_un.d_val = sec->size;
+       break;
+     }
+   return TRUE;
+ }
+ 
+ 
Index: bfd/elf-vxworks.h
===================================================================
RCS file: /cvs/src/src/bfd/elf-vxworks.h,v
retrieving revision 1.4
diff -c -3 -p -r1.4 elf-vxworks.h
*** bfd/elf-vxworks.h	3 Jul 2007 14:26:40 -0000	1.4
--- bfd/elf-vxworks.h	7 Nov 2007 12:31:42 -0000
*************** bfd_boolean elf_vxworks_emit_relocs
*** 33,35 ****
--- 33,38 ----
  void elf_vxworks_final_write_processing (bfd *, bfd_boolean);
  bfd_boolean elf_vxworks_create_dynamic_sections
    (bfd *, struct bfd_link_info *, asection **);
+ bfd_boolean elf_vxworks_add_dynamic_entries (bfd *, struct bfd_link_info *);
+ bfd_boolean elf_vxworks_finish_dynamic_entry (bfd *, Elf_Internal_Dyn *);
+ 
Index: bfd/elf32-arm.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-arm.c,v
retrieving revision 1.129
diff -c -3 -p -r1.129 elf32-arm.c
*** bfd/elf32-arm.c	15 Oct 2007 02:00:11 -0000	1.129
--- bfd/elf32-arm.c	7 Nov 2007 12:31:49 -0000
*************** elf32_arm_size_dynamic_sections (bfd * o
*** 8723,8728 ****
--- 8723,8731 ----
  	  if (!add_dynamic_entry (DT_TEXTREL, 0))
  	    return FALSE;
  	}
+       if (htab->vxworks_p
+ 	  && !elf_vxworks_add_dynamic_entries (output_bfd, info))
+ 	return FALSE;
      }
  #undef add_dynamic_entry
  
*************** elf32_arm_finish_dynamic_sections (bfd *
*** 9065,9070 ****
--- 9068,9076 ----
  	      unsigned int type;
  
  	    default:
+ 	      if (htab->vxworks_p
+ 		  && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn))
+ 		bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
  	      break;
  
  	    case DT_HASH:
Index: bfd/elf32-i386.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-i386.c,v
retrieving revision 1.182
diff -c -3 -p -r1.182 elf32-i386.c
*** bfd/elf32-i386.c	18 Oct 2007 09:13:51 -0000	1.182
--- bfd/elf32-i386.c	7 Nov 2007 12:31:52 -0000
*************** elf_i386_size_dynamic_sections (bfd *out
*** 2374,2379 ****
--- 2374,2382 ----
  		return FALSE;
  	    }
  	}
+       if (htab->is_vxworks
+ 	  && !elf_vxworks_add_dynamic_entries (output_bfd, info))
+ 	return FALSE;
      }
  #undef add_dynamic_entry
  
*************** elf_i386_finish_dynamic_sections (bfd *o
*** 3796,3801 ****
--- 3799,3807 ----
  	  switch (dyn.d_tag)
  	    {
  	    default:
+ 	      if (htab->is_vxworks
+ 		  && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn))
+ 		break;
  	      continue;
  
  	    case DT_PLTGOT:
Index: bfd/elf32-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-ppc.c,v
retrieving revision 1.223
diff -c -3 -p -r1.223 elf32-ppc.c
*** bfd/elf32-ppc.c	6 Nov 2007 03:59:14 -0000	1.223
--- bfd/elf32-ppc.c	7 Nov 2007 12:31:58 -0000
*************** ppc_elf_size_dynamic_sections (bfd *outp
*** 5188,5194 ****
  	  if (!add_dynamic_entry (DT_TEXTREL, 0))
  	    return FALSE;
  	}
!     }
  #undef add_dynamic_entry
  
    return TRUE;
--- 5188,5197 ----
  	  if (!add_dynamic_entry (DT_TEXTREL, 0))
  	    return FALSE;
  	}
!       if (htab->is_vxworks
! 	  && !elf_vxworks_add_dynamic_entries (output_bfd, info))
! 	return FALSE;
!    }
  #undef add_dynamic_entry
  
    return TRUE;
*************** ppc_elf_finish_dynamic_sections (bfd *ou
*** 7353,7358 ****
--- 7356,7364 ----
  	      continue;
  
  	    default:
+ 	      if (htab->is_vxworks
+ 		  && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn))
+ 		break;
  	      continue;
  	    }
  
Index: bfd/elf32-sh.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-sh.c,v
retrieving revision 1.153
diff -c -3 -p -r1.153 elf32-sh.c
*** bfd/elf32-sh.c	28 Sep 2007 08:43:45 -0000	1.153
--- bfd/elf32-sh.c	7 Nov 2007 12:32:02 -0000
*************** sh_elf_size_dynamic_sections (bfd *outpu
*** 3138,3143 ****
--- 3138,3146 ----
  		return FALSE;
  	    }
  	}
+       if (htab->vxworks_p
+ 	  && !elf_vxworks_add_dynamic_entries (output_bfd, info))
+ 	return FALSE;
      }
  #undef add_dynamic_entry
  
*************** sh_elf_finish_dynamic_sections (bfd *out
*** 5763,5768 ****
--- 5766,5774 ----
  	  switch (dyn.d_tag)
  	    {
  	    default:
+ 	      if (htab->vxworks_p
+ 		  && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn))
+ 		bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
  	      break;
  
  #ifdef INCLUDE_SHMEDIA
Index: bfd/elfxx-mips.c
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-mips.c,v
retrieving revision 1.217
diff -c -3 -p -r1.217 elfxx-mips.c
*** bfd/elfxx-mips.c	25 Oct 2007 11:38:30 -0000	1.217
--- bfd/elfxx-mips.c	7 Nov 2007 12:32:10 -0000
*************** _bfd_mips_elf_size_dynamic_sections (bfd
*** 7666,7671 ****
--- 7666,7674 ----
  	      && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_OPTIONS, 0))
  	    return FALSE;
  	}
+       if (htab->is_vxworks
+ 	  && !elf_vxworks_add_dynamic_entries (output_bfd, info))
+ 	return FALSE;
      }
  
    return TRUE;
*************** _bfd_mips_elf_finish_dynamic_sections (b
*** 8893,8898 ****
--- 8896,8904 ----
  
  	    default:
  	      swap_out_p = FALSE;
+ 	      if (htab->is_vxworks
+ 		  && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn))
+ 		swap_out_p = TRUE;
  	      break;
  	    }
  
Index: bfd/elfxx-sparc.c
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-sparc.c,v
retrieving revision 1.35
diff -c -3 -p -r1.35 elfxx-sparc.c
*** bfd/elfxx-sparc.c	26 Sep 2007 13:45:32 -0000	1.35
--- bfd/elfxx-sparc.c	7 Nov 2007 12:32:12 -0000
*************** _bfd_sparc_elf_size_dynamic_sections (bf
*** 2396,2401 ****
--- 2396,2404 ----
  		eht->dynsymcount++;
  	      }
  	}
+       if (htab->is_vxworks
+ 	  && !elf_vxworks_add_dynamic_entries (output_bfd, info))
+ 	return FALSE;
      }
  #undef add_dynamic_entry
  
*************** sparc_finish_dyn (bfd *output_bfd, struc
*** 3846,3851 ****
--- 3849,3857 ----
  	      bed->s->swap_dyn_out (output_bfd, &dyn, dyncon);
  	    }
  	}
+       else if (htab->is_vxworks
+ 	       && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn))
+ 	bed->s->swap_dyn_out (output_bfd, &dyn, dyncon);
        else if (abi_64_p && dyn.d_tag == DT_SPARC_REGISTER)
  	{
  	  if (stt_regidx == -1)
Index: include/elf/vxworks.h
===================================================================
RCS file: include/elf/vxworks.h
diff -N include/elf/vxworks.h
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- include/elf/vxworks.h	7 Nov 2007 12:32:18 -0000
***************
*** 0 ****
--- 1,32 ----
+ /* VxWorks ELF support for BFD.
+    Copyright 2007
+    Free Software Foundation, Inc.
+ 
+    Contributed by Nathan Sidwell <nathan@codesourcery.com>
+ 
+ This file is part of BFD, the Binary File Descriptor library.
+ 
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+ 
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+ 
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
+ 
+ #ifndef _ELF_VXWORKS_H
+ #define _ELF_VXWORKS_H
+ 
+ #define DT_VX_WRS_TLS_DATA_START 0x60000010
+ #define DT_VX_WRS_TLS_DATA_SIZE  0x60000011
+ #define DT_VX_WRS_TLS_DATA_ALIGN 0x60000015
+ #define DT_VX_WRS_TLS_VARS_START 0x60000012
+ #define DT_VX_WRS_TLS_VARS_SIZE  0x60000013
+   
+ #endif /* _ELF_VXWORKS_H */
Index: ld/testsuite/ld-vxworks/tls-2.d
===================================================================
RCS file: ld/testsuite/ld-vxworks/tls-2.d
diff -N ld/testsuite/ld-vxworks/tls-2.d
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- ld/testsuite/ld-vxworks/tls-2.d	7 Nov 2007 12:32:21 -0000
***************
*** 0 ****
--- 1,11 ----
+ # source: tls-2.s
+ # ld: --entry foo -q --force-dynamic
+ # readelf: -d
+ 
+ #...
+  0x60000010 \(Operating System specific: 60000010\)        0x[0-9a-f]+
+  0x60000011 \(Operating System specific: 60000011\)        0x4
+  0x60000015 \(Operating System specific: 60000015\)        0x4
+  0x60000012 \(Operating System specific: 60000012\)        0x[0-9a-f]+
+  0x60000013 \(Operating System specific: 60000013\)        0xc
+ #...
Index: ld/testsuite/ld-vxworks/tls-2.s
===================================================================
RCS file: ld/testsuite/ld-vxworks/tls-2.s
diff -N ld/testsuite/ld-vxworks/tls-2.s
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- ld/testsuite/ld-vxworks/tls-2.s	7 Nov 2007 12:32:21 -0000
***************
*** 0 ****
--- 1,19 ----
+ 	.globl	foo
+ foo:
+ 
+ 	.section	.tls_data
+ 	.p2align	2
+ 	.type	i,%object
+ 	.size	i,4
+ i:
+ 	.space	4
+ 	.globl	__tls__i
+ 	.section	.tls_vars
+ 	.p2align	2
+ 	.type	__tls__i,%object
+ 	.size	__tls__i,12
+ __tls__i:
+ 	.4byte	i
+ 	.4byte	0
+ 	.4byte	4
+ 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]