Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - crash on _smp_cmpxchg when dynamic linking is used: (1 Item)
   
crash on _smp_cmpxchg when dynamic linking is used  
Hi,

I’m trying to diagnose a crash caused by execution of _smp_cmpxchg function.
My binary is consisted of many shared libs, and one of them does some pre-main initialization that looks like this:

volatile unsigned * initialized;  // allocated in shmem
__attribute__((constructor)) void lib_init()
{
    if (!_smp_cmpxchg(initialized, 0, 1))
    {
      initialization_stuff();
    }
    other_stuff();
}

Executing this binary results in SIGBUS error.
According to stack trace the crash happens on the next instruction after leaving _smp_cmpxchg

I’ve verified that “initialized” variable is correctly aligned, and _smp_cmpxchg crashes also for local variables.
I’ve also verified via LD_DEBUG=all env var, that _smp_cmpxchg symbol is properly resolved.

All of these workarounds make the problem go away:
1.	Link library statically
2.	Remove -fomit-frame-pointer compilation flag
3.	Don’t use _smp_cmpxchg in pre-main code, using it later is fine.

Any suggestions on the root cause or proper fix?
I am using QNX6.5 SP1.