public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [patch 1/2, m68k] Fix bugs in the handling of TLS relocations
@ 2009-08-25 12:16 Maxim Kuvyrkov
  2009-08-25 18:05 ` Maxim Kuvyrkov
  2009-08-26 14:35 ` Nick Clifton
  0 siblings, 2 replies; 3+ messages in thread
From: Maxim Kuvyrkov @ 2009-08-25 12:16 UTC (permalink / raw)
  To: binutils; +Cc: Nick Clifton, Andreas Schwab

[-- Attachment #1: Type: text/plain, Size: 746 bytes --]

Good day,

The attached patch fixes bug in processing of TLS symbols which are 
defined in libraries that are not linked against directly, but rather to 
satisfy other library's dependency.  E.g.,

tls-def.so - defines TLS symbol 'x',
tls-lib1.so - linked against tls-def.so and uses 'x',
tls-prog - links against tls-lib1.so explicitly; tls-def.so gets linked 
in as a tls-lib1.so's dependency.

At the moment the linker fail on an assert in elflink.c due to presence 
of a TLS symbol and the output object not having a .tlsdata section.

The fix to the problem was adapted from the other architectures backends.

The patch  includes a testcase to make sure ld doesn't regress in the 
future.

OK to check in?

Thanks,

--
Maxim K.
CodeSourcery

[-- Attachment #2: binutils-m68k-fix-1.ChangeLog --]
[-- Type: text/plain, Size: 463 bytes --]

2009-08-25  Maxim Kuvyrkov  <maxim@codesourcery.com>

	* elf32-m68k.c (elf_m68k_copy_indirect_symbol): Propagate non_got_ref
	value.
	(elf_m68k_check_relocs): Handle dynamic TLS relocations.
	Handle non_got_ref field.
	(elf_m68k_adjust_dynamic_symbol): Handle non_got_ref field.

2009-08-25  Maxim Kuvyrkov  <maxim@codesourcery.com>

	* tls-def-1.s, tls-def-1.d, tls-gd-1.d2, tls-gd-1.d3, tls-main-1.s,
	* tls-main-1.d: New files.
	* m68k.exp: Run new TLS tests.

[-- Attachment #3: binutils-m68k-fix-1.patch --]
[-- Type: text/plain, Size: 5968 bytes --]

Index: elf32-m68k.c
===================================================================
RCS file: /scratch/gcc/repos/src/src/bfd/elf32-m68k.c,v
retrieving revision 1.112
diff -u -p -r1.112 elf32-m68k.c
--- elf32-m68k.c	18 Jun 2009 14:18:29 -0000	1.112
+++ elf32-m68k.c	24 Aug 2009 21:25:42 -0000
@@ -2487,6 +2487,10 @@ elf_m68k_copy_indirect_symbol (struct bf
   dir = elf_m68k_hash_entry (_dir);
   ind = elf_m68k_hash_entry (_ind);
 
+  /* Any absolute non-dynamic relocations against an indirect or weak
+     definition will be against the target symbol.  */
+  _dir->non_got_ref |= _ind->non_got_ref;
+
   /* We might have a direct symbol already having entries in the GOTs.
      Update its key only in case indirect symbol has GOT entries and
      assert that both indirect and direct symbols don't have GOT entries
@@ -2581,6 +2585,14 @@ elf_m68k_check_relocs (abfd, info, sec, 
 	case R_68K_TLS_IE16:
 	case R_68K_TLS_IE32:
 
+	case R_68K_TLS_TPREL32:
+	case R_68K_TLS_DTPREL32:
+
+	  if (ELF32_R_TYPE (rel->r_info) == R_68K_TLS_TPREL32
+	      && info->shared)
+	    /* Do the special chorus for libraries with static TLS.  */
+	    info->flags |= DF_STATIC_TLS;
+
 	  /* This symbol requires a global offset table entry.  */
 
 	  if (dynobj == NULL)
@@ -2739,6 +2751,10 @@ elf_m68k_check_relocs (abfd, info, sec, 
 	      /* Make sure a plt entry is created for this symbol if it
 		 turns out to be a function defined by a dynamic object.  */
 	      h->plt.refcount++;
+
+	      if (!info->shared)
+		/* This symbol needs a non-GOT reference.  */
+		h->non_got_ref = 1;
 	    }
 
 	  /* If we are creating a shared library, we need to copy the
@@ -2946,6 +2962,9 @@ elf_m68k_gc_sweep_hook (bfd *abfd,
 	case R_68K_TLS_IE16:
 	case R_68K_TLS_IE32:
 
+	case R_68K_TLS_TPREL32:
+	case R_68K_TLS_DTPREL32:
+
 	  if (got == NULL)
 	    {
 	      got = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info),
@@ -3159,6 +3178,11 @@ elf_m68k_adjust_dynamic_symbol (info, h)
   if (info->shared)
     return TRUE;
 
+  /* If there are no references to this symbol that do not use the
+     GOT, we don't need to generate a copy reloc.  */
+  if (!h->non_got_ref)
+    return TRUE;
+
   if (h->size == 0)
     {
       (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
Index: m68k.exp
===================================================================
RCS file: /scratch/gcc/repos/src/src/ld/testsuite/ld-m68k/m68k.exp,v
retrieving revision 1.10
diff -u -p -r1.10 m68k.exp
--- m68k.exp	3 Feb 2009 14:36:45 -0000	1.10
+++ m68k.exp	25 Aug 2009 11:44:49 -0000
@@ -74,4 +74,20 @@ if { [istarget m68k-*-linux*] } then {
     run_dump_test "tls-ie-1"
     run_dump_test "tls-ld-1"
     run_dump_test "tls-ld-2"
+
+    set m68k_tls_tests {
+	{"TLS definition"
+	    "-shared" "" {tls-def-1.s}
+	    {{nm -ngD tls-def-1.d}}
+	    "tls-def-1.so"}
+	{"TLS direct symbol use"
+	    "-shared tmpdir/tls-def-1.so" "" {tls-gd-1.s}
+	    {{nm -ngD tls-gd-1.d2} {readelf -d tls-gd-1.d3}}
+	    "tls-gd-1.so"}
+	{"TLS indirect symbol use"
+	    "tmpdir/tls-gd-1.so -rpath-link ./" "" {tls-main-1.s}
+	    {{readelf -d tls-main-1.d}}
+	    "tls-main-1"}}
+
+    run_ld_link_tests $m68k_tls_tests
 }
Index: tls-def-1.d
===================================================================
RCS file: tls-def-1.d
diff -N tls-def-1.d
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tls-def-1.d	25 Aug 2009 11:04:13 -0000
@@ -0,0 +1,4 @@
+00000000 B x
+.*
+.*
+.*
Index: tls-def-1.s
===================================================================
RCS file: tls-def-1.s
diff -N tls-def-1.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tls-def-1.s	25 Aug 2009 10:17:36 -0000
@@ -0,0 +1,9 @@
+#NO_APP
+	.globl	x
+	.section	.tbss,"awT",@nobits
+	.align	2
+	.type	x, @object
+	.size	x, 4
+x:
+	.zero	4
+	.section	.note.GNU-stack,"",@progbits
Index: tls-gd-1.d2
===================================================================
RCS file: tls-gd-1.d2
diff -N tls-gd-1.d2
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tls-gd-1.d2	25 Aug 2009 11:08:29 -0000
@@ -0,0 +1,5 @@
+.* U x
+.*
+.*
+.*
+.*
Index: tls-gd-1.d3
===================================================================
RCS file: tls-gd-1.d3
diff -N tls-gd-1.d3
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tls-gd-1.d3	25 Aug 2009 11:42:29 -0000
@@ -0,0 +1,13 @@
+
+Dynamic section at offset .* contains .*:
+ * Tag * Type * Name/Value
+ 0x00000001 \(NEEDED\) * Shared library: \[tmpdir/tls-def-1.so\]
+ 0x00000004 \(HASH\) .*
+ 0x00000005 \(STRTAB\) .*
+ 0x00000006 \(SYMTAB\) .*
+ 0x0000000a \(STRSZ\) .*
+ 0x0000000b \(SYMENT\) .*
+ 0x00000007 \(RELA\) .*
+ 0x00000008 \(RELASZ\) .*
+ 0x00000009 \(RELAENT\) .*
+ 0x00000000 \(NULL\) .*
Index: tls-main-1.d
===================================================================
RCS file: tls-main-1.d
diff -N tls-main-1.d
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tls-main-1.d	25 Aug 2009 11:51:19 -0000
@@ -0,0 +1,15 @@
+
+Dynamic section at offset .* contains .*:
+ * Tag * Type * Name/Value
+ 0x00000001 \(NEEDED\) * Shared library: \[tmpdir/tls-gd-1.so\]
+ 0x00000001 \(NEEDED\) * Shared library: \[tls-def-1.so\]
+ 0x00000004 \(HASH\) .*
+ 0x00000005 \(STRTAB\) .*
+ 0x00000006 \(SYMTAB\) .*
+ 0x0000000a \(STRSZ\) .*
+ 0x0000000b \(SYMENT\) .*
+ 0x00000015 \(DEBUG\) .*
+ 0x00000007 \(RELA\) .*
+ 0x00000008 \(RELASZ\) .*
+ 0x00000009 \(RELAENT\) .*
+ 0x00000000 \(NULL\) .*
Index: tls-main-1.s
===================================================================
RCS file: tls-main-1.s
diff -N tls-main-1.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tls-main-1.s	25 Aug 2009 11:47:13 -0000
@@ -0,0 +1,19 @@
+#NO_APP
+	.text
+	.align	2
+	.globl	main
+	.type	main, @function
+	.globl	_start
+	.type	_start, @function
+main:
+_start:
+	link.w %fp,#0
+	move.l %a5,-(%sp)
+	move.l #_GLOBAL_OFFSET_TABLE_@GOTPC, %a5
+	lea (-6, %pc, %a5), %a5
+	move.l x@TLSIE(%a5),%a0
+	move.l -4(%fp),%a5
+	unlk %fp
+	rts
+	.size	main, .-main
+	.section	.note.GNU-stack,"",@progbits

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch 1/2, m68k] Fix bugs in the handling of TLS relocations
  2009-08-25 12:16 [patch 1/2, m68k] Fix bugs in the handling of TLS relocations Maxim Kuvyrkov
@ 2009-08-25 18:05 ` Maxim Kuvyrkov
  2009-08-26 14:35 ` Nick Clifton
  1 sibling, 0 replies; 3+ messages in thread
From: Maxim Kuvyrkov @ 2009-08-25 18:05 UTC (permalink / raw)
  To: binutils; +Cc: Nick Clifton, Andreas Schwab

Maxim Kuvyrkov wrote:
> Good day,
> 
> The attached patch fixes bug in processing of TLS symbols which are 
> defined in libraries that are not linked against directly, but rather to 
> satisfy other library's dependency.  E.g.,

Ah, and the following hunk has nothing to do with the described problem 
per se, but rather adds the handling of the DF_STATIC_TLS flag.

> +	  if (ELF32_R_TYPE (rel->r_info) == R_68K_TLS_TPREL32
> +	      && info->shared)
> +	    /* Do the special chorus for libraries with static TLS.  */
> +	    info->flags |= DF_STATIC_TLS;
> +
>  	  /* This symbol requires a global offset table entry.  */
>  
>  	  if (dynobj == NULL)

--
Maxim

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch 1/2, m68k] Fix bugs in the handling of TLS relocations
  2009-08-25 12:16 [patch 1/2, m68k] Fix bugs in the handling of TLS relocations Maxim Kuvyrkov
  2009-08-25 18:05 ` Maxim Kuvyrkov
@ 2009-08-26 14:35 ` Nick Clifton
  1 sibling, 0 replies; 3+ messages in thread
From: Nick Clifton @ 2009-08-26 14:35 UTC (permalink / raw)
  To: Maxim Kuvyrkov; +Cc: binutils, Andreas Schwab

Hi Maxim,

> 2009-08-25  Maxim Kuvyrkov  <maxim@codesourcery.com>
> 
> 	* elf32-m68k.c (elf_m68k_copy_indirect_symbol): Propagate non_got_ref
> 	value.
> 	(elf_m68k_check_relocs): Handle dynamic TLS relocations.
> 	Handle non_got_ref field.
> 	(elf_m68k_adjust_dynamic_symbol): Handle non_got_ref field.
> 
> 2009-08-25  Maxim Kuvyrkov  <maxim@codesourcery.com>
> 
> 	* tls-def-1.s, tls-def-1.d, tls-gd-1.d2, tls-gd-1.d3, tls-main-1.s,
> 	* tls-main-1.d: New files.
> 	* m68k.exp: Run new TLS tests.

Approved and applied.

Cheers
   Nick


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-08-26 13:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-25 12:16 [patch 1/2, m68k] Fix bugs in the handling of TLS relocations Maxim Kuvyrkov
2009-08-25 18:05 ` Maxim Kuvyrkov
2009-08-26 14:35 ` Nick Clifton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).