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]

[patch 1/2, m68k] Fix bugs in the handling of TLS relocations


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
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.
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

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