Blame


1 9a4f7bce 2005-01-18 devnull Thread support on Linux is confused by the recent thread local storage (TLS)
2 9a4f7bce 2005-01-18 devnull support that has been put into the ELF tool chain. The TLS libraries are
3 9a4f7bce 2005-01-18 devnull installed in /lib/tls on most Linux systems.
4 9a4f7bce 2005-01-18 devnull
5 9a4f7bce 2005-01-18 devnull We provide two different implementations of the os-dependent parts
6 9a4f7bce 2005-01-18 devnull of libthread for Linux. The first is intended for use on Linux 2.4 and earlier
7 9a4f7bce 2005-01-18 devnull kernels, which do not support TLS. It is in Linux.c and Linuxasm.c and
8 9a4f7bce 2005-01-18 devnull does not use the pthread interface. The second is intended for Linux 2.6
9 9a4f7bce 2005-01-18 devnull and later kernels, which do support TLS. It is in pthread.c and uses the
10 9a4f7bce 2005-01-18 devnull standard pthread interface. It expects to be linked against the TLS-aware
11 9a4f7bce 2005-01-18 devnull thread library aka NPTL.
12 9a4f7bce 2005-01-18 devnull
13 9a4f7bce 2005-01-18 devnull If you use Linux.c and Linuxasm.c with TLS libraries, they do not
14 9a4f7bce 2005-01-18 devnull set up the TLS properly so you will get incorrect programs.
15 9a4f7bce 2005-01-18 devnull For example, there will only be one errno among all the procs
16 9a4f7bce 2005-01-18 devnull in your program instead of one per proc. The pthread NPTL
17 9a4f7bce 2005-01-18 devnull implementation is needed to use the TLS libraries properly.
18 9a4f7bce 2005-01-18 devnull
19 9a4f7bce 2005-01-18 devnull If you use pthread.c without TLS libraries (i.e., with the old Linux
20 9a4f7bce 2005-01-18 devnull pthread library known as LinuxThreads), then you will also get
21 9a4f7bce 2005-01-18 devnull incorrect programs, although more obviously so. The LinuxThreads
22 9a4f7bce 2005-01-18 devnull library assumes it can look at the stack pointer to distinguish between
23 9a4f7bce 2005-01-18 devnull threads, but libthread does its own stack management, breaking this
24 9a4f7bce 2005-01-18 devnull assumption. If you run a pthread-compiled program with the
25 9a4f7bce 2005-01-18 devnull LinuxThreads library, LinuxThreads itself will cause a segmentation
26 9a4f7bce 2005-01-18 devnull fault in __pthread_getspecific() the first time it is called from a
27 9a4f7bce 2005-01-18 devnull non-standard stack.
28 9a4f7bce 2005-01-18 devnull
29 9a4f7bce 2005-01-18 devnull So, it is important that you compile binaries that match your
30 9a4f7bce 2005-01-18 devnull system's choice of TLS vs. not-TLS libraries. The hard part is figuring
31 9a4f7bce 2005-01-18 devnull out which your system has chosen. Plan9port looks at the kernel
32 9a4f7bce 2005-01-18 devnull version you are running and assumes that on kernels that support
33 9a4f7bce 2005-01-18 devnull TLS (2.6+) you will be using TLS.
34 9a4f7bce 2005-01-18 devnull
35 9a4f7bce 2005-01-18 devnull Apparently Gentoo and maybe other distributions do not follow this rule.
36 9a4f7bce 2005-01-18 devnull They use non-TLS libraries even on kernels that can support TLS.
37 668b32b7 2005-01-18 devnull To accomodate them, you can add a line SYSVERSION=2.4 to $PLAN9/config
38 668b32b7 2005-01-18 devnull to force the build to think you are running an old kernel.
39 668b32b7 2005-01-18 devnull The INSTALL script sets up this file automatically on Linux systems.
40 9a4f7bce 2005-01-18 devnull