[patch bfd]: Fix generation of .tls directory entry

Kai Tietz ktietz70@googlemail.com
Tue Dec 21 12:49:00 GMT 2010


2010/12/21 Kai Tietz <ktietz70@googlemail.com>:
> 2010/12/20 Dave Korn <dave.korn.cygwin@gmail.com>:
>> On 20/12/2010 19:46, Kai Tietz wrote:
>>
>>> Well, the issue here is that, if a .tls section is present, it needs
>>> to be put into directory entry.
>>
>>  As I read the spec, the directory entry should point only and exactly to the
>> actual MS-defined TLS struct pointed to by the __tls_used symbol.  That was
>> why I asked about whether it's always the case that we can assume a .tls
>> section is exactly that and nothing else.
>>
>>> Why this isn't happening anymore, I am a bit puzzled too.
>>
>>  I think we should investigate this first.  Got a testcase?
>>
>>    cheers,
>>      DaveK
>>
>
> I found the issue. The cause for this is that bfd searches for
> '__tls_used', which is the underscored version of '_tls_used'
> variable. Caused by the fact that x64 windows doesn't prefix symbols
> by underscore, the symbol wasn't found, as it remains '_tls_used'.
>
> So we have two chances here to solve this: a) Change for windows x64
> the symbol to '__tls_used', or b) search in bfd for x64 windows for
> '_tls_used' instead of '_tls_used'.
>
> Kai
> --
> |  (\_/) This is Bunny. Copy and paste
> | (='.'=) Bunny into your signature to help
> | (")_(") him gain world domination
>

This patch should fix this underscoring issue (should affect wince arm too).

ChangeLog

2010-12-21  Kai Tietz

        * peXXigen.c (_bfd_XXi_final_link_postscript): Use
        TARGET_UNDERSCORE to determine "_tls_used" name.
        (TARGET_UNDERSCORE): Define to default zero, if not present.

        * ld-pe/pe.exp: Add TLS directory test.
        * ld-pe/tlssec.s: New.
        * ld-pe/tlssec64.d: New.
        * ld-pe/tlssec32.d: New.

Tested for x86_64-w64-mingw32, i686-pc-mingw32, and i686-pc-cygwin. Ok
for apply?

Kai
-- 
|  (\_/) This is Bunny. Copy and paste
| (='.'=) Bunny into your signature to help
| (")_(") him gain world domination
-------------- next part --------------
Index: src/bfd/peXXigen.c
===================================================================
--- src.orig/bfd/peXXigen.c	2010-12-21 10:08:50.000000000 +0100
+++ src/bfd/peXXigen.c	2010-12-21 10:51:59.155103300 +0100
@@ -2417,8 +2417,14 @@ _bfd_XXi_final_link_postscript (bfd * ab
         }
     }
 
+#ifndef TARGET_UNDERSCORE
+#define TARGET_UNDERSCORE 0
+#endif
+
   h1 = coff_link_hash_lookup (coff_hash_table (info),
-			      "__tls_used", FALSE, FALSE, TRUE);
+			      (TARGET_UNDERSCORE != 0 ? "__tls_used"
+						      : "_tls_used"),
+			      FALSE, FALSE, TRUE);
   if (h1 != NULL)
     {
       if ((h1->root.type == bfd_link_hash_defined
Index: src/ld/testsuite/ld-pe/pe.exp
===================================================================
--- src.orig/ld/testsuite/ld-pe/pe.exp	2010-04-07 09:31:26.000000000 +0200
+++ src/ld/testsuite/ld-pe/pe.exp	2010-12-21 11:37:15.851325100 +0100
@@ -38,6 +38,8 @@ if {[istarget i*86-*-cygwin*]
 	 {{objdump -s secrel_64.d}} "secrel.x"}
 	{"Empty export table" "" "" "exports.s"
 	 {{objdump -p exports64.d}} "exports.dll"}
+	{"TLS directory entry" "" "" "tlssec.s"
+	 {{objdump -p tlssec64.d}} "tlssec.dll"}
       }
     } elseif {[istarget i*86-*-cygwin*] } {
       set pe_tests {
@@ -45,6 +47,8 @@ if {[istarget i*86-*-cygwin*]
 	 {{objdump -s secrel.d}} "secrel.x"}
 	{"Empty export table" "" "" "exports.s"
 	 {{objdump -p exports.d}} "exports.dll"}
+	{"TLS directory entry" "" "" "tlssec.s"
+	 {{objdump -p tlssec32.d}} "tlssec.dll"}
       }
     } else {
       set pe_tests {
@@ -52,6 +56,8 @@ if {[istarget i*86-*-cygwin*]
 	 {{objdump -s secrel.d}} "secrel.x"}
 	{"Empty export table" "" "" "exports.s"
 	 {{objdump -p exports.d}} "exports.dll"}
+	{"TLS directory entry" "" "" "tlssec.s"
+	 {{objdump -p tlssec32.d}} "tlssec.dll"}
       }
     }
 
Index: src/ld/testsuite/ld-pe/tlssec.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ src/ld/testsuite/ld-pe/tlssec.s	2010-12-21 11:29:09.770089200 +0100
@@ -0,0 +1,20 @@
+.global _tls_used
+.global __tls_used
+.global _start
+.global start
+.global _mainCRTStartup
+.global mainCRTStartup
+
+.text
+_start:
+mainCRTStartup:
+_mainCRTStartup:
+        .byte 1
+
+.section .tls
+_tls_used:
+__tls_used:
+.long 1,2,3,4,5,6,7,8,9,10
+.long 11,12,13,14,15,16,17,18,19,20
+.long 21,22,23,24,25,26,27,28,29,30
+
Index: src/ld/testsuite/ld-pe/tlssec32.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ src/ld/testsuite/ld-pe/tlssec32.d	2010-12-21 11:53:41.935250500 +0100
@@ -0,0 +1,3 @@
+#...
+Entry 9 00003000 00000018 Thread Storage Directory \[\.tls\]
+#...
Index: src/ld/testsuite/ld-pe/tlssec64.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ src/ld/testsuite/ld-pe/tlssec64.d	2010-12-21 11:34:21.131456900 +0100
@@ -0,0 +1,3 @@
+#...
+Entry 9 0000000000003000 00000028 Thread Storage Directory \[\.tls\]
+#...


More information about the Binutils mailing list