public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix NPTL libc.a
@ 2005-05-20  9:10 Jakub Jelinek
  2005-05-21 19:00 ` Ulrich Drepper
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2005-05-20  9:10 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: Glibc hackers

Hi!

In NPTL, getpid, __libc_alloca_cutoff and a bunch of other functions
in libc.a access various fields in struct pthread.
But on TLS_TCB_AT_TP architectures, libc.a only allocates space for
tcbhead_t and TLS area before it (via sbrk), so the rest of struct pthread
is available for subsequent e.g. malloc calls.
This leads to problems like getpid always returning 5 or 7...

TLS_INIT_TCB* is only used in libc-tls.c (this case) and rtld.c (only
if ld.so itself uses __thread, which is not the case in any glibc so
far).

2005-05-20  Jakub Jelinek  <jakub@redhat.com>

	* sysdeps/i386/tls.h (TLS_INIT_TCB_SIZE, TLS_INIT_TCB_ALIGN): Define to
	size/alignment of struct pthread rather than tcbhead_t.
	* sysdeps/x86_64/tls.h (TLS_INIT_TCB_SIZE, TLS_INIT_TCB_ALIGN):
	Likewise.
	* sysdeps/s390/tls.h (TLS_INIT_TCB_SIZE, TLS_INIT_TCB_ALIGN):
	Likewise.
	* sysdeps/sparc/tls.h (TLS_INIT_TCB_SIZE, TLS_INIT_TCB_ALIGN):
	Likewise.

--- libc/nptl/sysdeps/s390/tls.h.jj	2005-05-03 21:50:31.000000000 +0200
+++ libc/nptl/sysdeps/s390/tls.h	2005-05-20 10:57:42.000000000 +0200
@@ -81,11 +81,13 @@ typedef struct
 /* Get the thread descriptor definition.  */
 # include <nptl/descr.h>
 
-/* This is the size of the initial TCB.  */
-# define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
+/* This is the size of the initial TCB.  Can't be just sizeof (tcbhead_t),
+   because NPTL getpid, __libc_alloca_cutoff etc. need (almost) the whole
+   struct pthread even when not linked with -lpthread.  */
+# define TLS_INIT_TCB_SIZE sizeof (struct pthread)
 
 /* Alignment requirements for the initial TCB.  */
-# define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
+# define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
 
 /* This is the size of the TCB.  */
 # define TLS_TCB_SIZE sizeof (struct pthread)
--- libc/nptl/sysdeps/sparc/tls.h.jj	2005-05-03 21:50:32.000000000 +0200
+++ libc/nptl/sysdeps/sparc/tls.h	2005-05-20 10:56:32.000000000 +0200
@@ -69,11 +69,13 @@ typedef struct
 
 register struct pthread *__thread_self __asm__("%g7");
 
-/* This is the size of the initial TCB.  */
-# define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
+/* This is the size of the initial TCB.  Can't be just sizeof (tcbhead_t),
+   because NPTL getpid, __libc_alloca_cutoff etc. need (almost) the whole
+   struct pthread even when not linked with -lpthread.  */
+# define TLS_INIT_TCB_SIZE sizeof (struct pthread)
 
 /* Alignment requirements for the initial TCB.  */
-# define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
+# define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
 
 /* This is the size of the TCB.  */
 # define TLS_TCB_SIZE sizeof (struct pthread)
--- libc/nptl/sysdeps/i386/tls.h.jj	2005-05-03 21:50:30.000000000 +0200
+++ libc/nptl/sysdeps/i386/tls.h	2005-05-20 10:55:13.000000000 +0200
@@ -1,5 +1,5 @@
 /* Definition for thread-local data handling.  nptl/i386 version.
-   Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -102,11 +102,13 @@ union user_desc_init
 /* Get the thread descriptor definition.  */
 # include <nptl/descr.h>
 
-/* This is the size of the initial TCB.  */
-# define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
+/* This is the size of the initial TCB.  Can't be just sizeof (tcbhead_t),
+   because NPTL getpid, __libc_alloca_cutoff etc. need (almost) the whole
+   struct pthread even when not linked with -lpthread.  */
+# define TLS_INIT_TCB_SIZE sizeof (struct pthread)
 
 /* Alignment requirements for the initial TCB.  */
-# define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
+# define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
 
 /* This is the size of the TCB.  */
 # define TLS_TCB_SIZE sizeof (struct pthread)
--- libc/nptl/sysdeps/x86_64/tls.h.jj	2005-05-03 21:50:35.000000000 +0200
+++ libc/nptl/sysdeps/x86_64/tls.h	2005-05-20 10:56:05.000000000 +0200
@@ -1,5 +1,5 @@
 /* Definition for thread-local data handling.  nptl/x86_64 version.
-   Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -82,11 +82,13 @@ typedef struct
 # endif
 #endif
 
-/* This is the size of the initial TCB.  */
-# define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
+/* This is the size of the initial TCB.  Can't be just sizeof (tcbhead_t),
+   because NPTL getpid, __libc_alloca_cutoff etc. need (almost) the whole
+   struct pthread even when not linked with -lpthread.  */
+# define TLS_INIT_TCB_SIZE sizeof (struct pthread)
 
 /* Alignment requirements for the initial TCB.  */
-# define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
+# define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
 
 /* This is the size of the TCB.  */
 # define TLS_TCB_SIZE sizeof (struct pthread)


	Jakub

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

* Re: [PATCH] Fix NPTL libc.a
  2005-05-20  9:10 [PATCH] Fix NPTL libc.a Jakub Jelinek
@ 2005-05-21 19:00 ` Ulrich Drepper
  0 siblings, 0 replies; 2+ messages in thread
From: Ulrich Drepper @ 2005-05-21 19:00 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Glibc hackers

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

Applied.

-- 
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 251 bytes --]

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

end of thread, other threads:[~2005-05-21 19:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-20  9:10 [PATCH] Fix NPTL libc.a Jakub Jelinek
2005-05-21 19:00 ` Ulrich Drepper

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