[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#170984: static linking to pthread causes segfault in ctime_r()



Package: libc6-dev
Version: 2.3.1-5
Severity: normal

When the code below is compiled like so:

gcc  -W -Wall -D_REENTRANT -static -g tst.cpp -o tst -lpthread

the resulting executable causes a segfault. The backtrace looks like this:

mb@tyrone:~$ gdb test core.630
gdb: Symbol `emacs_ctlx_keymap' has different size in shared object, consider 
re-linking
GNU gdb 2002-04-01-cvs
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-linux"...
Core was generated by `./test'.
Program terminated with signal 11, Segmentation fault.
#0  0x0805f1dd in vfprintf ()
(gdb) bt
#0  0x0805f1dd in vfprintf ()
#1  0x0808be33 in vsprintf ()
#2  0x08081ac5 in sprintf ()
#3  0x0806b4ca in asctime_r ()
#4  0x08053a31 in ctime_r ()
#5  0x080481e8 in print_date () at test.c:20
#6  0x08048236 in print_message_function (ptr=0x809eab0) at test.c:32
#7  0x08048c0c in pthread_start_thread ()
(gdb)

If I compile without -static it works. If I comment out the call to ctime_r() 
it works. If I downgrade the libc6 packages it works with both static and 
dynamic linking.

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <time.h>

void print_date(void)
{
    char timebuf[26]; /* This magic number is based on the ctime(3c) man page 
*/
    time_t secs = time(0);

    ctime_r (&secs, timebuf);
    printf("%s", timebuf);
}

void *print_message_function( void *ptr )
{
    char *message;
    message = (char *) ptr;
    printf("%s \n", message);

    sleep(1);

    print_date();

    pthread_exit(0);
}
  
int main()
{
    pthread_t thread1, thread2;
    char *message1 = "Thread 1";
    char *message2 = "Thread 2";
    int ret1, ret2;

    printf("Starting...\n");
    print_date();
    
    ret1 = pthread_create(&thread1, NULL, 
                          print_message_function, (void*) message1);
    ret2 = pthread_create(&thread2, NULL,
                          print_message_function, (void*) message2);

    pthread_join( thread1, NULL);
    pthread_join( thread2, NULL); 

    printf("Thread 1 returns: %d\n", ret1);
    printf("Thread 2 returns: %d\n", ret2);

    exit(0);
}

-- System Information
Debian Release: testing/unstable
Architecture: i386
Kernel: Linux tyrone 2.4.17 #1 Thu Jul 18 19:33:15 CEST 2002 i686
Locale: LANG=C, LC_CTYPE=C

Versions of packages libc6-dev depends on:
ii  libc6                         2.3.1-5    GNU C Library: Shared libraries 
an



Reply to: