Skip to content

Tag: thread-local-storage

Why does this nostdlib C++ code segfault when I call a function with a thread local variable? But not with a global var or when I access members?

Assembly included. This weekend I tried to get my own small library running without any C libs and the thread local stuff is giving me problems. Below you can see I created a struct called Try1 (because it’s my first attempt!) If I set the thread local variable and use it, the code seems to execute fine. If I call

c++ thread_local destructors with pthread destructors

I want to do some work after all C++ thread_local destructors called. This is platform specific – Android, so I have access to pthreads. The question is, when pthread_key_created destructors should be called, before or after C++ thread_local destructors? Or they can be interleaved? I tested On Linux Mint and pthread destructors called after C++ ‘s. Answer bionic/pthread_exit.cpp currently has

What is %gs in Assembly

void return_input (void) { char array[30]; gets (array); printf(“%sn”, array); } After compiling it in gcc, this function is converted to the following Assembly code: push %ebp mov %esp,%ebp sub $0x28,%esp mov %gs:0x14,%eax mov %eax,-0x4(%ebp) xor %eax,%eax lea -0x22(%ebp),%eax mov %eax,(%esp) call 0x8048374 lea -0x22(%ebp),%eax mov %eax,(%esp) call 0x80483a4 mov -0x4(%ebp),%eax xor %gs:0x14,%eax je 0x80484ac call 0x8048394 leave ret I