This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug dynamic-link/21777] use of pthread_getspecific, pthread_setspecific in a statically linked program leads to a crash before main


https://sourceware.org/bugzilla/show_bug.cgi?id=21777

Paul Pluzhnikov <ppluzhnikov at google dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2018-09-02
                 CC|                            |ppluzhnikov at google dot com
     Ever confirmed|0                           |1

--- Comment #2 from Paul Pluzhnikov <ppluzhnikov at google dot com> ---
Trivial reproducer:


#include <assert.h>
#include <pthread.h>

pthread_key_t k;

int main (int argc, char *argv[])
{
  int rc;

  rc = pthread_key_create (&k, NULL);
  assert (rc == 0);
  rc = pthread_setspecific(k, NULL);
  assert (rc == 0);

  return 0;
}



Using current trunk:

(gdb) run
Starting program: /build/nptl/tst-bz21777-static

Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) bt
#0  0x0000000000000000 in ?? ()
#1  0x0000000000478215 in __gthread_mutex_lock (__mutex=0x6a7380
<object_mutex>) at ./gthr-default.h:748
#2  __register_frame_info_bases (begin=<optimized out>, ob=0x6a2300 <object>,
tbase=<optimized out>, dbase=<optimized out>) at
../../../libgcc/unwind-dw2-fde.c:103
#3  0x0000000000400b3d in frame_dummy ()
#4  0x0000000000000001 in ?? ()
#5  0x000000000040197c in __libc_csu_init (argc=-9616, argc@entry=1,
argv=argv@entry=0x7fffffffdbe8, envp=0x7fffffffdbf8) at elf-init.c:88
#6  0x00000000004011a0 in __libc_start_main (main=0x400540 <main>, argc=1,
argv=0x7fffffffdbe8, init=0x401900 <__libc_csu_init>, fini=0x4019a0
<__libc_csu_fini>, rtld_fini=0x0, stack_end=0x7fffffffdbd8) at
../csu/libc-start.c:264
#7  0x0000000000400a6a in _start () at ../sysdeps/x86_64/start.S:120

(gdb) up
#1  0x0000000000478215 in __gthread_mutex_lock (__mutex=0x6a7380
<object_mutex>) at ./gthr-default.h:748
748         return __gthrw_(pthread_mutex_lock) (__mutex);
(gdb) disas
Dump of assembler code for function __register_frame_info_bases:
   0x00000000004781e0 <+0>:     cmpq   $0x0,0x227d60(%rip)        # 0x69ff48
   0x00000000004781e8 <+8>:     movq   $0xffffffffffffffff,(%rsi)
   0x00000000004781ef <+15>:    mov    %rdx,0x8(%rsi)
   0x00000000004781f3 <+19>:    mov    %rcx,0x10(%rsi)
   0x00000000004781f7 <+23>:    mov    %rdi,0x18(%rsi)
   0x00000000004781fb <+27>:    movq   $0x7f8,0x20(%rsi)
   0x0000000000478203 <+35>:    je     0x478240
<__register_frame_info_bases+96>
   0x0000000000478205 <+37>:    push   %rbx
   0x0000000000478206 <+38>:    lea    0x22f173(%rip),%rdi        # 0x6a7380
<object_mutex>
   0x000000000047820d <+45>:    mov    %rsi,%rbx
   0x0000000000478210 <+48>:    callq  0x0   <<<=== weak reference to
pthread_mutex_lock

=> 0x0000000000478215 <+53>:    mov    0x22f18d(%rip),%edx        # 0x6a73a8
<any_objects_registered>
   0x000000000047821b <+59>:    mov    0x22f196(%rip),%rax        # 0x6a73b8
<unseen_objects>
   0x0000000000478222 <+66>:    mov    %rbx,0x22f18f(%rip)        # 0x6a73b8
<unseen_objects>
...

The issue then is that pthread_setspecific is linked in, but pthread_mutex_lock
is not.

Adding -Wl,-u,pthread_mutex_lock -Wl,-u,pthread_mutex_unlock to the link line
fixes the problem.


It would be nice for this to work out of the box, but I am not sure how to
achieve that.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]