Description of problem: If LD_LIBRARY_PATH contain /lib, a program that uses getcontext/setcontext/swapcontext function and links with libpthread will crash if it tries to access the errno value. The crash will happen after the first swapcontext() call. If LD_LIBRARY_PATH is unset or /lib is not in the list of directories, program runs correctly. The following foo.c program reproduces the problem as per the steps below: #include <stdlib.h> #include <stdio.h> #include <ucontext.h> #include <malloc.h> ucontext_t func, main_func; void MyFunc() { printf( "MyFunc running\n" ); // this will crash printf( "Now func switching back to main_func\n" ); swapcontext( &func, &main_func ); } int main() { char * ss_sp = (char *)malloc( 16 * 1024 ); // Get the current execution context getcontext( &func ); // Modify the context to a new stack func.uc_link = 0; func.uc_stack.ss_flags = 0; func.uc_stack.ss_size = (16* 1024); func.uc_stack.ss_sp = ss_sp; printf( "Creating thread context... \n" ); makecontext( &func, &MyFunc, 0 ); printf( "Switching to thread \n" ); swapcontext( &main_func, &func ); free( ss_sp ); printf( "main_func done\n" ); return 0; } Version-Release number of selected component (if applicable): How reproducible: Every time. Steps to Reproduce: 1. g++ foo.c -o foo -lpthread 2. export LD_LIBRARY_PATH=/lib 3. ./foo Actual results: Creating thread context... Switching to thread Segmentation fault Expected results: Creating thread context... Switching to thread MyFunc running Now func switching back to main_func main_func done Additional info:
That's not a bug. The thread library in /lib cannot possibly handle setcontext etc since it does not use a thread register and has to rely on the stack pointer to lead to the thread decriptor. Use the thread library in /lib/i686 or on RHL9 in /lib/tls.