This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH] Fix .tls_common handling in ld -r
On Thu, Jun 15, 2006 at 08:00:23AM -0700, H. J. Lu wrote:
> > > Can you add a testcase?
> >
> > We don't have yet any checks in the testsuite whether the compiler
> > supports __thread. But, perhaps just compiling/ld -r'ing/linking
> > __asm (".tls_common foo,4,4");
> > int main (void) { return 0; }
> > would be enough. But then again, we need some test to see whether
> > the target supports TLS at all. The current TLS tests are all in
> > ld-<cpu>/ ATM, but this test isn't arch specific.
>
> You can put the test in ld-elf and limit it to those targets with
> TLS support. There are many cases in ld-elf.
Ok, here is a testcase for the patch I sent yesterday.
Verified it passes on x86_64-linux with the patch in and fails without it
(also if I comment out these 2 lines:
# fail "tls_common"
} else {
unresolved "tls_common"
}
# return
}
it fails without the patch on the readelf test).
Ok?
2006-06-16 Jakub Jelinek <jakub@redhat.com>
* ld-elf/tls_common.exp: New test.
* ld-elf/tls_common.s: New file.
--- ld/testsuite/ld-elf/tls_common.exp.jj 2006-06-16 16:34:55.000000000 +0200
+++ ld/testsuite/ld-elf/tls_common.exp 2006-06-16 17:15:38.000000000 +0200
@@ -0,0 +1,70 @@
+# Expect script for .tls_common tests
+# Copyright 2006 Free Software Foundation, Inc.
+#
+# This file 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.
+#
+# Written by Jakub Jelinek (jakub@redhat.com)
+#
+
+# Make sure that binutils can correctly handle ld output in ELF.
+
+# Run on Linux only.
+if { ![istarget *-*-linux*] } {
+ return
+}
+
+if { [istarget *-*-linux*aout*]
+ || [istarget *-*-linux*oldld*] } {
+ return
+}
+
+global as
+global ld
+global READELF
+global srcdir
+global subdir
+global link_output
+
+if { ![ld_assemble $as $srcdir/$subdir/tls_common.s tmpdir/tls_common.o ] } {
+ unresolved "tls_common"
+ return
+}
+
+if { ![ld_simple_link $ld tmpdir/tls_common1.o "-r tmpdir/tls_common.o"] } {
+ fail "tls_common"
+ return
+}
+
+if { ![ld_simple_link $ld tmpdir/tls_common "tmpdir/tls_common1.o"] } {
+ if { [string match "*not supported*" $link_output]
+ || [string match "*unrecognized option*" $link_output] } {
+ unsupported "$ld_options is not supported by this target"
+ } elseif { [string match "*Warning*alignment*of common symbol*" $link_output] } {
+ fail "tls_common"
+ } else {
+ unresolved "tls_common"
+ }
+ return
+}
+
+send_log "$READELF -l --wide tmpdir/tls_common\n"
+catch "exec $READELF -l --wide tmpdir/tls_common" readelf_output
+if ![string match "*TLS*0x000000 0x000004 R *" $readelf_output] then {
+ send_log "$readelf_output\n"
+ fail "tls_common"
+ return
+}
+
+pass "tls_common"
--- ld/testsuite/ld-elf/tls_common.s.jj 2006-06-16 16:34:34.000000000 +0200
+++ ld/testsuite/ld-elf/tls_common.s 2006-06-16 16:34:30.000000000 +0200
@@ -0,0 +1,11 @@
+ .globl main
+ .globl start
+ .globl _start
+ .globl __start
+ .text
+main:
+start:
+_start:
+__start:
+ .byte 0
+ .tls_common foo,4,4
Jakub