PERFORCE change 76485 for review

David Xu davidxu at FreeBSD.org
Wed May 4 05:37:25 PDT 2005


http://perforce.freebsd.org/chv.cgi?CH=76485

Change 76485 by davidxu at davidxu_alona on 2005/05/04 12:35:17

	Allocate enough TCB space for libthr, on Variant II platforms,
	orignal code only initializes basic tcb, while thread libraries
	at least need extra pointer to store its per-thread info.
	Add the extra space to allow libthr to unconditionally access
	%gs on i386 for its _get_curthread() inline function, this reduces
	target code size about 1K on i386.

Affected files ...

.. //depot/projects/davidxu_thread/src/lib/libc/gen/tls.c#5 edit
.. //depot/projects/davidxu_thread/src/libexec/rtld-elf/amd64/reloc.c#2 edit
.. //depot/projects/davidxu_thread/src/libexec/rtld-elf/i386/reloc.c#3 edit
.. //depot/projects/davidxu_thread/src/libexec/rtld-elf/powerpc/reloc.c#2 edit
.. //depot/projects/davidxu_thread/src/libexec/rtld-elf/rtld.c#8 edit
.. //depot/projects/davidxu_thread/src/libexec/rtld-elf/sparc64/reloc.c#2 edit

Differences ...

==== //depot/projects/davidxu_thread/src/lib/libc/gen/tls.c#5 (text+ko) ====

@@ -132,6 +132,7 @@
 		size = tcbsize;
 
 	tls = malloc(size);
+	bzero(tls, size);
 	dtv = malloc(3 * sizeof(Elf_Addr));
 
 	*(Elf_Addr **) tls = dtv;
@@ -203,6 +204,7 @@
 
 	assert(tcbsize >= 2*sizeof(Elf_Addr));
 	tls = malloc(size + tcbsize);
+	bzero(tls, size + tcbsize);
 	dtv = malloc(3 * sizeof(Elf_Addr));
 
 	segbase = (Elf_Addr)(tls + size);
@@ -309,7 +311,13 @@
 		}
 	}
 
-	tls = _rtld_allocate_tls(NULL, 2*sizeof(Elf_Addr),
+	/*
+	 * Here we allocate large enough tcb for libthr, libthr
+	 * needs another field in tcb to store pthread pointer
+	 * on Variant II tcb, while on Variant I, the size is already
+	 * in tls_static_space.
+	 */
+	tls = _rtld_allocate_tls(NULL, 3*sizeof(Elf_Addr),
 	    sizeof(Elf_Addr));
 
 	_set_tp(tls);

==== //depot/projects/davidxu_thread/src/libexec/rtld-elf/amd64/reloc.c#2 (text+ko) ====

@@ -382,7 +382,7 @@
      */
     tls_static_space = tls_last_offset + RTLD_STATIC_TLS_EXTRA;
     amd64_set_fsbase(allocate_tls(objs, 0,
-				  2*sizeof(Elf_Addr), sizeof(Elf_Addr)));
+				  3*sizeof(Elf_Addr), sizeof(Elf_Addr)));
 }
 
 void *__tls_get_addr(tls_index *ti)

==== //depot/projects/davidxu_thread/src/libexec/rtld-elf/i386/reloc.c#3 (text+ko) ====

@@ -338,7 +338,7 @@
      * use.
      */
     tls_static_space = tls_last_offset + RTLD_STATIC_TLS_EXTRA;
-    tls = allocate_tls(objs, NULL, 2*sizeof(Elf_Addr), sizeof(Elf_Addr));
+    tls = allocate_tls(objs, NULL, 3*sizeof(Elf_Addr), sizeof(Elf_Addr));
 
 #ifndef COMPAT_32BIT
     error = i386_set_gsbase(tls);

==== //depot/projects/davidxu_thread/src/libexec/rtld-elf/powerpc/reloc.c#2 (text+ko) ====

@@ -556,7 +556,7 @@
 
 	tls_static_space = tls_last_offset + tls_last_size + RTLD_STATIC_TLS_EXTRA;
 
-	_tp = (Elf_Addr **) ((char *) allocate_tls(list, 0, 8, 8) 
+	_tp = (Elf_Addr **) ((char *) allocate_tls(list, 0, 12, 8) 
 	    + TLS_TP_OFFSET + TLS_TCB_SIZE);
 
 	/*

==== //depot/projects/davidxu_thread/src/libexec/rtld-elf/rtld.c#8 (text+ko) ====

@@ -2560,6 +2560,7 @@
     size = tls_static_space;
 
     tls = malloc(size);
+    bzero(tls, size);
     dtv = calloc(1, (tls_max_index + 2) * sizeof(Elf_Addr));
 
     *(Elf_Addr**) tls = dtv;
@@ -2657,6 +2658,7 @@
 
     assert(tcbsize >= 2*sizeof(Elf_Addr));
     tls = malloc(size + tcbsize);
+    bzero(tls, size + tcbsize);
     dtv = calloc(1, (tls_max_index + 2) * sizeof(Elf_Addr));
 
     segbase = (Elf_Addr)(tls + size);

==== //depot/projects/davidxu_thread/src/libexec/rtld-elf/sparc64/reloc.c#2 (text+ko) ====

@@ -729,7 +729,7 @@
      * use.
      */
     tls_static_space = tls_last_offset + RTLD_STATIC_TLS_EXTRA;
-    tp = allocate_tls(objs, NULL, 2*sizeof(Elf_Addr), sizeof(Elf_Addr));
+    tp = allocate_tls(objs, NULL, 3*sizeof(Elf_Addr), sizeof(Elf_Addr));
 }
 
 void *__tls_get_addr(tls_index *ti)


More information about the p4-projects mailing list