40 lines · 2.1 KB · Text
RawDownload
Thread support on Linux is confused by the recent thread local storage (TLS)support that has been put into the ELF tool chain.  The TLS libraries are installed in /lib/tls on most Linux systems. We provide two different implementations of the os-dependent partsof libthread for Linux.  The first is intended for use on Linux 2.4 and earlierkernels, which do not support TLS.  It is in Linux.c and Linuxasm.c anddoes not use the pthread interface.  The second is intended for Linux 2.6and later kernels, which do support TLS.  It is in pthread.c and uses thestandard pthread interface.  It expects to be linked against the TLS-awarethread library aka NPTL. If you use Linux.c and Linuxasm.c with TLS libraries, they do notset up the TLS properly so you will get incorrect programs.For example, there will only be one errno among all the procsin your program instead of one per proc.  The pthread NPTLimplementation is needed to use the TLS libraries properly. If you use pthread.c without TLS libraries (i.e., with the old Linuxpthread library known as LinuxThreads), then you will also getincorrect programs, although more obviously so.  The LinuxThreadslibrary assumes it can look at the stack pointer to distinguish betweenthreads, but libthread does its own stack management, breaking thisassumption.  If you run a pthread-compiled program with the LinuxThreads library, LinuxThreads itself will cause a segmentationfault in __pthread_getspecific() the first time it is called from anon-standard stack. So, it is important that you compile binaries that match yoursystem's choice of TLS vs. not-TLS libraries.  The hard part is figuringout which your system has chosen.  Plan9port looks at the kernelversion you are running and assumes that on kernels that supportTLS (2.6+) you will be using TLS. Apparently Gentoo and maybe other distributions do not follow this rule.They use non-TLS libraries even on kernels that can support TLS.To accomodate them, you can add a line SYSVERSION=2.4 to $PLAN9/configto force the build to think you are running an old kernel.The INSTALL script sets up this file automatically on Linux systems.