This is the mail archive of the binutils@sources.redhat.com 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]

working TLS support, take 1


Here is the first go at working Win32 TLS support in GNU binutils for a MingW target.

tls.pat is the patch for TLS support (since GCC doesnt do TLS yet, you will need an obj file from visual C that uses TLS in order to test, I can provide my test obj to anyone who wants it)
atlsup.s and tlssup.c will be going into MingW-Runtime but since they arent there yet, I am posting them here for testing purposes.
Assuming a sutably patched and build version of LD and the linker script, you will need to do the following:
1.get a .obj file from visual C that uses TLS
2.link it with atlssup.s, tlssup.o plus the folowing from mingw-runtime:
crt2.o
-lmsvcrt
-lkernel32
-lmingw32


plus of course anything else that your test program needs (such as -luser32 or -lgdi32)

I am posting this so that:
1.it can be tested on other peoples machines/by other people/etc (and also other hosts/targets) to make sure that I didnt break anything
2.it can be checked by some binutils people to see if it follows whatever the "coding guide" for binutils is
and 3.assuming 1 and 2 are true, it (or the patch anyway, the .c and .s are to go into MingW-Runtime later on) can go into CVS for binutils.


BTW, I sent my copyright assignment out on monday by airmail and they said about a week to get from australia to USA so hopefully it should arrive so I can get my patch into CVS :)

Now, onwards to GCC (thats if I can ever get it to build :)
Index: bfd/peXXigen.c
===================================================================
RCS file: /cvs/src/src/bfd/peXXigen.c,v
retrieving revision 1.16
diff -u -w -r1.16 peXXigen.c
--- bfd/peXXigen.c	7 Oct 2003 08:49:11 -0000	1.16
+++ bfd/peXXigen.c	15 Oct 2003 11:44:59 -0000
@@ -570,7 +570,7 @@
   struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
   PEAOUTHDR *aouthdr_out = (PEAOUTHDR *) out;
   bfd_vma sa, fa, ib;
-  IMAGE_DATA_DIRECTORY idata2, idata5;
+  IMAGE_DATA_DIRECTORY idata2, idata5, tls;
 
   
   if (pe->force_minimum_alignment)
@@ -590,6 +590,7 @@
 
   idata2 = pe->pe_opthdr.DataDirectory[1];
   idata5 = pe->pe_opthdr.DataDirectory[12];
+  tls = pe->pe_opthdr.DataDirectory[9];
   
   if (aouthdr_in->tsize)
     {
@@ -641,6 +642,7 @@
      a final link is going to be performed, it can overwrite them.  */
   extra->DataDirectory[1]  = idata2;
   extra->DataDirectory[12] = idata5;
+  extra->DataDirectory[9] = tls;
 
   if (extra->DataDirectory[1].VirtualAddress == 0)
     /* Until other .idata fixes are made (pending patch), the entry for
@@ -2024,6 +2026,17 @@
 	 - pe_data (abfd)->pe_opthdr.DataDirectory[12].VirtualAddress);      
     }
   
+  h1 = coff_link_hash_lookup (coff_hash_table (info),
+                  "__tls_used", FALSE, FALSE, TRUE);
+  if (h1 != NULL)
+    {
+      pe_data (abfd)->pe_opthdr.DataDirectory[9].VirtualAddress =
+      (h1->root.u.def.value
+       + h1->root.u.def.section->output_section->vma
+       + h1->root.u.def.section->output_offset
+	   - pe_data (abfd)->pe_opthdr.ImageBase);
+      pe_data (abfd)->pe_opthdr.DataDirectory[9].Size = 0x18;
+    } 
   /* If we couldn't find idata$2, we either have an excessively
      trivial program or are in DEEP trouble; we have to assume trivial
      program....  */
Index: ld/scripttempl/pe.sc
===================================================================
RCS file: /cvs/src/src/ld/scripttempl/pe.sc,v
retrieving revision 1.8
diff -u -w -r1.8 pe.sc
--- ld/scripttempl/pe.sc	3 Mar 2003 02:38:10 -0000	1.8
+++ ld/scripttempl/pe.sc	15 Oct 2003 11:45:27 -0000
@@ -25,6 +25,10 @@
     SORT(*)(.idata$6)
     SORT(*)(.idata$7)'
   R_CRT='*(SORT(.CRT$*))'
+  R_TLS='
+    *(.tls)
+    *(.tls$)
+    *(SORT(.tls$*))'
   R_RSRC='*(SORT(.rsrc$*))'
 else
   R_TEXT=
@@ -129,6 +133,11 @@
     ${R_CRT}
   }
 
+  .tls ${RELOCATING+BLOCK(__section_alignment__)} :
+  { 					
+    ${R_TLS}
+  }
+
   .endjunk ${RELOCATING+BLOCK(__section_alignment__)} :
   {
     /* end is deprecated, don't use it */
.file "i386\\atlssup.asm"
    @comp.id:
    @comp.id = 0xe1c83
    __tls_array = 0x2c
    .globl __tls_array
.text
.data
#include <windows.h>
DWORD _tls_start __attribute__ ((section (".tls"))) = 0;
DWORD _tls_end __attribute__ ((section (".tls$ZZZ"))) = 0;
DWORD _tls_index = 0;
PIMAGE_TLS_CALLBACK __xl_a __attribute__ ((section (".CRT$XLA"))) = 0;
PIMAGE_TLS_CALLBACK __xl_z __attribute__ ((section (".CRT$XLZ"))) = 0;
IMAGE_TLS_DIRECTORY _tls_used = {(DWORD)&_tls_start, (DWORD)&_tls_end, &_tls_index, &__xl_a, 0, 0};

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