Blob


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